libstdc++
random.h
Go to the documentation of this file.
1// random number generation -*- C++ -*-
2
3// Copyright (C) 2009-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/**
26 * @file bits/random.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
29 */
30
31#ifndef _RANDOM_H
32#define _RANDOM_H 1
33
34#include <vector>
35#include <bits/ios_base.h>
37
38namespace std _GLIBCXX_VISIBILITY(default)
39{
40_GLIBCXX_BEGIN_NAMESPACE_VERSION
41
42 // [26.4] Random number generation
43
44 /**
45 * @defgroup random Random Number Generation
46 * @ingroup numerics
47 *
48 * A facility for generating random numbers on selected distributions.
49 * @{
50 */
51
52 // std::uniform_random_bit_generator is defined in <bits/uniform_int_dist.h>
53
54#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
55_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
56#endif
57 /**
58 * @brief A function template for converting the output of a (integral)
59 * uniform random number generator to a floatng point result in the range
60 * [0-1).
61 */
62 template<typename _RealType, size_t __bits,
63 typename _UniformRandomNumberGenerator>
64 _RealType
65 generate_canonical(_UniformRandomNumberGenerator& __g);
66#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
67_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
68#endif
69
70 /// @cond undocumented
71 // Implementation-space details.
72 namespace __detail
73 {
74#pragma GCC diagnostic push
75#pragma GCC diagnostic ignored "-Wc++17-extensions"
76
77#ifndef __SIZEOF_INT128__
78 // Emulate 128-bit integer type, for the arithmetic ops used in <random>.
79 // The __detail::__mod function needs: (type(a) * x + c) % m.
80 // std::philox_engine needs multiplication and bitwise ops.
81 struct __rand_uint128
82 {
83 using type = __rand_uint128;
84
85 __rand_uint128() = default;
86
87 explicit constexpr
88 __rand_uint128(uint64_t __lo) noexcept : _M_lo(__lo) { }
89
90 __rand_uint128(const __rand_uint128&) = default;
91 __rand_uint128& operator=(const __rand_uint128&) = default;
92
93 _GLIBCXX14_CONSTEXPR type&
94 operator=(uint64_t __x) noexcept
95 { return *this = type(__x); }
96
97 _GLIBCXX14_CONSTEXPR type&
98 operator++() noexcept
99 { return *this = *this + 1; }
100
101 _GLIBCXX14_CONSTEXPR type&
102 operator--() noexcept
103 { return *this = *this - 1; }
104
105 _GLIBCXX14_CONSTEXPR type
106 operator++(int) noexcept
107 {
108 auto __tmp = *this;
109 ++*this;
110 return __tmp;
111 }
112
113 _GLIBCXX14_CONSTEXPR type
114 operator--(int) noexcept
115 {
116 auto __tmp = *this;
117 --*this;
118 return __tmp;
119 }
120
121 _GLIBCXX14_CONSTEXPR type&
122 operator+=(const type& __r) noexcept
123 {
124 _M_hi += __r._M_hi + __builtin_add_overflow(_M_lo, __r._M_lo, &_M_lo);
125 return *this;
126 }
127
128 friend _GLIBCXX14_CONSTEXPR type
129 operator+(type __l, const type& __r) noexcept
130 { return __l += __r; }
131
132 // Addition with 64-bit operand
133 friend _GLIBCXX14_CONSTEXPR type
134 operator+(type __l, uint64_t __r) noexcept
135 { return __l += type(__r); }
136
137 // Subtraction with 64-bit operand
138 _GLIBCXX14_CONSTEXPR type&
139 operator-=(uint64_t __r) noexcept
140 {
141 _M_hi -= __builtin_sub_overflow(_M_lo, __r, &_M_lo);
142 return *this;
143 }
144
145 friend _GLIBCXX14_CONSTEXPR type
146 operator-(type __l, uint64_t __r) noexcept
147 { return __l -= __r; }
148
149 _GLIBCXX14_CONSTEXPR type&
150 operator*=(const type& __x) noexcept
151 {
152 uint64_t __a[12] = {
153 uint32_t(_M_lo), _M_lo >> 32,
154 uint32_t(_M_hi), _M_hi >> 32,
155 uint32_t(__x._M_lo), __x._M_lo >> 32,
156 uint32_t(__x._M_hi), __x._M_hi >> 32,
157 0, 0,
158 0, 0 };
159 for (int __i = 0; __i < 4; ++__i)
160 {
161 uint64_t __c = 0;
162 for (int __j = __i; __j < 4; ++__j)
163 {
164 __c += __a[__i] * __a[4 + __j - __i] + __a[8 + __j];
165 __a[8 + __j] = uint32_t(__c);
166 __c >>= 32;
167 }
168 }
169 _M_lo = __a[8] + (__a[9] << 32);
170 _M_hi = __a[10] + (__a[11] << 32);
171 return *this;
172 }
173
174 // Multiplication with a 64-bit operand is simpler.
175 // pre: _M_hi == 0
176 _GLIBCXX14_CONSTEXPR type&
177 operator*=(uint64_t __x) noexcept
178 {
179 // Split 64-bit values _M_lo and __x into high and low 32-bit
180 // limbs and multiply those individually.
181 // l * x = (l0 + l1) * (x0 + x1) = l0x0 + l0x1 + l1x0 + l1x1
182
183 constexpr uint64_t __mask = 0xffffffff;
184 uint64_t __ll[2] = { _M_lo >> 32, _M_lo & __mask };
185 uint64_t __xx[2] = { __x >> 32, __x & __mask };
186 uint64_t __l0x0 = __ll[0] * __xx[0];
187 uint64_t __l0x1 = __ll[0] * __xx[1];
188 uint64_t __l1x0 = __ll[1] * __xx[0];
189 uint64_t __l1x1 = __ll[1] * __xx[1];
190 // These bits are the low half of _M_hi and the high half of _M_lo.
191 uint64_t __mid
192 = (__l0x1 & __mask) + (__l1x0 & __mask) + (__l1x1 >> 32);
193 _M_hi = __l0x0 + (__l0x1 >> 32) + (__l1x0 >> 32) + (__mid >> 32);
194 _M_lo = (__mid << 32) + (__l1x1 & __mask);
195 return *this;
196 }
197
198 _GLIBCXX14_CONSTEXPR type&
199 operator/=(const type& __r) noexcept
200 {
201 if (!_M_hi)
202 {
203 if (!__r._M_hi)
204 _M_lo = _M_lo / __r._M_lo;
205 else
206 _M_lo = 0;
207 }
208 else
209 {
210 uint64_t __a[13] = {
211 uint32_t(_M_lo), _M_lo >> 32,
212 uint32_t(_M_hi), _M_hi >> 32,
213 0,
214 uint32_t(__r._M_lo), __r._M_lo >> 32,
215 uint32_t(__r._M_hi), __r._M_hi >> 32,
216 0, 0,
217 0, 0
218 };
219 uint64_t __c = 0, __w = 0;
220 if (!__r._M_hi && __r._M_lo <= ~uint32_t(0))
221 for (int __i = 3; ; --__i)
222 {
223 __w = __a[__i] + (__c << 32);
224 __a[9 + __i] = __w / __r._M_lo;
225 if (__i == 0)
226 break;
227 __c = __w % __r._M_lo;
228 }
229 else
230 {
231 // See Donald E. Knuth's "Seminumerical Algorithms".
232 int __n = 0, __d = 0;
233 uint64_t __q = 0, __s = 0;
234 for (__d = 3; __a[5 + __d] == 0; --__d)
235 ;
236 __s = (uint64_t(1) << 32) / (__a[5 + __d] + 1);
237 if (__s > 1)
238 {
239 for (int __i = 0; __i <= 3; ++__i)
240 {
241 __w = __a[__i] * __s + __c;
242 __a[__i] = uint32_t(__w);
243 __c = __w >> 32;
244 }
245 __a[4] = __c;
246 __c = 0;
247 for (int __i = 0; __i <= 3; ++__i)
248 {
249 __w = __a[5 + __i] * __s + __c;
250 __a[5 + __i] = uint32_t(__w);
251 __c = __w >> 32;
252 if (__a[5 + __i])
253 __d = __i;
254 }
255 }
256 __n = 4;
257 for (int __i = __n - __d - 1; __i >= 0; --__i)
258 {
259 __n = __i + __d + 1;
260 __w = (__a[__n] << 32) + __a[__n - 1];
261 if (__a[__n] != __a[5 + __d])
262 __q = __w / __a[5 + __d];
263 else
264 __q = ~uint32_t(0);
265 uint64_t __t = __w - __q * __a[5 + __d];
266 if (__t <= ~uint32_t(0)
267 && __a[4 + __d] * __q > (__t << 32) + __a[__n - 2])
268 --__q;
269 __c = 0;
270 for (int __j = 0; __j <= __d; ++__j)
271 {
272 __w = __q * __a[5 + __j] + __c;
273 __c = __w >> 32;
274 __w = __a[__i + __j] - uint32_t(__w);
275 __a[__i + __j] = uint32_t(__w);
276 __c += (__w >> 32) != 0;
277 }
278 if (int64_t(__a[__n]) < int64_t(__c))
279 {
280 --__q;
281 __c = 0;
282 for (int __j = 0; __j <= __d; ++__j)
283 {
284 __w = __a[__i + __j] + __a[5 + __j] + __c;
285 __c = __w >> 32;
286 __a[__i + __j] = uint32_t(__w);
287 }
288 __a[__n] += __c;
289 }
290 __a[9 + __i] = __q;
291 }
292 }
293 _M_lo = __a[9] + (__a[10] << 32);
294 _M_hi = __a[11] + (__a[12] << 32);
295 }
296 return *this;
297 }
298
299 // Currently only supported for 64-bit operands.
300 _GLIBCXX14_CONSTEXPR type&
301 operator%=(uint64_t __m) noexcept
302 {
303 if (_M_hi == 0)
304 {
305 _M_lo %= __m;
306 return *this;
307 }
308
309 int __shift = __builtin_clzll(__m) + 64 - __builtin_clzll(_M_hi);
310 type __x(0);
311 if (__shift >= 64)
312 {
313 __x._M_hi = __m << (__shift - 64);
314 __x._M_lo = 0;
315 }
316 else
317 {
318 __x._M_hi = __m >> (64 - __shift);
319 __x._M_lo = __m << __shift;
320 }
321
322 while (_M_hi != 0 || _M_lo >= __m)
323 {
324 if (__x <= *this)
325 {
326 _M_hi -= __x._M_hi;
327 _M_hi -= __builtin_sub_overflow(_M_lo, __x._M_lo,
328 &_M_lo);
329 }
330 __x._M_lo = (__x._M_lo >> 1) | (__x._M_hi << 63);
331 __x._M_hi >>= 1;
332 }
333 return *this;
334 }
335
336 friend _GLIBCXX14_CONSTEXPR type
337 operator*(type __l, const type& __r) noexcept
338 { return __l *= __r; }
339
340 friend _GLIBCXX14_CONSTEXPR type
341 operator*(type __l, uint64_t __r) noexcept
342 { return __l *= __r; }
343
344 friend _GLIBCXX14_CONSTEXPR type
345 operator/(type __l, const type& __r) noexcept
346 { return __l /= __r; }
347
348 friend _GLIBCXX14_CONSTEXPR type
349 operator%(type __l, uint64_t __m) noexcept
350 { return __l %= __m; }
351
352 friend _GLIBCXX14_CONSTEXPR type
353 operator~(type __v) noexcept
354 {
355 __v._M_hi = ~__v._M_hi;
356 __v._M_lo = ~__v._M_lo;
357 return __v;
358 }
359
360 _GLIBCXX14_CONSTEXPR type&
361 operator>>=(unsigned __c) noexcept
362 {
363 if (__c >= 64)
364 {
365 _M_lo = _M_hi >>= (__c - 64);
366 _M_hi = 0;
367 }
368 else if (__c != 0)
369 {
370 _M_lo = (_M_lo >> __c) | (_M_hi << (64 - __c));
371 _M_hi >>= __c;
372 }
373 return *this;
374 }
375
376 _GLIBCXX14_CONSTEXPR type&
377 operator<<=(unsigned __c) noexcept
378 {
379 if (__c >= 64)
380 {
381 _M_hi = _M_lo << (__c - 64);
382 _M_lo = 0;
383 }
384 else if (__c != 0)
385 {
386 _M_hi = (_M_hi << __c) | (_M_lo >> (64 - __c));
387 _M_lo <<= __c;
388 }
389 return *this;
390 }
391
392 friend _GLIBCXX14_CONSTEXPR type
393 operator>>(type __x, unsigned __c) noexcept
394 { return __x >>= __c; }
395
396 friend _GLIBCXX14_CONSTEXPR type
397 operator<<(type __x, unsigned __c) noexcept
398 { return __x <<= __c; }
399
400 _GLIBCXX14_CONSTEXPR type&
401 operator|=(const type& __r) noexcept
402 {
403 _M_hi |= __r._M_hi;
404 _M_lo |= __r._M_lo;
405 return *this;
406 }
407
408 _GLIBCXX14_CONSTEXPR type&
409 operator^=(const type& __r) noexcept
410 {
411 _M_hi ^= __r._M_hi;
412 _M_lo ^= __r._M_lo;
413 return *this;
414 }
415
416 _GLIBCXX14_CONSTEXPR type&
417 operator&=(const type& __r) noexcept
418 {
419 _M_hi &= __r._M_hi;
420 _M_lo &= __r._M_lo;
421 return *this;
422 }
423
424 friend _GLIBCXX14_CONSTEXPR type
425 operator|(type __l, const type& __r) noexcept
426 { return __l |= __r; }
427
428 friend _GLIBCXX14_CONSTEXPR type
429 operator^(type __l, const type& __r) noexcept
430 { return __l ^= __r; }
431
432 friend _GLIBCXX14_CONSTEXPR type
433 operator&(type __l, const type& __r) noexcept
434 { return __l &= __r; }
435
436 friend _GLIBCXX14_CONSTEXPR type
437 operator&(type __l, uint64_t __r) noexcept
438 {
439 __l._M_hi = 0;
440 __l._M_lo &= __r;
441 return __l;
442 }
443
444#if __cpp_impl_three_way_comparison >= 201907L
445 friend std::strong_ordering
446 operator<=>(const type&, const type&) = default;
447
448 friend bool
449 operator==(const type&, const type&) = default;
450#else
451 friend constexpr bool
452 operator==(const type& __l, const type& __r) noexcept
453 { return __l._M_hi == __r._M_hi && __l._M_lo == __r._M_lo; }
454
455 friend _GLIBCXX14_CONSTEXPR bool
456 operator<(const type& __l, const type& __r) noexcept
457 {
458 if (__l._M_hi < __r._M_hi)
459 return true;
460 else if (__l._M_hi == __r._M_hi)
461 return __l._M_lo < __r._M_lo;
462 else
463 return false;
464 }
465
466 friend _GLIBCXX14_CONSTEXPR bool
467 operator>(const type& __l, const type& __r) noexcept
468 { return __r < __l; }
469
470 friend _GLIBCXX14_CONSTEXPR bool
471 operator<=(const type& __l, const type& __r) noexcept
472 { return !(__r < __l); }
473
474 friend _GLIBCXX14_CONSTEXPR bool
475 operator>=(const type& __l, const type& __r) noexcept
476 { return !(__l < __r); }
477#endif
478
479 friend _GLIBCXX14_CONSTEXPR bool
480 operator==(const type& __l, uint64_t __r) noexcept
481 { return __l == type(__r); }
482
483 template<typename _RealT>
484 constexpr explicit operator _RealT() const noexcept
485 {
486 static_assert(std::is_floating_point<_RealT>::value,
487 "template argument must be a floating point type");
488 return _M_hi == 0
489 ? _RealT(_M_lo)
490 : _RealT(_M_hi) * _RealT(18446744073709551616.0)
491 + _RealT(_M_lo);
492 }
493
494 // pre: _M_hi == 0
495 constexpr explicit operator uint64_t() const noexcept
496 { return _M_lo; }
497
498 uint64_t _M_hi = 0;
499 uint64_t _M_lo = 0;
500 };
501#endif // ! __SIZEOF_INT128__
502
503 template<typename _UIntType, size_t __w,
504 bool = __w < static_cast<size_t>
506 struct _Shift
507 { static constexpr _UIntType __value = 0; };
508
509 template<typename _UIntType, size_t __w>
510 struct _Shift<_UIntType, __w, true>
511 { static constexpr _UIntType __value = _UIntType(1) << __w; };
512
513 template<int __s,
514 int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
515 + (__s <= __CHAR_BIT__ * sizeof (long))
516 + (__s <= __CHAR_BIT__ * sizeof (long long))
517 /* assume long long no bigger than __int128 */
518 + (__s <= 128))>
519 struct _Select_uint_least_t
520 {
521 static_assert(__which < 0, /* needs to be dependent */
522 "sorry, would be too much trouble for a slow result");
523 };
524
525 template<int __s>
526 struct _Select_uint_least_t<__s, 4>
527 { using type = unsigned int; };
528
529 template<int __s>
530 struct _Select_uint_least_t<__s, 3>
531 { using type = unsigned long; };
532
533 template<int __s>
534 struct _Select_uint_least_t<__s, 2>
535 { using type = unsigned long long; };
536
537#if __SIZEOF_INT128__ > __SIZEOF_LONG_LONG__
538 template<int __s>
539 struct _Select_uint_least_t<__s, 1>
540 { __extension__ using type = unsigned __int128; };
541#elif __has_builtin(__builtin_add_overflow) \
542 && __has_builtin(__builtin_sub_overflow) \
543 && defined __UINT64_TYPE__
544 template<int __s>
545 struct _Select_uint_least_t<__s, 1>
546 { using type = __rand_uint128; };
547#endif
548
549 // Assume a != 0, a < m, c < m, x < m.
550 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
551 bool __big_enough = (!(__m & (__m - 1))
552 || (_Tp(-1) - __c) / __a >= __m - 1),
553 bool __schrage_ok = __m % __a < __m / __a>
554 struct _Mod
555 {
556 static _Tp
557 __calc(_Tp __x)
558 {
559 using _Tp2
560 = typename _Select_uint_least_t<std::__lg(__a)
561 + std::__lg(__m) + 2>::type;
562 return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m);
563 }
564 };
565
566 // Schrage.
567 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
568 struct _Mod<_Tp, __m, __a, __c, false, true>
569 {
570 static _Tp
571 __calc(_Tp __x);
572 };
573
574 // Special cases:
575 // - for m == 2^n or m == 0, unsigned integer overflow is safe.
576 // - a * (m - 1) + c fits in _Tp, there is no overflow.
577 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
578 struct _Mod<_Tp, __m, __a, __c, true, __s>
579 {
580 static _Tp
581 __calc(_Tp __x)
582 {
583 _Tp __res = __a * __x + __c;
584 if (__m)
585 __res %= __m;
586 return __res;
587 }
588 };
589
590 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
591 inline _Tp
592 __mod(_Tp __x)
593 {
594 if constexpr (__a == 0)
595 return __c;
596 else // N.B. _Mod must not be instantiated with a == 0
597 return _Mod<_Tp, __m, __a, __c>::__calc(__x);
598 }
599
600 /*
601 * An adaptor class for converting the output of any Generator into
602 * the input for a specific Distribution.
603 */
604 template<typename _Engine, typename _DInputType>
605 struct _Adaptor
606 {
607 static_assert(std::is_floating_point<_DInputType>::value,
608 "template argument must be a floating point type");
609
610 public:
611 _Adaptor(_Engine& __g)
612 : _M_g(__g) { }
613
614 _DInputType
615 min() const
616 { return _DInputType(0); }
617
618 _DInputType
619 max() const
620 { return _DInputType(1); }
621
622 /*
623 * Converts a value generated by the adapted random number generator
624 * into a value in the input domain for the dependent random number
625 * distribution.
626 */
627 _DInputType
628 operator()()
629 {
630 return std::generate_canonical<_DInputType,
632 _Engine>(_M_g);
633 }
634
635 private:
636 _Engine& _M_g;
637 };
638
639 // Detect whether a template argument _Sseq is a valid seed sequence for
640 // a random number engine _Engine with result type _Res.
641 // Used to constrain _Engine::_Engine(_Sseq&) and _Engine::seed(_Sseq&)
642 // as required by [rand.eng.general].
643
644 template<typename _Sseq>
645 using __seed_seq_generate_t = decltype(
648
649 template<typename _Sseq, typename _Engine, typename _Res,
650 typename _GenerateCheck = __seed_seq_generate_t<_Sseq>>
651 using _If_seed_seq_for = _Require<
652 __not_<is_same<__remove_cvref_t<_Sseq>, _Engine>>,
653 is_unsigned<typename _Sseq::result_type>,
654 __not_<is_convertible<_Sseq, _Res>>
655 >;
656
657#pragma GCC diagnostic pop
658 } // namespace __detail
659 /// @endcond
660
661 /**
662 * @addtogroup random_generators Random Number Generators
663 * @ingroup random
664 *
665 * These classes define objects which provide random or pseudorandom
666 * numbers, either from a discrete or a continuous interval. The
667 * random number generator supplied as a part of this library are
668 * all uniform random number generators which provide a sequence of
669 * random number uniformly distributed over their range.
670 *
671 * A number generator is a function object with an operator() that
672 * takes zero arguments and returns a number.
673 *
674 * A compliant random number generator must satisfy the following
675 * requirements. <table border=1 cellpadding=10 cellspacing=0>
676 * <caption align=top>Random Number Generator Requirements</caption>
677 * <tr><td>To be documented.</td></tr> </table>
678 *
679 * @{
680 */
681
682 /**
683 * @brief A model of a linear congruential random number generator.
684 *
685 * A random number generator that produces pseudorandom numbers via
686 * linear function:
687 * @f[
688 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
689 * @f]
690 *
691 * The template parameter @p _UIntType must be an unsigned integral type
692 * large enough to store values up to (__m-1). If the template parameter
693 * @p __m is 0, the modulus @p __m used is
694 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
695 * parameters @p __a and @p __c must be less than @p __m.
696 *
697 * The size of the state is @f$1@f$.
698 *
699 * @headerfile random
700 * @since C++11
701 */
702 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
704 {
706 "result_type must be an unsigned integral type");
707 static_assert(__m == 0u || (__a < __m && __c < __m),
708 "template argument substituting __m out of bounds");
709
710 template<typename _Sseq>
711 using _If_seed_seq
712 = __detail::_If_seed_seq_for<_Sseq, linear_congruential_engine,
713 _UIntType>;
714
715 public:
716 /** The type of the generated random value. */
717 typedef _UIntType result_type;
718
719 /** The multiplier. */
720 static constexpr result_type multiplier = __a;
721 /** An increment. */
722 static constexpr result_type increment = __c;
723 /** The modulus. */
724 static constexpr result_type modulus = __m;
725 static constexpr result_type default_seed = 1u;
726
727 /**
728 * @brief Constructs a %linear_congruential_engine random number
729 * generator engine with seed 1.
732 { }
733
734 /**
735 * @brief Constructs a %linear_congruential_engine random number
736 * generator engine with seed @p __s. The default seed value
737 * is 1.
738 *
739 * @param __s The initial seed value.
740 */
743 { seed(__s); }
744
745 /**
746 * @brief Constructs a %linear_congruential_engine random number
747 * generator engine seeded from the seed sequence @p __q.
748 *
749 * @param __q the seed sequence.
750 */
751 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
752 explicit
754 { seed(__q); }
755
756 /**
757 * @brief Reseeds the %linear_congruential_engine random number generator
758 * engine sequence to the seed @p __s.
759 *
760 * @param __s The new seed.
761 */
762 void
763 seed(result_type __s = default_seed);
764
765 /**
766 * @brief Reseeds the %linear_congruential_engine random number generator
767 * engine
768 * sequence using values from the seed sequence @p __q.
769 *
770 * @param __q the seed sequence.
771 */
772 template<typename _Sseq>
773 _If_seed_seq<_Sseq>
774 seed(_Sseq& __q);
775
776 /**
777 * @brief Gets the smallest possible value in the output range.
778 *
779 * The minimum depends on the @p __c parameter: if it is zero, the
780 * minimum generated must be > 0, otherwise 0 is allowed.
781 */
782 static constexpr result_type
783 min()
784 { return __c == 0u ? 1u : 0u; }
785
786 /**
787 * @brief Gets the largest possible value in the output range.
788 */
789 static constexpr result_type
790 max()
791 { return __m - 1u; }
792
793 /**
794 * @brief Discard a sequence of random numbers.
795 */
796 void
797 discard(unsigned long long __z)
798 {
799 for (; __z != 0ULL; --__z)
800 (*this)();
801 }
802
803 /**
804 * @brief Gets the next random number in the sequence.
805 */
807 operator()()
808 {
809 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
810 return _M_x;
811 }
812
813 /**
814 * @brief Compares two linear congruential random number generator
815 * objects of the same type for equality.
816 *
817 * @param __lhs A linear congruential random number generator object.
818 * @param __rhs Another linear congruential random number generator
819 * object.
820 *
821 * @returns true if the infinite sequences of generated values
822 * would be equal, false otherwise.
823 */
824 friend bool
826 const linear_congruential_engine& __rhs)
827 { return __lhs._M_x == __rhs._M_x; }
828
829 /**
830 * @brief Writes the textual representation of the state x(i) of x to
831 * @p __os.
832 *
833 * @param __os The output stream.
834 * @param __lcr A % linear_congruential_engine random number generator.
835 * @returns __os.
836 */
837 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
838 _UIntType1 __m1, typename _CharT, typename _Traits>
841 const std::linear_congruential_engine<_UIntType1,
842 __a1, __c1, __m1>& __lcr);
843
844 /**
845 * @brief Sets the state of the engine by reading its textual
846 * representation from @p __is.
847 *
848 * The textual representation must have been previously written using
849 * an output stream whose imbued locale and whose type's template
850 * specialization arguments _CharT and _Traits were the same as those
851 * of @p __is.
852 *
853 * @param __is The input stream.
854 * @param __lcr A % linear_congruential_engine random number generator.
855 * @returns __is.
856 */
857 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
858 _UIntType1 __m1, typename _CharT, typename _Traits>
861 std::linear_congruential_engine<_UIntType1, __a1,
862 __c1, __m1>& __lcr);
863
864 private:
865 _UIntType _M_x;
866 };
867
868#if __cpp_impl_three_way_comparison < 201907L
869 /**
870 * @brief Compares two linear congruential random number generator
871 * objects of the same type for inequality.
872 *
873 * @param __lhs A linear congruential random number generator object.
874 * @param __rhs Another linear congruential random number generator
875 * object.
876 *
877 * @returns true if the infinite sequences of generated values
878 * would be different, false otherwise.
879 */
880 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
881 inline bool
882 operator!=(const std::linear_congruential_engine<_UIntType, __a,
883 __c, __m>& __lhs,
884 const std::linear_congruential_engine<_UIntType, __a,
885 __c, __m>& __rhs)
886 { return !(__lhs == __rhs); }
887#endif
888
889 /**
890 * A generalized feedback shift register discrete random number generator.
891 *
892 * This algorithm avoids multiplication and division and is designed to be
893 * friendly to a pipelined architecture. If the parameters are chosen
894 * correctly, this generator will produce numbers with a very long period and
895 * fairly good apparent entropy, although still not cryptographically strong.
896 *
897 * The best way to use this generator is with the predefined mt19937 class.
898 *
899 * This algorithm was originally invented by Makoto Matsumoto and
900 * Takuji Nishimura.
901 *
902 * @tparam __w Word size, the number of bits in each element of
903 * the state vector.
904 * @tparam __n The degree of recursion.
905 * @tparam __m The period parameter.
906 * @tparam __r The separation point bit index.
907 * @tparam __a The last row of the twist matrix.
908 * @tparam __u The first right-shift tempering matrix parameter.
909 * @tparam __d The first right-shift tempering matrix mask.
910 * @tparam __s The first left-shift tempering matrix parameter.
911 * @tparam __b The first left-shift tempering matrix mask.
912 * @tparam __t The second left-shift tempering matrix parameter.
913 * @tparam __c The second left-shift tempering matrix mask.
914 * @tparam __l The second right-shift tempering matrix parameter.
915 * @tparam __f Initialization multiplier.
916 *
917 * @headerfile random
918 * @since C++11
919 */
920 template<typename _UIntType, size_t __w,
921 size_t __n, size_t __m, size_t __r,
922 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
923 _UIntType __b, size_t __t,
924 _UIntType __c, size_t __l, _UIntType __f>
925 class mersenne_twister_engine
926 {
928 "result_type must be an unsigned integral type");
929 static_assert(1u <= __m && __m <= __n,
930 "template argument substituting __m out of bounds");
931 static_assert(__r <= __w, "template argument substituting "
932 "__r out of bound");
933 static_assert(__u <= __w, "template argument substituting "
934 "__u out of bound");
935 static_assert(__s <= __w, "template argument substituting "
936 "__s out of bound");
937 static_assert(__t <= __w, "template argument substituting "
938 "__t out of bound");
939 static_assert(__l <= __w, "template argument substituting "
940 "__l out of bound");
941 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
942 "template argument substituting __w out of bound");
943 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
944 "template argument substituting __a out of bound");
945 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
946 "template argument substituting __b out of bound");
947 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
948 "template argument substituting __c out of bound");
949 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
950 "template argument substituting __d out of bound");
951 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
952 "template argument substituting __f out of bound");
953
954 template<typename _Sseq>
955 using _If_seed_seq
956 = __detail::_If_seed_seq_for<_Sseq, mersenne_twister_engine,
957 _UIntType>;
958
959 public:
960 /** The type of the generated random value. */
961 typedef _UIntType result_type;
962
963 // parameter values
964 static constexpr size_t word_size = __w;
965 static constexpr size_t state_size = __n;
966 static constexpr size_t shift_size = __m;
967 static constexpr size_t mask_bits = __r;
968 static constexpr result_type xor_mask = __a;
969 static constexpr size_t tempering_u = __u;
970 static constexpr result_type tempering_d = __d;
971 static constexpr size_t tempering_s = __s;
972 static constexpr result_type tempering_b = __b;
973 static constexpr size_t tempering_t = __t;
974 static constexpr result_type tempering_c = __c;
975 static constexpr size_t tempering_l = __l;
976 static constexpr result_type initialization_multiplier = __f;
977 static constexpr result_type default_seed = 5489u;
978
979 // constructors and member functions
980
981 mersenne_twister_engine() : mersenne_twister_engine(default_seed) { }
982
983 explicit
984 mersenne_twister_engine(result_type __sd)
985 { seed(__sd); }
986
987 /**
988 * @brief Constructs a %mersenne_twister_engine random number generator
989 * engine seeded from the seed sequence @p __q.
990 *
991 * @param __q the seed sequence.
992 */
993 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
994 explicit
995 mersenne_twister_engine(_Sseq& __q)
996 { seed(__q); }
997
998 void
999 seed(result_type __sd = default_seed);
1000
1001 template<typename _Sseq>
1002 _If_seed_seq<_Sseq>
1003 seed(_Sseq& __q);
1004
1005 /**
1006 * @brief Gets the smallest possible value in the output range.
1007 */
1008 static constexpr result_type
1009 min()
1010 { return 0; }
1011
1012 /**
1013 * @brief Gets the largest possible value in the output range.
1014 */
1015 static constexpr result_type
1016 max()
1017 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1018
1019 /**
1020 * @brief Discard a sequence of random numbers.
1021 */
1022 void
1023 discard(unsigned long long __z);
1024
1026 operator()();
1027
1028 /**
1029 * @brief Compares two % mersenne_twister_engine random number generator
1030 * objects of the same type for equality.
1031 *
1032 * @param __lhs A % mersenne_twister_engine random number generator
1033 * object.
1034 * @param __rhs Another % mersenne_twister_engine random number
1035 * generator object.
1036 *
1037 * @returns true if the infinite sequences of generated values
1038 * would be equal, false otherwise.
1039 */
1040 friend bool
1041 operator==(const mersenne_twister_engine& __lhs,
1042 const mersenne_twister_engine& __rhs)
1043 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
1044 && __lhs._M_p == __rhs._M_p); }
1045
1046 /**
1047 * @brief Inserts the current state of a % mersenne_twister_engine
1048 * random number generator engine @p __x into the output stream
1049 * @p __os.
1050 *
1051 * @param __os An output stream.
1052 * @param __x A % mersenne_twister_engine random number generator
1053 * engine.
1054 *
1055 * @returns The output stream with the state of @p __x inserted or in
1056 * an error state.
1057 */
1058 template<typename _UIntType1,
1059 size_t __w1, size_t __n1,
1060 size_t __m1, size_t __r1,
1061 _UIntType1 __a1, size_t __u1,
1062 _UIntType1 __d1, size_t __s1,
1063 _UIntType1 __b1, size_t __t1,
1064 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
1065 typename _CharT, typename _Traits>
1068 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
1069 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
1070 __l1, __f1>& __x);
1071
1072 /**
1073 * @brief Extracts the current state of a % mersenne_twister_engine
1074 * random number generator engine @p __x from the input stream
1075 * @p __is.
1076 *
1077 * @param __is An input stream.
1078 * @param __x A % mersenne_twister_engine random number generator
1079 * engine.
1080 *
1081 * @returns The input stream with the state of @p __x extracted or in
1082 * an error state.
1083 */
1084 template<typename _UIntType1,
1085 size_t __w1, size_t __n1,
1086 size_t __m1, size_t __r1,
1087 _UIntType1 __a1, size_t __u1,
1088 _UIntType1 __d1, size_t __s1,
1089 _UIntType1 __b1, size_t __t1,
1090 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
1091 typename _CharT, typename _Traits>
1094 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
1095 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
1096 __l1, __f1>& __x);
1097
1098 private:
1099 void _M_gen_rand();
1100
1101 _UIntType _M_x[state_size];
1102 size_t _M_p;
1103 };
1104
1105#if __cpp_impl_three_way_comparison < 201907L
1106 /**
1107 * @brief Compares two % mersenne_twister_engine random number generator
1108 * objects of the same type for inequality.
1109 *
1110 * @param __lhs A % mersenne_twister_engine random number generator
1111 * object.
1112 * @param __rhs Another % mersenne_twister_engine random number
1113 * generator object.
1114 *
1115 * @returns true if the infinite sequences of generated values
1116 * would be different, false otherwise.
1117 */
1118 template<typename _UIntType, size_t __w,
1119 size_t __n, size_t __m, size_t __r,
1120 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
1121 _UIntType __b, size_t __t,
1122 _UIntType __c, size_t __l, _UIntType __f>
1123 inline bool
1124 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
1125 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
1126 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
1127 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
1128 { return !(__lhs == __rhs); }
1129#endif
1130
1131 /**
1132 * @brief The Marsaglia-Zaman generator.
1133 *
1134 * This is a model of a Generalized Fibonacci discrete random number
1135 * generator, sometimes referred to as the SWC generator.
1136 *
1137 * A discrete random number generator that produces pseudorandom
1138 * numbers using:
1139 * @f[
1140 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
1141 * @f]
1142 *
1143 * The size of the state is @f$r@f$
1144 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
1145 *
1146 * @headerfile random
1147 * @since C++11
1148 */
1149 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
1150 class subtract_with_carry_engine
1151 {
1153 "result_type must be an unsigned integral type");
1154 static_assert(0u < __s && __s < __r,
1155 "0 < s < r");
1156 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1157 "template argument substituting __w out of bounds");
1158
1159 template<typename _Sseq>
1160 using _If_seed_seq
1161 = __detail::_If_seed_seq_for<_Sseq, subtract_with_carry_engine,
1162 _UIntType>;
1163
1164 public:
1165 /** The type of the generated random value. */
1166 typedef _UIntType result_type;
1167
1168 // parameter values
1169 static constexpr size_t word_size = __w;
1170 static constexpr size_t short_lag = __s;
1171 static constexpr size_t long_lag = __r;
1172 static constexpr uint_least32_t default_seed = 19780503u;
1173
1174 subtract_with_carry_engine() : subtract_with_carry_engine(0u)
1175 { }
1176
1177 /**
1178 * @brief Constructs an explicitly seeded %subtract_with_carry_engine
1179 * random number generator.
1180 */
1181 explicit
1182 subtract_with_carry_engine(result_type __sd)
1183 { seed(__sd); }
1184
1185 /**
1186 * @brief Constructs a %subtract_with_carry_engine random number engine
1187 * seeded from the seed sequence @p __q.
1188 *
1189 * @param __q the seed sequence.
1190 */
1191 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1192 explicit
1193 subtract_with_carry_engine(_Sseq& __q)
1194 { seed(__q); }
1195
1196 /**
1197 * @brief Seeds the initial state @f$x_0@f$ of the random number
1198 * generator.
1199 *
1200 * N1688[4.19] modifies this as follows. If @p __value == 0,
1201 * sets value to 19780503. In any case, with a linear
1202 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
1203 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
1204 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
1205 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
1206 * set carry to 1, otherwise sets carry to 0.
1207 */
1208 void
1209 seed(result_type __sd = 0u);
1210
1211 /**
1212 * @brief Seeds the initial state @f$x_0@f$ of the
1213 * % subtract_with_carry_engine random number generator.
1214 */
1215 template<typename _Sseq>
1216 _If_seed_seq<_Sseq>
1217 seed(_Sseq& __q);
1218
1219 /**
1220 * @brief Gets the inclusive minimum value of the range of random
1221 * integers returned by this generator.
1222 */
1223 static constexpr result_type
1224 min()
1225 { return 0; }
1226
1227 /**
1228 * @brief Gets the inclusive maximum value of the range of random
1229 * integers returned by this generator.
1230 */
1231 static constexpr result_type
1232 max()
1233 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1234
1235 /**
1236 * @brief Discard a sequence of random numbers.
1237 */
1238 void
1239 discard(unsigned long long __z)
1240 {
1241 for (; __z != 0ULL; --__z)
1242 (*this)();
1243 }
1244
1245 /**
1246 * @brief Gets the next random number in the sequence.
1247 */
1249 operator()();
1250
1251 /**
1252 * @brief Compares two % subtract_with_carry_engine random number
1253 * generator objects of the same type for equality.
1254 *
1255 * @param __lhs A % subtract_with_carry_engine random number generator
1256 * object.
1257 * @param __rhs Another % subtract_with_carry_engine random number
1258 * generator object.
1259 *
1260 * @returns true if the infinite sequences of generated values
1261 * would be equal, false otherwise.
1262 */
1263 friend bool
1264 operator==(const subtract_with_carry_engine& __lhs,
1265 const subtract_with_carry_engine& __rhs)
1266 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
1267 && __lhs._M_carry == __rhs._M_carry
1268 && __lhs._M_p == __rhs._M_p); }
1269
1270 /**
1271 * @brief Inserts the current state of a % subtract_with_carry_engine
1272 * random number generator engine @p __x into the output stream
1273 * @p __os.
1274 *
1275 * @param __os An output stream.
1276 * @param __x A % subtract_with_carry_engine random number generator
1277 * engine.
1278 *
1279 * @returns The output stream with the state of @p __x inserted or in
1280 * an error state.
1281 */
1282 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
1283 typename _CharT, typename _Traits>
1286 const std::subtract_with_carry_engine<_UIntType1, __w1,
1287 __s1, __r1>& __x);
1288
1289 /**
1290 * @brief Extracts the current state of a % subtract_with_carry_engine
1291 * random number generator engine @p __x from the input stream
1292 * @p __is.
1293 *
1294 * @param __is An input stream.
1295 * @param __x A % subtract_with_carry_engine random number generator
1296 * engine.
1297 *
1298 * @returns The input stream with the state of @p __x extracted or in
1299 * an error state.
1300 */
1301 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
1302 typename _CharT, typename _Traits>
1305 std::subtract_with_carry_engine<_UIntType1, __w1,
1306 __s1, __r1>& __x);
1307
1308 private:
1309 /// The state of the generator. This is a ring buffer.
1310 _UIntType _M_x[long_lag];
1311 _UIntType _M_carry; ///< The carry
1312 size_t _M_p; ///< Current index of x(i - r).
1313 };
1314
1315#if __cpp_impl_three_way_comparison < 201907L
1316 /**
1317 * @brief Compares two % subtract_with_carry_engine random number
1318 * generator objects of the same type for inequality.
1319 *
1320 * @param __lhs A % subtract_with_carry_engine random number generator
1321 * object.
1322 * @param __rhs Another % subtract_with_carry_engine random number
1323 * generator object.
1324 *
1325 * @returns true if the infinite sequences of generated values
1326 * would be different, false otherwise.
1327 */
1328 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
1329 inline bool
1330 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
1331 __s, __r>& __lhs,
1332 const std::subtract_with_carry_engine<_UIntType, __w,
1333 __s, __r>& __rhs)
1334 { return !(__lhs == __rhs); }
1335#endif
1336
1337 /**
1338 * Produces random numbers from some base engine by discarding blocks of
1339 * data.
1340 *
1341 * @pre @f$ 0 \leq r \leq p @f$
1342 *
1343 * @headerfile random
1344 * @since C++11
1345 */
1346 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1348 {
1349 static_assert(1 <= __r && __r <= __p,
1350 "template argument substituting __r out of bounds");
1351
1352 public:
1353 /** The type of the generated random value. */
1354 typedef typename _RandomNumberEngine::result_type result_type;
1355
1356 template<typename _Sseq>
1357 using _If_seed_seq
1358 = __detail::_If_seed_seq_for<_Sseq, discard_block_engine,
1359 result_type>;
1360
1361 // parameter values
1362 static constexpr size_t block_size = __p;
1363 static constexpr size_t used_block = __r;
1364
1365 /**
1366 * @brief Constructs a default %discard_block_engine engine.
1367 *
1368 * The underlying engine is default constructed as well.
1371 : _M_b(), _M_n(0) { }
1372
1373 /**
1374 * @brief Copy constructs a %discard_block_engine engine.
1375 *
1376 * Copies an existing base class random number generator.
1377 * @param __rng An existing (base class) engine object.
1378 */
1379 explicit
1380 discard_block_engine(const _RandomNumberEngine& __rng)
1381 : _M_b(__rng), _M_n(0) { }
1382
1383 /**
1384 * @brief Move constructs a %discard_block_engine engine.
1385 *
1386 * Copies an existing base class random number generator.
1387 * @param __rng An existing (base class) engine object.
1388 */
1389 explicit
1390 discard_block_engine(_RandomNumberEngine&& __rng)
1391 : _M_b(std::move(__rng)), _M_n(0) { }
1392
1393 /**
1394 * @brief Seed constructs a %discard_block_engine engine.
1395 *
1396 * Constructs the underlying generator engine seeded with @p __s.
1397 * @param __s A seed value for the base class engine.
1398 */
1401 : _M_b(__s), _M_n(0) { }
1402
1403 /**
1404 * @brief Generator construct a %discard_block_engine engine.
1405 *
1406 * @param __q A seed sequence.
1407 */
1408 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1409 explicit
1410 discard_block_engine(_Sseq& __q)
1411 : _M_b(__q), _M_n(0)
1412 { }
1413
1414 /**
1415 * @brief Reseeds the %discard_block_engine object with the default
1416 * seed for the underlying base class generator engine.
1417 */
1418 void
1419 seed()
1420 {
1421 _M_b.seed();
1422 _M_n = 0;
1423 }
1424
1425 /**
1426 * @brief Reseeds the %discard_block_engine object with the default
1427 * seed for the underlying base class generator engine.
1428 */
1429 void
1430 seed(result_type __s)
1431 {
1432 _M_b.seed(__s);
1433 _M_n = 0;
1434 }
1435
1436 /**
1437 * @brief Reseeds the %discard_block_engine object with the given seed
1438 * sequence.
1439 * @param __q A seed generator function.
1440 */
1441 template<typename _Sseq>
1442 _If_seed_seq<_Sseq>
1443 seed(_Sseq& __q)
1444 {
1445 _M_b.seed(__q);
1446 _M_n = 0;
1447 }
1448
1449 /**
1450 * @brief Gets a const reference to the underlying generator engine
1451 * object.
1452 */
1453 const _RandomNumberEngine&
1454 base() const noexcept
1455 { return _M_b; }
1456
1457 /**
1458 * @brief Gets the minimum value in the generated random number range.
1459 */
1460 static constexpr result_type
1461 min()
1462 { return _RandomNumberEngine::min(); }
1463
1464 /**
1465 * @brief Gets the maximum value in the generated random number range.
1466 */
1467 static constexpr result_type
1468 max()
1469 { return _RandomNumberEngine::max(); }
1470
1471 /**
1472 * @brief Discard a sequence of random numbers.
1473 */
1474 void
1475 discard(unsigned long long __z)
1476 {
1477 for (; __z != 0ULL; --__z)
1478 (*this)();
1479 }
1480
1481 /**
1482 * @brief Gets the next value in the generated random number sequence.
1483 */
1485 operator()();
1486
1487 /**
1488 * @brief Compares two %discard_block_engine random number generator
1489 * objects of the same type for equality.
1490 *
1491 * @param __lhs A %discard_block_engine random number generator object.
1492 * @param __rhs Another %discard_block_engine random number generator
1493 * object.
1494 *
1495 * @returns true if the infinite sequences of generated values
1496 * would be equal, false otherwise.
1497 */
1498 friend bool
1499 operator==(const discard_block_engine& __lhs,
1500 const discard_block_engine& __rhs)
1501 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
1502
1503 /**
1504 * @brief Inserts the current state of a %discard_block_engine random
1505 * number generator engine @p __x into the output stream
1506 * @p __os.
1507 *
1508 * @param __os An output stream.
1509 * @param __x A %discard_block_engine random number generator engine.
1510 *
1511 * @returns The output stream with the state of @p __x inserted or in
1512 * an error state.
1513 */
1514 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1515 typename _CharT, typename _Traits>
1518 const std::discard_block_engine<_RandomNumberEngine1,
1519 __p1, __r1>& __x);
1520
1521 /**
1522 * @brief Extracts the current state of a % subtract_with_carry_engine
1523 * random number generator engine @p __x from the input stream
1524 * @p __is.
1525 *
1526 * @param __is An input stream.
1527 * @param __x A %discard_block_engine random number generator engine.
1528 *
1529 * @returns The input stream with the state of @p __x extracted or in
1530 * an error state.
1531 */
1532 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1533 typename _CharT, typename _Traits>
1536 std::discard_block_engine<_RandomNumberEngine1,
1537 __p1, __r1>& __x);
1538
1539 private:
1540 _RandomNumberEngine _M_b;
1541 size_t _M_n;
1542 };
1543
1544#if __cpp_impl_three_way_comparison < 201907L
1545 /**
1546 * @brief Compares two %discard_block_engine random number generator
1547 * objects of the same type for inequality.
1548 *
1549 * @param __lhs A %discard_block_engine random number generator object.
1550 * @param __rhs Another %discard_block_engine random number generator
1551 * object.
1552 *
1553 * @returns true if the infinite sequences of generated values
1554 * would be different, false otherwise.
1555 */
1556 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1557 inline bool
1558 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1559 __r>& __lhs,
1560 const std::discard_block_engine<_RandomNumberEngine, __p,
1561 __r>& __rhs)
1562 { return !(__lhs == __rhs); }
1563#endif
1564
1565 /**
1566 * Produces random numbers by combining random numbers from some base
1567 * engine to produce random numbers with a specified number of bits @p __w.
1568 *
1569 * @headerfile random
1570 * @since C++11
1571 */
1572 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1574 {
1576 "result_type must be an unsigned integral type");
1577 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1578 "template argument substituting __w out of bounds");
1579
1580 template<typename _Sseq>
1581 using _If_seed_seq
1582 = __detail::_If_seed_seq_for<_Sseq, independent_bits_engine,
1583 _UIntType>;
1584
1585 public:
1586 /** The type of the generated random value. */
1587 typedef _UIntType result_type;
1588
1589 /**
1590 * @brief Constructs a default %independent_bits_engine engine.
1591 *
1592 * The underlying engine is default constructed as well.
1595 : _M_b() { }
1596
1597 /**
1598 * @brief Copy constructs a %independent_bits_engine engine.
1599 *
1600 * Copies an existing base class random number generator.
1601 * @param __rng An existing (base class) engine object.
1602 */
1603 explicit
1604 independent_bits_engine(const _RandomNumberEngine& __rng)
1605 : _M_b(__rng) { }
1606
1607 /**
1608 * @brief Move constructs a %independent_bits_engine engine.
1609 *
1610 * Copies an existing base class random number generator.
1611 * @param __rng An existing (base class) engine object.
1612 */
1613 explicit
1614 independent_bits_engine(_RandomNumberEngine&& __rng)
1615 : _M_b(std::move(__rng)) { }
1616
1617 /**
1618 * @brief Seed constructs a %independent_bits_engine engine.
1619 *
1620 * Constructs the underlying generator engine seeded with @p __s.
1621 * @param __s A seed value for the base class engine.
1622 */
1625 : _M_b(__s) { }
1626
1627 /**
1628 * @brief Generator construct a %independent_bits_engine engine.
1629 *
1630 * @param __q A seed sequence.
1631 */
1632 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1633 explicit
1634 independent_bits_engine(_Sseq& __q)
1635 : _M_b(__q)
1636 { }
1637
1638 /**
1639 * @brief Reseeds the %independent_bits_engine object with the default
1640 * seed for the underlying base class generator engine.
1641 */
1642 void
1643 seed()
1644 { _M_b.seed(); }
1645
1646 /**
1647 * @brief Reseeds the %independent_bits_engine object with the default
1648 * seed for the underlying base class generator engine.
1649 */
1650 void
1651 seed(result_type __s)
1652 { _M_b.seed(__s); }
1653
1654 /**
1655 * @brief Reseeds the %independent_bits_engine object with the given
1656 * seed sequence.
1657 * @param __q A seed generator function.
1658 */
1659 template<typename _Sseq>
1660 _If_seed_seq<_Sseq>
1661 seed(_Sseq& __q)
1662 { _M_b.seed(__q); }
1663
1664 /**
1665 * @brief Gets a const reference to the underlying generator engine
1666 * object.
1667 */
1668 const _RandomNumberEngine&
1669 base() const noexcept
1670 { return _M_b; }
1671
1672 /**
1673 * @brief Gets the minimum value in the generated random number range.
1674 */
1675 static constexpr result_type
1676 min()
1677 { return 0U; }
1678
1679 /**
1680 * @brief Gets the maximum value in the generated random number range.
1681 */
1682 static constexpr result_type
1683 max()
1684 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1685
1686 /**
1687 * @brief Discard a sequence of random numbers.
1688 */
1689 void
1690 discard(unsigned long long __z)
1691 {
1692 for (; __z != 0ULL; --__z)
1693 (*this)();
1694 }
1695
1696 /**
1697 * @brief Gets the next value in the generated random number sequence.
1698 */
1699 result_type
1700 operator()();
1701
1702 /**
1703 * @brief Compares two %independent_bits_engine random number generator
1704 * objects of the same type for equality.
1705 *
1706 * @param __lhs A %independent_bits_engine random number generator
1707 * object.
1708 * @param __rhs Another %independent_bits_engine random number generator
1709 * object.
1710 *
1711 * @returns true if the infinite sequences of generated values
1712 * would be equal, false otherwise.
1713 */
1714 friend bool
1716 const independent_bits_engine& __rhs)
1717 { return __lhs._M_b == __rhs._M_b; }
1718
1719 /**
1720 * @brief Extracts the current state of a % subtract_with_carry_engine
1721 * random number generator engine @p __x from the input stream
1722 * @p __is.
1723 *
1724 * @param __is An input stream.
1725 * @param __x A %independent_bits_engine random number generator
1726 * engine.
1727 *
1728 * @returns The input stream with the state of @p __x extracted or in
1729 * an error state.
1730 */
1731 template<typename _CharT, typename _Traits>
1734 std::independent_bits_engine<_RandomNumberEngine,
1735 __w, _UIntType>& __x)
1736 {
1737 __is >> __x._M_b;
1738 return __is;
1739 }
1740
1741 private:
1742 _RandomNumberEngine _M_b;
1743 };
1744
1745#if __cpp_impl_three_way_comparison < 201907L
1746 /**
1747 * @brief Compares two %independent_bits_engine random number generator
1748 * objects of the same type for inequality.
1749 *
1750 * @param __lhs A %independent_bits_engine random number generator
1751 * object.
1752 * @param __rhs Another %independent_bits_engine random number generator
1753 * object.
1754 *
1755 * @returns true if the infinite sequences of generated values
1756 * would be different, false otherwise.
1757 */
1758 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1759 inline bool
1760 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1761 _UIntType>& __lhs,
1762 const std::independent_bits_engine<_RandomNumberEngine, __w,
1763 _UIntType>& __rhs)
1764 { return !(__lhs == __rhs); }
1765#endif
1766
1767 /**
1768 * @brief Inserts the current state of a %independent_bits_engine random
1769 * number generator engine @p __x into the output stream @p __os.
1770 *
1771 * @param __os An output stream.
1772 * @param __x A %independent_bits_engine random number generator engine.
1773 *
1774 * @returns The output stream with the state of @p __x inserted or in
1775 * an error state.
1776 */
1777 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1778 typename _CharT, typename _Traits>
1779 std::basic_ostream<_CharT, _Traits>&
1780 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1781 const std::independent_bits_engine<_RandomNumberEngine,
1782 __w, _UIntType>& __x)
1783 {
1784 __os << __x.base();
1785 return __os;
1786 }
1787
1788
1789 /**
1790 * @brief Produces random numbers by reordering random numbers from some
1791 * base engine.
1792 *
1793 * The values from the base engine are stored in a sequence of size @p __k
1794 * and shuffled by an algorithm that depends on those values.
1795 *
1796 * @headerfile random
1797 * @since C++11
1798 */
1799 template<typename _RandomNumberEngine, size_t __k>
1801 {
1802 static_assert(1u <= __k, "template argument substituting "
1803 "__k out of bound");
1804
1805 public:
1806 /** The type of the generated random value. */
1807 typedef typename _RandomNumberEngine::result_type result_type;
1808
1809 template<typename _Sseq>
1810 using _If_seed_seq
1811 = __detail::_If_seed_seq_for<_Sseq, shuffle_order_engine,
1812 result_type>;
1813
1814 static constexpr size_t table_size = __k;
1815
1816 /**
1817 * @brief Constructs a default %shuffle_order_engine engine.
1818 *
1819 * The underlying engine is default constructed as well.
1822 : _M_b()
1823 { _M_initialize(); }
1824
1825 /**
1826 * @brief Copy constructs a %shuffle_order_engine engine.
1827 *
1828 * Copies an existing base class random number generator.
1829 * @param __rng An existing (base class) engine object.
1830 */
1831 explicit
1832 shuffle_order_engine(const _RandomNumberEngine& __rng)
1833 : _M_b(__rng)
1834 { _M_initialize(); }
1835
1836 /**
1837 * @brief Move constructs a %shuffle_order_engine engine.
1838 *
1839 * Copies an existing base class random number generator.
1840 * @param __rng An existing (base class) engine object.
1841 */
1842 explicit
1843 shuffle_order_engine(_RandomNumberEngine&& __rng)
1844 : _M_b(std::move(__rng))
1845 { _M_initialize(); }
1846
1847 /**
1848 * @brief Seed constructs a %shuffle_order_engine engine.
1849 *
1850 * Constructs the underlying generator engine seeded with @p __s.
1851 * @param __s A seed value for the base class engine.
1852 */
1853 explicit
1855 : _M_b(__s)
1856 { _M_initialize(); }
1857
1858 /**
1859 * @brief Generator construct a %shuffle_order_engine engine.
1860 *
1861 * @param __q A seed sequence.
1862 */
1863 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1864 explicit
1865 shuffle_order_engine(_Sseq& __q)
1866 : _M_b(__q)
1867 { _M_initialize(); }
1868
1869 /**
1870 * @brief Reseeds the %shuffle_order_engine object with the default seed
1871 for the underlying base class generator engine.
1872 */
1873 void
1874 seed()
1875 {
1876 _M_b.seed();
1877 _M_initialize();
1878 }
1879
1880 /**
1881 * @brief Reseeds the %shuffle_order_engine object with the default seed
1882 * for the underlying base class generator engine.
1883 */
1884 void
1885 seed(result_type __s)
1886 {
1887 _M_b.seed(__s);
1888 _M_initialize();
1889 }
1890
1891 /**
1892 * @brief Reseeds the %shuffle_order_engine object with the given seed
1893 * sequence.
1894 * @param __q A seed generator function.
1895 */
1896 template<typename _Sseq>
1897 _If_seed_seq<_Sseq>
1898 seed(_Sseq& __q)
1899 {
1900 _M_b.seed(__q);
1901 _M_initialize();
1902 }
1903
1904 /**
1905 * Gets a const reference to the underlying generator engine object.
1906 */
1907 const _RandomNumberEngine&
1908 base() const noexcept
1909 { return _M_b; }
1910
1911 /**
1912 * Gets the minimum value in the generated random number range.
1913 */
1914 static constexpr result_type
1915 min()
1916 { return _RandomNumberEngine::min(); }
1917
1918 /**
1919 * Gets the maximum value in the generated random number range.
1920 */
1921 static constexpr result_type
1922 max()
1923 { return _RandomNumberEngine::max(); }
1924
1925 /**
1926 * Discard a sequence of random numbers.
1927 */
1928 void
1929 discard(unsigned long long __z)
1930 {
1931 for (; __z != 0ULL; --__z)
1932 (*this)();
1933 }
1934
1935 /**
1936 * Gets the next value in the generated random number sequence.
1937 */
1939 operator()();
1940
1941 /**
1942 * Compares two %shuffle_order_engine random number generator objects
1943 * of the same type for equality.
1944 *
1945 * @param __lhs A %shuffle_order_engine random number generator object.
1946 * @param __rhs Another %shuffle_order_engine random number generator
1947 * object.
1948 *
1949 * @returns true if the infinite sequences of generated values
1950 * would be equal, false otherwise.
1951 */
1952 friend bool
1953 operator==(const shuffle_order_engine& __lhs,
1954 const shuffle_order_engine& __rhs)
1955 { return (__lhs._M_b == __rhs._M_b
1956 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1957 && __lhs._M_y == __rhs._M_y); }
1958
1959 /**
1960 * @brief Inserts the current state of a %shuffle_order_engine random
1961 * number generator engine @p __x into the output stream
1962 @p __os.
1963 *
1964 * @param __os An output stream.
1965 * @param __x A %shuffle_order_engine random number generator engine.
1966 *
1967 * @returns The output stream with the state of @p __x inserted or in
1968 * an error state.
1969 */
1970 template<typename _RandomNumberEngine1, size_t __k1,
1971 typename _CharT, typename _Traits>
1974 const std::shuffle_order_engine<_RandomNumberEngine1,
1975 __k1>& __x);
1976
1977 /**
1978 * @brief Extracts the current state of a % subtract_with_carry_engine
1979 * random number generator engine @p __x from the input stream
1980 * @p __is.
1981 *
1982 * @param __is An input stream.
1983 * @param __x A %shuffle_order_engine random number generator engine.
1984 *
1985 * @returns The input stream with the state of @p __x extracted or in
1986 * an error state.
1987 */
1988 template<typename _RandomNumberEngine1, size_t __k1,
1989 typename _CharT, typename _Traits>
1993
1994 private:
1995 void _M_initialize()
1996 {
1997 for (size_t __i = 0; __i < __k; ++__i)
1998 _M_v[__i] = _M_b();
1999 _M_y = _M_b();
2000 }
2001
2002 _RandomNumberEngine _M_b;
2003 result_type _M_v[__k];
2004 result_type _M_y;
2005 };
2006
2007#if __cpp_impl_three_way_comparison < 201907L
2008 /**
2009 * Compares two %shuffle_order_engine random number generator objects
2010 * of the same type for inequality.
2011 *
2012 * @param __lhs A %shuffle_order_engine random number generator object.
2013 * @param __rhs Another %shuffle_order_engine random number generator
2014 * object.
2015 *
2016 * @returns true if the infinite sequences of generated values
2017 * would be different, false otherwise.
2018 */
2019 template<typename _RandomNumberEngine, size_t __k>
2020 inline bool
2021 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
2022 __k>& __lhs,
2023 const std::shuffle_order_engine<_RandomNumberEngine,
2024 __k>& __rhs)
2025 { return !(__lhs == __rhs); }
2026#endif
2027
2028#if __glibcxx_philox_engine // >= C++26
2029 /**
2030 * @brief A discrete pseudorandom number generator with weak cryptographic
2031 * properties
2032 *
2033 * This algorithm was designed to be used for highly parallel random number
2034 * generation, and is capable of immensely long periods. It provides
2035 * "Crush-resistance", denoting an ability to pass the TestU01 Suite's
2036 * "Big Crush" test, demonstrating significant apparent entropy.
2037 *
2038 * It is not intended for cryptographic use and should not be used for such,
2039 * despite being based on cryptographic primitives.
2040 *
2041 * The typedefs `philox4x32` and `philox4x64` are provided as suitable
2042 * defaults for most use cases, providing high-quality random numbers
2043 * with reasonable performance.
2044 *
2045 * This algorithm was created by John Salmon, Mark Moraes, Ron Dror, and
2046 * David Shaw as a product of D.E. Shaw Research.
2047 *
2048 * @tparam __w Word size
2049 * @tparam __n Buffer size
2050 * @tparam __r Rounds
2051 * @tparam __consts Multiplication and round constant pack, ordered as
2052 * M_{0}, C_{0}, M_{1}, C_{1}, ... , M_{N/2-1}, C_{N/2-1}
2053 *
2054 * @headerfile random
2055 * @since C++26
2056 */
2057 template<typename _UIntType, size_t __w, size_t __n, size_t __r,
2058 _UIntType... __consts>
2059 class philox_engine
2060 {
2061 static_assert(__n == 2 || __n == 4,
2062 "template argument N must be either 2 or 4");
2063 static_assert(sizeof...(__consts) == __n,
2064 "length of consts array must match specified N");
2065 static_assert(0 < __r, "a number of rounds must be specified");
2066 static_assert((0 < __w && __w <= numeric_limits<_UIntType>::digits),
2067 "specified bitlength must match input type");
2068
2069 template<typename _Sseq>
2070 static constexpr bool __is_seed_seq = requires {
2071 typename __detail::_If_seed_seq_for<_Sseq, philox_engine, _UIntType>;
2072 };
2073
2074 template <size_t __ind0, size_t __ind1>
2075 static constexpr
2076 array<_UIntType, __n / 2>
2077 _S_popArray()
2078 {
2079 if constexpr (__n == 4)
2080 return {__consts...[__ind0], __consts...[__ind1]};
2081 else
2082 return {__consts...[__ind0]};
2083 }
2084
2085 public:
2086 using result_type = _UIntType;
2087 // public members
2088 static constexpr size_t word_size = __w;
2089 static constexpr size_t word_count = __n;
2090 static constexpr size_t round_count = __r;
2091 static constexpr array<result_type, __n / 2> multipliers
2092 = _S_popArray<0,2>();
2093 static constexpr array<result_type, __n / 2> round_consts
2094 = _S_popArray<1,3>();
2095
2096 /// The minimum value that this engine can return
2097 static constexpr result_type
2099 { return 0; }
2100
2101 /// The maximum value that this engine can return
2102 static constexpr result_type
2104 {
2105 return ((1ull << (__w - 1)) | ((1ull << (__w - 1)) - 1));
2106 }
2107 // default key value
2108 static constexpr result_type default_seed = 20111115u;
2109
2110 // constructors
2112 : philox_engine(default_seed)
2113 { }
2114
2115 explicit
2116 philox_engine(result_type __value)
2117 : _M_x{}, _M_k{}, _M_y{}, _M_i(__n - 1)
2118 { _M_k[0] = __value & max(); }
2119
2120 /** @brief seed sequence constructor for %philox_engine
2121 *
2122 * @param __q the seed sequence
2123 */
2124 template<typename _Sseq> requires __is_seed_seq<_Sseq>
2125 explicit
2126 philox_engine(_Sseq& __q)
2127 {
2128 seed(__q);
2129 }
2130
2131 void
2132 seed(result_type __value = default_seed)
2133 {
2134 _M_x = {};
2135 _M_y = {};
2136 _M_k = {};
2137 _M_k[0] = __value & max();
2138 _M_i = __n - 1;
2139 }
2140
2141 /** @brief seeds %philox_engine by seed sequence
2142 *
2143 * @param __q the seed sequence
2144 */
2145 template<typename _Sseq>
2146 void
2147 seed(_Sseq& __q) requires __is_seed_seq<_Sseq>;
2148
2149 /** @brief sets the internal counter "cleartext"
2150 *
2151 * @param __counter std::array of len N
2152 */
2153 void
2155 {
2156 for (size_t __j = 0; __j < __n; ++__j)
2157 _M_x[__j] = __counter[__n - 1 - __j] & max();
2158 _M_i = __n - 1;
2159 }
2160
2161 /** @brief compares two %philox_engine objects
2162 *
2163 * @returns true if the objects will produce an identical stream,
2164 * false otherwise
2165 */
2166 friend bool
2167 operator==(const philox_engine&, const philox_engine&) = default;
2168
2169 /** @brief outputs a single w-bit number and handles state advancement
2170 *
2171 * @returns return_type
2172 */
2173 result_type
2175 {
2176 _M_transition();
2177 return _M_y[_M_i];
2178 }
2179
2180 /** @brief discards __z numbers
2181 *
2182 * @param __z number of iterations to discard
2183 */
2184 void
2185 discard(unsigned long long __z)
2186 {
2187 while (__z--)
2188 _M_transition();
2189 }
2190
2191 /** @brief outputs the state of the generator
2192 *
2193 * @param __os An output stream.
2194 * @param __x A %philox_engine object reference
2195 *
2196 * @returns the state of the Philox Engine in __os
2197 */
2198 template<typename _CharT, typename _Traits>
2201 const philox_engine& __x)
2202 {
2203 const typename ios_base::fmtflags __flags = __os.flags();
2204 const _CharT __fill = __os.fill();
2206 _CharT __space = __os.widen(' ');
2207 __os.fill(__space);
2208 for (auto& __subkey : __x._M_k)
2209 __os << __subkey << __space;
2210 for (auto& __ctr : __x._M_x)
2211 __os << __ctr << __space;
2212 __os << __x._M_i;
2213 __os.flags(__flags);
2214 __os.fill(__fill);
2215 return __os;
2216 }
2217
2218 /** @brief takes input to set the state of the %philox_engine object
2219 *
2220 * @param __is An input stream.
2221 * @param __x A %philox_engine object reference
2222 *
2223 * @returns %philox_engine object is set with values from instream
2224 */
2225 template <typename _CharT, typename _Traits>
2228 philox_engine& __x)
2229 {
2230 const typename ios_base::fmtflags __flags = __is.flags();
2232 for (auto& __subkey : __x._M_k)
2233 __is >> __subkey;
2234 for (auto& __ctr : __x._M_x)
2235 __is >> __ctr;
2236 array<_UIntType, __n> __tmpCtr = __x._M_x;
2237 unsigned char __setIndex = 0;
2238 for (size_t __j = 0; __j < __x._M_x.size(); ++__j)
2239 {
2240 if (__x._M_x[__j] > 0)
2241 {
2242 __setIndex = __j;
2243 break;
2244 }
2245 }
2246 for (size_t __j = 0; __j <= __setIndex; ++__j)
2247 {
2248 if (__j != __setIndex)
2249 __x._M_x[__j] = max();
2250 else
2251 --__x._M_x[__j];
2252 }
2253 __x._M_philox();
2254 __x._M_x = __tmpCtr;
2255 __is >> __x._M_i;
2256 __is.flags(__flags);
2257 return __is;
2258 }
2259
2260 private:
2261 // private state variables
2263 array<_UIntType, __n / 2> _M_k;
2265 unsigned long long _M_i = 0;
2266
2267 // The high W bits of the product of __a and __b
2268 static _UIntType
2269 _S_mulhi(_UIntType __a, _UIntType __b); // (A*B)/2^W
2270
2271 // The low W bits of the product of __a and __b
2272 static _UIntType
2273 _S_mullo(_UIntType __a, _UIntType __b); // (A*B)%2^W
2274
2275 // An R-round substitution/Feistel Network hybrid for philox_engine
2276 void
2277 _M_philox();
2278
2279 // The transition function
2280 void
2281 _M_transition();
2282 };
2283#endif
2284
2285 /**
2286 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
2287 */
2288 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
2290
2291 /**
2292 * An alternative LCR (Lehmer Generator function).
2293 */
2296
2297 /**
2298 * The classic Mersenne Twister.
2299 *
2300 * Reference:
2301 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
2302 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
2303 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
2304 */
2306 uint_fast32_t,
2307 32, 624, 397, 31,
2308 0x9908b0dfUL, 11,
2309 0xffffffffUL, 7,
2310 0x9d2c5680UL, 15,
2311 0xefc60000UL, 18, 1812433253UL> mt19937;
2312
2313 /**
2314 * An alternative Mersenne Twister.
2315 */
2317 uint_fast64_t,
2318 64, 312, 156, 31,
2319 0xb5026f5aa96619e9ULL, 29,
2320 0x5555555555555555ULL, 17,
2321 0x71d67fffeda60000ULL, 37,
2322 0xfff7eee000000000ULL, 43,
2323 6364136223846793005ULL> mt19937_64;
2324
2326 ranlux24_base;
2327
2329 ranlux48_base;
2330
2332
2334
2336
2337 typedef minstd_rand0 default_random_engine;
2338
2339#if __glibcxx_philox_engine
2340
2341 /// 32-bit four-word Philox engine.
2342 typedef philox_engine<
2343 uint_fast32_t,
2344 32, 4, 10,
2345 0xCD9E8D57, 0x9E3779B9,
2346 0xD2511F53, 0xBB67AE85> philox4x32;
2347
2348 /// 64-bit four-word Philox engine.
2349 typedef philox_engine<
2350 uint_fast64_t,
2351 64, 4, 10,
2352 0xCA5A826395121157, 0x9E3779B97F4A7C15,
2353 0xD2E7470EE14C6C93, 0xBB67AE8584CAA73B> philox4x64;
2354#endif
2355
2356 /**
2357 * A standard interface to a platform-specific non-deterministic
2358 * random number generator (if any are available).
2359 *
2360 * @headerfile random
2361 * @since C++11
2362 */
2363 class random_device
2364 {
2365 public:
2366 /** The type of the generated random value. */
2367 typedef unsigned int result_type;
2368
2369 // constructors, destructors and member functions
2370
2371 random_device() { _M_init("default"); }
2372
2373 explicit
2374 random_device(const std::string& __token) { _M_init(__token); }
2375
2376 ~random_device()
2377 { _M_fini(); }
2378
2379 static constexpr result_type
2380 min()
2382
2383 static constexpr result_type
2384 max()
2386
2387 double
2388 entropy() const noexcept
2389 { return this->_M_getentropy(); }
2390
2392 operator()()
2393 { return this->_M_getval(); }
2394
2395 // No copy functions.
2396 random_device(const random_device&) = delete;
2397 void operator=(const random_device&) = delete;
2398
2399 private:
2400
2401 void _M_init(const std::string& __token);
2402 void _M_init_pretr1(const std::string& __token);
2403 void _M_fini();
2404
2405 result_type _M_getval();
2406 result_type _M_getval_pretr1();
2407 double _M_getentropy() const noexcept;
2408
2409 void _M_init(const char*, size_t); // not exported from the shared library
2410
2411 __extension__ union
2412 {
2413 struct
2414 {
2415 void* _M_file;
2416 result_type (*_M_func)(void*);
2417 int _M_fd;
2418 };
2419 mt19937 _M_mt;
2420 };
2421 };
2422
2423 /// @} group random_generators
2424
2425 /**
2426 * @addtogroup random_distributions Random Number Distributions
2427 * @ingroup random
2428 * @{
2429 */
2430
2431 /**
2432 * @addtogroup random_distributions_uniform Uniform Distributions
2433 * @ingroup random_distributions
2434 * @{
2435 */
2436
2437 // std::uniform_int_distribution is defined in <bits/uniform_int_dist.h>
2438
2439#if __cpp_impl_three_way_comparison < 201907L
2440 /**
2441 * @brief Return true if two uniform integer distributions have
2442 * different parameters.
2443 */
2444 template<typename _IntType>
2445 inline bool
2446 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
2447 const std::uniform_int_distribution<_IntType>& __d2)
2448 { return !(__d1 == __d2); }
2449#endif
2450
2451 /**
2452 * @brief Inserts a %uniform_int_distribution random number
2453 * distribution @p __x into the output stream @p os.
2454 *
2455 * @param __os An output stream.
2456 * @param __x A %uniform_int_distribution random number distribution.
2457 *
2458 * @returns The output stream with the state of @p __x inserted or in
2459 * an error state.
2460 */
2461 template<typename _IntType, typename _CharT, typename _Traits>
2462 std::basic_ostream<_CharT, _Traits>&
2463 operator<<(std::basic_ostream<_CharT, _Traits>&,
2464 const std::uniform_int_distribution<_IntType>&);
2465
2466 /**
2467 * @brief Extracts a %uniform_int_distribution random number distribution
2468 * @p __x from the input stream @p __is.
2469 *
2470 * @param __is An input stream.
2471 * @param __x A %uniform_int_distribution random number generator engine.
2472 *
2473 * @returns The input stream with @p __x extracted or in an error state.
2474 */
2475 template<typename _IntType, typename _CharT, typename _Traits>
2476 std::basic_istream<_CharT, _Traits>&
2477 operator>>(std::basic_istream<_CharT, _Traits>&,
2478 std::uniform_int_distribution<_IntType>&);
2479
2480
2481 /**
2482 * @brief Uniform continuous distribution for random numbers.
2483 *
2484 * A continuous random distribution on the range [min, max) with equal
2485 * probability throughout the range. The URNG should be real-valued and
2486 * deliver number in the range [0, 1).
2487 *
2488 * @headerfile random
2489 * @since C++11
2490 */
2491 template<typename _RealType = double>
2493 {
2495 "result_type must be a floating point type");
2496
2497 public:
2498 /** The type of the range of the distribution. */
2499 typedef _RealType result_type;
2500
2501 /** Parameter type. */
2502 struct param_type
2503 {
2504 typedef uniform_real_distribution<_RealType> distribution_type;
2505
2506 param_type() : param_type(0) { }
2507
2508 explicit
2509 param_type(_RealType __a, _RealType __b = _RealType(1))
2510 : _M_a(__a), _M_b(__b)
2511 {
2512 __glibcxx_assert(_M_a <= _M_b);
2513 }
2514
2516 a() const
2517 { return _M_a; }
2518
2520 b() const
2521 { return _M_b; }
2522
2523 friend bool
2524 operator==(const param_type& __p1, const param_type& __p2)
2525 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2526
2527#if __cpp_impl_three_way_comparison < 201907L
2528 friend bool
2529 operator!=(const param_type& __p1, const param_type& __p2)
2530 { return !(__p1 == __p2); }
2531#endif
2532
2533 private:
2534 _RealType _M_a;
2535 _RealType _M_b;
2536 };
2537
2538 public:
2539 /**
2540 * @brief Constructs a uniform_real_distribution object.
2541 *
2542 * The lower bound is set to 0.0 and the upper bound to 1.0
2543 */
2545
2546 /**
2547 * @brief Constructs a uniform_real_distribution object.
2548 *
2549 * @param __a [IN] The lower bound of the distribution.
2550 * @param __b [IN] The upper bound of the distribution.
2551 */
2552 explicit
2553 uniform_real_distribution(_RealType __a, _RealType __b = _RealType(1))
2554 : _M_param(__a, __b)
2555 { }
2556
2557 explicit
2558 uniform_real_distribution(const param_type& __p)
2559 : _M_param(__p)
2560 { }
2561
2562 /**
2563 * @brief Resets the distribution state.
2564 *
2565 * Does nothing for the uniform real distribution.
2566 */
2567 void
2568 reset() { }
2569
2570 result_type
2571 a() const
2572 { return _M_param.a(); }
2573
2574 result_type
2575 b() const
2576 { return _M_param.b(); }
2577
2578 /**
2579 * @brief Returns the parameter set of the distribution.
2580 */
2582 param() const
2583 { return _M_param; }
2584
2585 /**
2586 * @brief Sets the parameter set of the distribution.
2587 * @param __param The new parameter set of the distribution.
2588 */
2589 void
2590 param(const param_type& __param)
2591 { _M_param = __param; }
2592
2593 /**
2594 * @brief Returns the inclusive lower bound of the distribution range.
2595 */
2596 result_type
2597 min() const
2598 { return this->a(); }
2599
2600 /**
2601 * @brief Returns the inclusive upper bound of the distribution range.
2602 */
2603 result_type
2604 max() const
2605 { return this->b(); }
2606
2607 /**
2608 * @brief Generating functions.
2609 */
2610 template<typename _UniformRandomNumberGenerator>
2611 result_type
2612 operator()(_UniformRandomNumberGenerator& __urng)
2613 { return this->operator()(__urng, _M_param); }
2614
2615 template<typename _UniformRandomNumberGenerator>
2616 result_type
2617 operator()(_UniformRandomNumberGenerator& __urng,
2618 const param_type& __p)
2619 {
2620 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2621 __aurng(__urng);
2622 return (__aurng() * (__p.b() - __p.a())) + __p.a();
2623 }
2624
2625 template<typename _ForwardIterator,
2626 typename _UniformRandomNumberGenerator>
2627 void
2628 __generate(_ForwardIterator __f, _ForwardIterator __t,
2629 _UniformRandomNumberGenerator& __urng)
2630 { this->__generate(__f, __t, __urng, _M_param); }
2631
2632 template<typename _ForwardIterator,
2633 typename _UniformRandomNumberGenerator>
2634 void
2635 __generate(_ForwardIterator __f, _ForwardIterator __t,
2636 _UniformRandomNumberGenerator& __urng,
2637 const param_type& __p)
2638 { this->__generate_impl(__f, __t, __urng, __p); }
2639
2640 template<typename _UniformRandomNumberGenerator>
2641 void
2642 __generate(result_type* __f, result_type* __t,
2643 _UniformRandomNumberGenerator& __urng,
2644 const param_type& __p)
2645 { this->__generate_impl(__f, __t, __urng, __p); }
2646
2647 /**
2648 * @brief Return true if two uniform real distributions have
2649 * the same parameters.
2650 */
2651 friend bool
2653 const uniform_real_distribution& __d2)
2654 { return __d1._M_param == __d2._M_param; }
2655
2656 private:
2657 template<typename _ForwardIterator,
2658 typename _UniformRandomNumberGenerator>
2659 void
2660 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2661 _UniformRandomNumberGenerator& __urng,
2662 const param_type& __p);
2663
2664 param_type _M_param;
2665 };
2666
2667#if __cpp_impl_three_way_comparison < 201907L
2668 /**
2669 * @brief Return true if two uniform real distributions have
2670 * different parameters.
2671 */
2672 template<typename _IntType>
2673 inline bool
2674 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
2676 { return !(__d1 == __d2); }
2677#endif
2678
2679 /**
2680 * @brief Inserts a %uniform_real_distribution random number
2681 * distribution @p __x into the output stream @p __os.
2682 *
2683 * @param __os An output stream.
2684 * @param __x A %uniform_real_distribution random number distribution.
2685 *
2686 * @returns The output stream with the state of @p __x inserted or in
2687 * an error state.
2688 */
2689 template<typename _RealType, typename _CharT, typename _Traits>
2690 std::basic_ostream<_CharT, _Traits>&
2691 operator<<(std::basic_ostream<_CharT, _Traits>&,
2692 const std::uniform_real_distribution<_RealType>&);
2693
2694 /**
2695 * @brief Extracts a %uniform_real_distribution random number distribution
2696 * @p __x from the input stream @p __is.
2697 *
2698 * @param __is An input stream.
2699 * @param __x A %uniform_real_distribution random number generator engine.
2700 *
2701 * @returns The input stream with @p __x extracted or in an error state.
2702 */
2703 template<typename _RealType, typename _CharT, typename _Traits>
2704 std::basic_istream<_CharT, _Traits>&
2705 operator>>(std::basic_istream<_CharT, _Traits>&,
2706 std::uniform_real_distribution<_RealType>&);
2707
2708 /// @} group random_distributions_uniform
2709
2710 /**
2711 * @addtogroup random_distributions_normal Normal Distributions
2712 * @ingroup random_distributions
2713 * @{
2714 */
2715
2716 /**
2717 * @brief A normal continuous distribution for random numbers.
2718 *
2719 * The formula for the normal probability density function is
2720 * @f[
2721 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
2722 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
2723 * @f]
2724 *
2725 * @headerfile random
2726 * @since C++11
2727 */
2728 template<typename _RealType = double>
2729 class normal_distribution
2730 {
2732 "result_type must be a floating point type");
2733
2734 public:
2735 /** The type of the range of the distribution. */
2736 typedef _RealType result_type;
2737
2738 /** Parameter type. */
2739 struct param_type
2740 {
2741 typedef normal_distribution<_RealType> distribution_type;
2742
2743 param_type() : param_type(0.0) { }
2744
2745 explicit
2746 param_type(_RealType __mean, _RealType __stddev = _RealType(1))
2747 : _M_mean(__mean), _M_stddev(__stddev)
2748 {
2749 __glibcxx_assert(_M_stddev > _RealType(0));
2750 }
2751
2752 _RealType
2753 mean() const
2754 { return _M_mean; }
2755
2756 _RealType
2757 stddev() const
2758 { return _M_stddev; }
2759
2760 friend bool
2761 operator==(const param_type& __p1, const param_type& __p2)
2762 { return (__p1._M_mean == __p2._M_mean
2763 && __p1._M_stddev == __p2._M_stddev); }
2764
2765#if __cpp_impl_three_way_comparison < 201907L
2766 friend bool
2767 operator!=(const param_type& __p1, const param_type& __p2)
2768 { return !(__p1 == __p2); }
2769#endif
2770
2771 private:
2772 _RealType _M_mean;
2773 _RealType _M_stddev;
2774 };
2775
2776 public:
2777 normal_distribution() : normal_distribution(0.0) { }
2778
2779 /**
2780 * Constructs a normal distribution with parameters @f$mean@f$ and
2781 * standard deviation.
2782 */
2783 explicit
2785 result_type __stddev = result_type(1))
2786 : _M_param(__mean, __stddev)
2787 { }
2788
2789 explicit
2790 normal_distribution(const param_type& __p)
2791 : _M_param(__p)
2792 { }
2793
2794 /**
2795 * @brief Resets the distribution state.
2796 */
2797 void
2799 { _M_saved_available = false; }
2800
2801 /**
2802 * @brief Returns the mean of the distribution.
2803 */
2804 _RealType
2805 mean() const
2806 { return _M_param.mean(); }
2807
2808 /**
2809 * @brief Returns the standard deviation of the distribution.
2810 */
2811 _RealType
2812 stddev() const
2813 { return _M_param.stddev(); }
2814
2815 /**
2816 * @brief Returns the parameter set of the distribution.
2817 */
2818 param_type
2819 param() const
2820 { return _M_param; }
2821
2822 /**
2823 * @brief Sets the parameter set of the distribution.
2824 * @param __param The new parameter set of the distribution.
2825 */
2826 void
2827 param(const param_type& __param)
2828 { _M_param = __param; }
2829
2830 /**
2831 * @brief Returns the greatest lower bound value of the distribution.
2832 */
2833 result_type
2836
2837 /**
2838 * @brief Returns the least upper bound value of the distribution.
2839 */
2840 result_type
2841 max() const
2843
2844 /**
2845 * @brief Generating functions.
2846 */
2847 template<typename _UniformRandomNumberGenerator>
2848 result_type
2849 operator()(_UniformRandomNumberGenerator& __urng)
2850 { return this->operator()(__urng, _M_param); }
2851
2852 template<typename _UniformRandomNumberGenerator>
2853 result_type
2854 operator()(_UniformRandomNumberGenerator& __urng,
2855 const param_type& __p);
2856
2857 template<typename _ForwardIterator,
2858 typename _UniformRandomNumberGenerator>
2859 void
2860 __generate(_ForwardIterator __f, _ForwardIterator __t,
2861 _UniformRandomNumberGenerator& __urng)
2862 { this->__generate(__f, __t, __urng, _M_param); }
2863
2864 template<typename _ForwardIterator,
2865 typename _UniformRandomNumberGenerator>
2866 void
2867 __generate(_ForwardIterator __f, _ForwardIterator __t,
2868 _UniformRandomNumberGenerator& __urng,
2869 const param_type& __p)
2870 { this->__generate_impl(__f, __t, __urng, __p); }
2871
2872 template<typename _UniformRandomNumberGenerator>
2873 void
2874 __generate(result_type* __f, result_type* __t,
2875 _UniformRandomNumberGenerator& __urng,
2876 const param_type& __p)
2877 { this->__generate_impl(__f, __t, __urng, __p); }
2878
2879 /**
2880 * @brief Return true if two normal distributions have
2881 * the same parameters and the sequences that would
2882 * be generated are equal.
2883 */
2884 template<typename _RealType1>
2885 friend bool
2888
2889 /**
2890 * @brief Inserts a %normal_distribution random number distribution
2891 * @p __x into the output stream @p __os.
2892 *
2893 * @param __os An output stream.
2894 * @param __x A %normal_distribution random number distribution.
2895 *
2896 * @returns The output stream with the state of @p __x inserted or in
2897 * an error state.
2898 */
2899 template<typename _RealType1, typename _CharT, typename _Traits>
2903
2904 /**
2905 * @brief Extracts a %normal_distribution random number distribution
2906 * @p __x from the input stream @p __is.
2907 *
2908 * @param __is An input stream.
2909 * @param __x A %normal_distribution random number generator engine.
2910 *
2911 * @returns The input stream with @p __x extracted or in an error
2912 * state.
2913 */
2914 template<typename _RealType1, typename _CharT, typename _Traits>
2918
2919 private:
2920 template<typename _ForwardIterator,
2921 typename _UniformRandomNumberGenerator>
2922 void
2923 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2924 _UniformRandomNumberGenerator& __urng,
2925 const param_type& __p);
2926
2927 param_type _M_param;
2928 result_type _M_saved = 0;
2929 bool _M_saved_available = false;
2930 };
2931
2932#if __cpp_impl_three_way_comparison < 201907L
2933 /**
2934 * @brief Return true if two normal distributions are different.
2935 */
2936 template<typename _RealType>
2937 inline bool
2938 operator!=(const std::normal_distribution<_RealType>& __d1,
2940 { return !(__d1 == __d2); }
2941#endif
2942
2943 /**
2944 * @brief A lognormal_distribution random number distribution.
2945 *
2946 * The formula for the normal probability mass function is
2947 * @f[
2948 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2949 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2950 * @f]
2951 *
2952 * @headerfile random
2953 * @since C++11
2954 */
2955 template<typename _RealType = double>
2956 class lognormal_distribution
2957 {
2959 "result_type must be a floating point type");
2960
2961 public:
2962 /** The type of the range of the distribution. */
2963 typedef _RealType result_type;
2964
2965 /** Parameter type. */
2966 struct param_type
2967 {
2968 typedef lognormal_distribution<_RealType> distribution_type;
2969
2970 param_type() : param_type(0.0) { }
2971
2972 explicit
2973 param_type(_RealType __m, _RealType __s = _RealType(1))
2974 : _M_m(__m), _M_s(__s)
2975 { }
2976
2977 _RealType
2978 m() const
2979 { return _M_m; }
2980
2981 _RealType
2982 s() const
2983 { return _M_s; }
2984
2985 friend bool
2986 operator==(const param_type& __p1, const param_type& __p2)
2987 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2988
2989#if __cpp_impl_three_way_comparison < 201907L
2990 friend bool
2991 operator!=(const param_type& __p1, const param_type& __p2)
2992 { return !(__p1 == __p2); }
2993#endif
2994
2995 private:
2996 _RealType _M_m;
2997 _RealType _M_s;
2998 };
2999
3000 lognormal_distribution() : lognormal_distribution(0.0) { }
3001
3002 explicit
3003 lognormal_distribution(_RealType __m, _RealType __s = _RealType(1))
3004 : _M_param(__m, __s), _M_nd()
3005 { }
3006
3007 explicit
3008 lognormal_distribution(const param_type& __p)
3009 : _M_param(__p), _M_nd()
3010 { }
3011
3012 /**
3013 * Resets the distribution state.
3014 */
3015 void
3017 { _M_nd.reset(); }
3018
3019 /**
3020 *
3021 */
3022 _RealType
3023 m() const
3024 { return _M_param.m(); }
3025
3026 _RealType
3027 s() const
3028 { return _M_param.s(); }
3029
3030 /**
3031 * @brief Returns the parameter set of the distribution.
3032 */
3034 param() const
3035 { return _M_param; }
3036
3037 /**
3038 * @brief Sets the parameter set of the distribution.
3039 * @param __param The new parameter set of the distribution.
3040 */
3041 void
3042 param(const param_type& __param)
3043 { _M_param = __param; }
3044
3045 /**
3046 * @brief Returns the greatest lower bound value of the distribution.
3047 */
3048 result_type
3049 min() const
3050 { return result_type(0); }
3051
3052 /**
3053 * @brief Returns the least upper bound value of the distribution.
3054 */
3055 result_type
3056 max() const
3058
3059 /**
3060 * @brief Generating functions.
3061 */
3062 template<typename _UniformRandomNumberGenerator>
3063 result_type
3064 operator()(_UniformRandomNumberGenerator& __urng)
3065 { return this->operator()(__urng, _M_param); }
3066
3067 template<typename _UniformRandomNumberGenerator>
3068 result_type
3069 operator()(_UniformRandomNumberGenerator& __urng,
3070 const param_type& __p)
3071 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
3072
3073 template<typename _ForwardIterator,
3074 typename _UniformRandomNumberGenerator>
3075 void
3076 __generate(_ForwardIterator __f, _ForwardIterator __t,
3077 _UniformRandomNumberGenerator& __urng)
3078 { this->__generate(__f, __t, __urng, _M_param); }
3079
3080 template<typename _ForwardIterator,
3081 typename _UniformRandomNumberGenerator>
3082 void
3083 __generate(_ForwardIterator __f, _ForwardIterator __t,
3084 _UniformRandomNumberGenerator& __urng,
3085 const param_type& __p)
3086 { this->__generate_impl(__f, __t, __urng, __p); }
3087
3088 template<typename _UniformRandomNumberGenerator>
3089 void
3090 __generate(result_type* __f, result_type* __t,
3091 _UniformRandomNumberGenerator& __urng,
3092 const param_type& __p)
3093 { this->__generate_impl(__f, __t, __urng, __p); }
3094
3095 /**
3096 * @brief Return true if two lognormal distributions have
3097 * the same parameters and the sequences that would
3098 * be generated are equal.
3099 */
3100 friend bool
3101 operator==(const lognormal_distribution& __d1,
3102 const lognormal_distribution& __d2)
3103 { return (__d1._M_param == __d2._M_param
3104 && __d1._M_nd == __d2._M_nd); }
3105
3106 /**
3107 * @brief Inserts a %lognormal_distribution random number distribution
3108 * @p __x into the output stream @p __os.
3109 *
3110 * @param __os An output stream.
3111 * @param __x A %lognormal_distribution random number distribution.
3112 *
3113 * @returns The output stream with the state of @p __x inserted or in
3114 * an error state.
3115 */
3116 template<typename _RealType1, typename _CharT, typename _Traits>
3120
3121 /**
3122 * @brief Extracts a %lognormal_distribution random number distribution
3123 * @p __x from the input stream @p __is.
3124 *
3125 * @param __is An input stream.
3126 * @param __x A %lognormal_distribution random number
3127 * generator engine.
3128 *
3129 * @returns The input stream with @p __x extracted or in an error state.
3130 */
3131 template<typename _RealType1, typename _CharT, typename _Traits>
3135
3136 private:
3137 template<typename _ForwardIterator,
3138 typename _UniformRandomNumberGenerator>
3139 void
3140 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3141 _UniformRandomNumberGenerator& __urng,
3142 const param_type& __p);
3143
3144 param_type _M_param;
3145
3147 };
3148
3149#if __cpp_impl_three_way_comparison < 201907L
3150 /**
3151 * @brief Return true if two lognormal distributions are different.
3152 */
3153 template<typename _RealType>
3154 inline bool
3155 operator!=(const std::lognormal_distribution<_RealType>& __d1,
3157 { return !(__d1 == __d2); }
3158#endif
3159
3160 /// @} group random_distributions_normal
3161
3162 /**
3163 * @addtogroup random_distributions_poisson Poisson Distributions
3164 * @ingroup random_distributions
3165 * @{
3166 */
3167
3168 /**
3169 * @brief A gamma continuous distribution for random numbers.
3170 *
3171 * The formula for the gamma probability density function is:
3172 * @f[
3173 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
3174 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
3175 * @f]
3176 *
3177 * @headerfile random
3178 * @since C++11
3179 */
3180 template<typename _RealType = double>
3182 {
3184 "result_type must be a floating point type");
3185
3186 public:
3187 /** The type of the range of the distribution. */
3188 typedef _RealType result_type;
3189
3190 /** Parameter type. */
3191 struct param_type
3192 {
3193 typedef gamma_distribution<_RealType> distribution_type;
3194 friend class gamma_distribution<_RealType>;
3195
3196 param_type() : param_type(1.0) { }
3197
3198 explicit
3199 param_type(_RealType __alpha_val, _RealType __beta_val = _RealType(1))
3200 : _M_alpha(__alpha_val), _M_beta(__beta_val)
3201 {
3202 __glibcxx_assert(_M_alpha > _RealType(0));
3203 _M_initialize();
3204 }
3205
3206 _RealType
3207 alpha() const
3208 { return _M_alpha; }
3209
3210 _RealType
3211 beta() const
3212 { return _M_beta; }
3213
3214 friend bool
3215 operator==(const param_type& __p1, const param_type& __p2)
3216 { return (__p1._M_alpha == __p2._M_alpha
3217 && __p1._M_beta == __p2._M_beta); }
3218
3219#if __cpp_impl_three_way_comparison < 201907L
3220 friend bool
3221 operator!=(const param_type& __p1, const param_type& __p2)
3222 { return !(__p1 == __p2); }
3223#endif
3224
3225 private:
3226 void
3227 _M_initialize();
3228
3229 _RealType _M_alpha;
3230 _RealType _M_beta;
3231
3232 _RealType _M_malpha, _M_a2;
3233 };
3234
3235 public:
3236 /**
3237 * @brief Constructs a gamma distribution with parameters 1 and 1.
3238 */
3240
3241 /**
3242 * @brief Constructs a gamma distribution with parameters
3243 * @f$\alpha@f$ and @f$\beta@f$.
3244 */
3245 explicit
3246 gamma_distribution(_RealType __alpha_val,
3247 _RealType __beta_val = _RealType(1))
3248 : _M_param(__alpha_val, __beta_val), _M_nd()
3249 { }
3250
3251 explicit
3252 gamma_distribution(const param_type& __p)
3253 : _M_param(__p), _M_nd()
3254 { }
3255
3256 /**
3257 * @brief Resets the distribution state.
3258 */
3259 void
3261 { _M_nd.reset(); }
3262
3263 /**
3264 * @brief Returns the @f$\alpha@f$ of the distribution.
3265 */
3266 _RealType
3267 alpha() const
3268 { return _M_param.alpha(); }
3269
3270 /**
3271 * @brief Returns the @f$\beta@f$ of the distribution.
3272 */
3273 _RealType
3274 beta() const
3275 { return _M_param.beta(); }
3276
3277 /**
3278 * @brief Returns the parameter set of the distribution.
3279 */
3280 param_type
3281 param() const
3282 { return _M_param; }
3283
3284 /**
3285 * @brief Sets the parameter set of the distribution.
3286 * @param __param The new parameter set of the distribution.
3287 */
3288 void
3289 param(const param_type& __param)
3290 { _M_param = __param; }
3291
3292 /**
3293 * @brief Returns the greatest lower bound value of the distribution.
3294 */
3295 result_type
3296 min() const
3297 { return result_type(0); }
3298
3299 /**
3300 * @brief Returns the least upper bound value of the distribution.
3301 */
3302 result_type
3303 max() const
3305
3306 /**
3307 * @brief Generating functions.
3308 */
3309 template<typename _UniformRandomNumberGenerator>
3310 result_type
3311 operator()(_UniformRandomNumberGenerator& __urng)
3312 { return this->operator()(__urng, _M_param); }
3313
3314 template<typename _UniformRandomNumberGenerator>
3315 result_type
3316 operator()(_UniformRandomNumberGenerator& __urng,
3317 const param_type& __p);
3318
3319 template<typename _ForwardIterator,
3320 typename _UniformRandomNumberGenerator>
3321 void
3322 __generate(_ForwardIterator __f, _ForwardIterator __t,
3323 _UniformRandomNumberGenerator& __urng)
3324 { this->__generate(__f, __t, __urng, _M_param); }
3325
3326 template<typename _ForwardIterator,
3327 typename _UniformRandomNumberGenerator>
3328 void
3329 __generate(_ForwardIterator __f, _ForwardIterator __t,
3330 _UniformRandomNumberGenerator& __urng,
3331 const param_type& __p)
3332 { this->__generate_impl(__f, __t, __urng, __p); }
3333
3334 template<typename _UniformRandomNumberGenerator>
3335 void
3336 __generate(result_type* __f, result_type* __t,
3337 _UniformRandomNumberGenerator& __urng,
3338 const param_type& __p)
3339 { this->__generate_impl(__f, __t, __urng, __p); }
3340
3341 /**
3342 * @brief Return true if two gamma distributions have the same
3343 * parameters and the sequences that would be generated
3344 * are equal.
3345 */
3346 friend bool
3348 const gamma_distribution& __d2)
3349 { return (__d1._M_param == __d2._M_param
3350 && __d1._M_nd == __d2._M_nd); }
3351
3352 /**
3353 * @brief Inserts a %gamma_distribution random number distribution
3354 * @p __x into the output stream @p __os.
3355 *
3356 * @param __os An output stream.
3357 * @param __x A %gamma_distribution random number distribution.
3358 *
3359 * @returns The output stream with the state of @p __x inserted or in
3360 * an error state.
3361 */
3362 template<typename _RealType1, typename _CharT, typename _Traits>
3366
3367 /**
3368 * @brief Extracts a %gamma_distribution random number distribution
3369 * @p __x from the input stream @p __is.
3370 *
3371 * @param __is An input stream.
3372 * @param __x A %gamma_distribution random number generator engine.
3373 *
3374 * @returns The input stream with @p __x extracted or in an error state.
3375 */
3376 template<typename _RealType1, typename _CharT, typename _Traits>
3380
3381 private:
3382 template<typename _ForwardIterator,
3383 typename _UniformRandomNumberGenerator>
3384 void
3385 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3386 _UniformRandomNumberGenerator& __urng,
3387 const param_type& __p);
3388
3389 param_type _M_param;
3390
3392 };
3393
3394#if __cpp_impl_three_way_comparison < 201907L
3395 /**
3396 * @brief Return true if two gamma distributions are different.
3397 */
3398 template<typename _RealType>
3399 inline bool
3400 operator!=(const std::gamma_distribution<_RealType>& __d1,
3402 { return !(__d1 == __d2); }
3403#endif
3404
3405 /// @} group random_distributions_poisson
3406
3407 /**
3408 * @addtogroup random_distributions_normal Normal Distributions
3409 * @ingroup random_distributions
3410 * @{
3411 */
3412
3413 /**
3414 * @brief A chi_squared_distribution random number distribution.
3415 *
3416 * The formula for the normal probability mass function is
3417 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
3418 *
3419 * @headerfile random
3420 * @since C++11
3421 */
3422 template<typename _RealType = double>
3423 class chi_squared_distribution
3424 {
3426 "result_type must be a floating point type");
3427
3428 public:
3429 /** The type of the range of the distribution. */
3430 typedef _RealType result_type;
3431
3432 /** Parameter type. */
3433 struct param_type
3434 {
3435 typedef chi_squared_distribution<_RealType> distribution_type;
3436
3437 param_type() : param_type(1) { }
3438
3439 explicit
3440 param_type(_RealType __n)
3441 : _M_n(__n)
3442 { }
3443
3444 _RealType
3445 n() const
3446 { return _M_n; }
3447
3448 friend bool
3449 operator==(const param_type& __p1, const param_type& __p2)
3450 { return __p1._M_n == __p2._M_n; }
3451
3452#if __cpp_impl_three_way_comparison < 201907L
3453 friend bool
3454 operator!=(const param_type& __p1, const param_type& __p2)
3455 { return !(__p1 == __p2); }
3456#endif
3457
3458 private:
3459 _RealType _M_n;
3460 };
3461
3462 chi_squared_distribution() : chi_squared_distribution(1) { }
3463
3464 explicit
3465 chi_squared_distribution(_RealType __n)
3466 : _M_param(__n), _M_gd(__n / 2)
3467 { }
3468
3469 explicit
3470 chi_squared_distribution(const param_type& __p)
3471 : _M_param(__p), _M_gd(__p.n() / 2)
3472 { }
3473
3474 /**
3475 * @brief Resets the distribution state.
3476 */
3477 void
3479 { _M_gd.reset(); }
3480
3481 /**
3482 *
3483 */
3484 _RealType
3485 n() const
3486 { return _M_param.n(); }
3487
3488 /**
3489 * @brief Returns the parameter set of the distribution.
3490 */
3491 param_type
3492 param() const
3493 { return _M_param; }
3494
3495 /**
3496 * @brief Sets the parameter set of the distribution.
3497 * @param __param The new parameter set of the distribution.
3498 */
3499 void
3500 param(const param_type& __param)
3501 {
3502 _M_param = __param;
3503
3504 using param_type
3506 _M_gd.param(param_type(__param.n() / 2));
3507 }
3508
3509 /**
3510 * @brief Returns the greatest lower bound value of the distribution.
3511 */
3512 result_type
3513 min() const
3514 { return result_type(0); }
3515
3516 /**
3517 * @brief Returns the least upper bound value of the distribution.
3518 */
3519 result_type
3520 max() const
3522
3523 /**
3524 * @brief Generating functions.
3525 */
3526 template<typename _UniformRandomNumberGenerator>
3527 result_type
3528 operator()(_UniformRandomNumberGenerator& __urng)
3529 { return 2 * _M_gd(__urng); }
3530
3531 template<typename _UniformRandomNumberGenerator>
3532 result_type
3533 operator()(_UniformRandomNumberGenerator& __urng,
3534 const param_type& __p)
3535 {
3537 param_type;
3538 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
3539 }
3540
3541 template<typename _ForwardIterator,
3542 typename _UniformRandomNumberGenerator>
3543 void
3544 __generate(_ForwardIterator __f, _ForwardIterator __t,
3545 _UniformRandomNumberGenerator& __urng)
3546 { this->__generate_impl(__f, __t, __urng); }
3547
3548 template<typename _ForwardIterator,
3549 typename _UniformRandomNumberGenerator>
3550 void
3551 __generate(_ForwardIterator __f, _ForwardIterator __t,
3552 _UniformRandomNumberGenerator& __urng,
3553 const param_type& __p)
3554 { typename std::gamma_distribution<result_type>::param_type
3555 __p2(__p.n() / 2);
3556 this->__generate_impl(__f, __t, __urng, __p2); }
3557
3558 template<typename _UniformRandomNumberGenerator>
3559 void
3560 __generate(result_type* __f, result_type* __t,
3561 _UniformRandomNumberGenerator& __urng)
3562 { this->__generate_impl(__f, __t, __urng); }
3563
3564 template<typename _UniformRandomNumberGenerator>
3565 void
3566 __generate(result_type* __f, result_type* __t,
3567 _UniformRandomNumberGenerator& __urng,
3568 const param_type& __p)
3569 { typename std::gamma_distribution<result_type>::param_type
3570 __p2(__p.n() / 2);
3571 this->__generate_impl(__f, __t, __urng, __p2); }
3572
3573 /**
3574 * @brief Return true if two Chi-squared distributions have
3575 * the same parameters and the sequences that would be
3576 * generated are equal.
3577 */
3578 friend bool
3579 operator==(const chi_squared_distribution& __d1,
3580 const chi_squared_distribution& __d2)
3581 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
3582
3583 /**
3584 * @brief Inserts a %chi_squared_distribution random number distribution
3585 * @p __x into the output stream @p __os.
3586 *
3587 * @param __os An output stream.
3588 * @param __x A %chi_squared_distribution random number distribution.
3589 *
3590 * @returns The output stream with the state of @p __x inserted or in
3591 * an error state.
3592 */
3593 template<typename _RealType1, typename _CharT, typename _Traits>
3597
3598 /**
3599 * @brief Extracts a %chi_squared_distribution random number distribution
3600 * @p __x from the input stream @p __is.
3601 *
3602 * @param __is An input stream.
3603 * @param __x A %chi_squared_distribution random number
3604 * generator engine.
3605 *
3606 * @returns The input stream with @p __x extracted or in an error state.
3607 */
3608 template<typename _RealType1, typename _CharT, typename _Traits>
3612
3613 private:
3614 template<typename _ForwardIterator,
3615 typename _UniformRandomNumberGenerator>
3616 void
3617 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3618 _UniformRandomNumberGenerator& __urng);
3619
3620 template<typename _ForwardIterator,
3621 typename _UniformRandomNumberGenerator>
3622 void
3623 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3624 _UniformRandomNumberGenerator& __urng,
3625 const typename
3627
3628 param_type _M_param;
3629
3631 };
3632
3633#if __cpp_impl_three_way_comparison < 201907L
3634 /**
3635 * @brief Return true if two Chi-squared distributions are different.
3636 */
3637 template<typename _RealType>
3638 inline bool
3639 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
3641 { return !(__d1 == __d2); }
3642#endif
3643
3644 /**
3645 * @brief A cauchy_distribution random number distribution.
3646 *
3647 * The formula for the normal probability mass function is
3648 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
3649 *
3650 * @headerfile random
3651 * @since C++11
3652 */
3653 template<typename _RealType = double>
3654 class cauchy_distribution
3655 {
3657 "result_type must be a floating point type");
3658
3659 public:
3660 /** The type of the range of the distribution. */
3661 typedef _RealType result_type;
3662
3663 /** Parameter type. */
3664 struct param_type
3665 {
3666 typedef cauchy_distribution<_RealType> distribution_type;
3667
3668 param_type() : param_type(0) { }
3669
3670 explicit
3671 param_type(_RealType __a, _RealType __b = _RealType(1))
3672 : _M_a(__a), _M_b(__b)
3673 { }
3674
3675 _RealType
3676 a() const
3677 { return _M_a; }
3678
3679 _RealType
3680 b() const
3681 { return _M_b; }
3682
3683 friend bool
3684 operator==(const param_type& __p1, const param_type& __p2)
3685 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
3686
3687#if __cpp_impl_three_way_comparison < 201907L
3688 friend bool
3689 operator!=(const param_type& __p1, const param_type& __p2)
3690 { return !(__p1 == __p2); }
3691#endif
3692
3693 private:
3694 _RealType _M_a;
3695 _RealType _M_b;
3696 };
3697
3698 cauchy_distribution() : cauchy_distribution(0.0) { }
3699
3700 explicit
3701 cauchy_distribution(_RealType __a, _RealType __b = 1.0)
3702 : _M_param(__a, __b)
3703 { }
3704
3705 explicit
3706 cauchy_distribution(const param_type& __p)
3707 : _M_param(__p)
3708 { }
3709
3710 /**
3711 * @brief Resets the distribution state.
3712 */
3713 void
3715 { }
3716
3717 /**
3718 *
3719 */
3720 _RealType
3721 a() const
3722 { return _M_param.a(); }
3723
3724 _RealType
3725 b() const
3726 { return _M_param.b(); }
3727
3728 /**
3729 * @brief Returns the parameter set of the distribution.
3730 */
3732 param() const
3733 { return _M_param; }
3734
3735 /**
3736 * @brief Sets the parameter set of the distribution.
3737 * @param __param The new parameter set of the distribution.
3738 */
3739 void
3740 param(const param_type& __param)
3741 { _M_param = __param; }
3742
3743 /**
3744 * @brief Returns the greatest lower bound value of the distribution.
3745 */
3746 result_type
3749
3750 /**
3751 * @brief Returns the least upper bound value of the distribution.
3752 */
3753 result_type
3754 max() const
3756
3757 /**
3758 * @brief Generating functions.
3759 */
3760 template<typename _UniformRandomNumberGenerator>
3761 result_type
3762 operator()(_UniformRandomNumberGenerator& __urng)
3763 { return this->operator()(__urng, _M_param); }
3764
3765 template<typename _UniformRandomNumberGenerator>
3766 result_type
3767 operator()(_UniformRandomNumberGenerator& __urng,
3768 const param_type& __p);
3769
3770 template<typename _ForwardIterator,
3771 typename _UniformRandomNumberGenerator>
3772 void
3773 __generate(_ForwardIterator __f, _ForwardIterator __t,
3774 _UniformRandomNumberGenerator& __urng)
3775 { this->__generate(__f, __t, __urng, _M_param); }
3776
3777 template<typename _ForwardIterator,
3778 typename _UniformRandomNumberGenerator>
3779 void
3780 __generate(_ForwardIterator __f, _ForwardIterator __t,
3781 _UniformRandomNumberGenerator& __urng,
3782 const param_type& __p)
3783 { this->__generate_impl(__f, __t, __urng, __p); }
3784
3785 template<typename _UniformRandomNumberGenerator>
3786 void
3787 __generate(result_type* __f, result_type* __t,
3788 _UniformRandomNumberGenerator& __urng,
3789 const param_type& __p)
3790 { this->__generate_impl(__f, __t, __urng, __p); }
3791
3792 /**
3793 * @brief Return true if two Cauchy distributions have
3794 * the same parameters.
3795 */
3796 friend bool
3797 operator==(const cauchy_distribution& __d1,
3798 const cauchy_distribution& __d2)
3799 { return __d1._M_param == __d2._M_param; }
3800
3801 private:
3802 template<typename _ForwardIterator,
3803 typename _UniformRandomNumberGenerator>
3804 void
3805 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3806 _UniformRandomNumberGenerator& __urng,
3807 const param_type& __p);
3808
3809 param_type _M_param;
3810 };
3811
3812#if __cpp_impl_three_way_comparison < 201907L
3813 /**
3814 * @brief Return true if two Cauchy distributions have
3815 * different parameters.
3816 */
3817 template<typename _RealType>
3818 inline bool
3819 operator!=(const std::cauchy_distribution<_RealType>& __d1,
3821 { return !(__d1 == __d2); }
3822#endif
3823
3824 /**
3825 * @brief Inserts a %cauchy_distribution random number distribution
3826 * @p __x into the output stream @p __os.
3827 *
3828 * @param __os An output stream.
3829 * @param __x A %cauchy_distribution random number distribution.
3830 *
3831 * @returns The output stream with the state of @p __x inserted or in
3832 * an error state.
3833 */
3834 template<typename _RealType, typename _CharT, typename _Traits>
3835 std::basic_ostream<_CharT, _Traits>&
3836 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3837 const std::cauchy_distribution<_RealType>& __x);
3838
3839 /**
3840 * @brief Extracts a %cauchy_distribution random number distribution
3841 * @p __x from the input stream @p __is.
3842 *
3843 * @param __is An input stream.
3844 * @param __x A %cauchy_distribution random number
3845 * generator engine.
3846 *
3847 * @returns The input stream with @p __x extracted or in an error state.
3848 */
3849 template<typename _RealType, typename _CharT, typename _Traits>
3850 std::basic_istream<_CharT, _Traits>&
3851 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3852 std::cauchy_distribution<_RealType>& __x);
3853
3854
3855 /**
3856 * @brief A fisher_f_distribution random number distribution.
3857 *
3858 * The formula for the normal probability mass function is
3859 * @f[
3860 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3861 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3862 * (1 + \frac{mx}{n})^{-(m+n)/2}
3863 * @f]
3864 *
3865 * @headerfile random
3866 * @since C++11
3867 */
3868 template<typename _RealType = double>
3869 class fisher_f_distribution
3870 {
3872 "result_type must be a floating point type");
3873
3874 public:
3875 /** The type of the range of the distribution. */
3876 typedef _RealType result_type;
3877
3878 /** Parameter type. */
3879 struct param_type
3880 {
3881 typedef fisher_f_distribution<_RealType> distribution_type;
3882
3883 param_type() : param_type(1) { }
3884
3885 explicit
3886 param_type(_RealType __m, _RealType __n = _RealType(1))
3887 : _M_m(__m), _M_n(__n)
3888 { }
3889
3890 _RealType
3891 m() const
3892 { return _M_m; }
3893
3894 _RealType
3895 n() const
3896 { return _M_n; }
3897
3898 friend bool
3899 operator==(const param_type& __p1, const param_type& __p2)
3900 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
3901
3902#if __cpp_impl_three_way_comparison < 201907L
3903 friend bool
3904 operator!=(const param_type& __p1, const param_type& __p2)
3905 { return !(__p1 == __p2); }
3906#endif
3907
3908 private:
3909 _RealType _M_m;
3910 _RealType _M_n;
3911 };
3912
3913 fisher_f_distribution() : fisher_f_distribution(1.0) { }
3914
3915 explicit
3916 fisher_f_distribution(_RealType __m,
3917 _RealType __n = _RealType(1))
3918 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
3919 { }
3920
3921 explicit
3922 fisher_f_distribution(const param_type& __p)
3923 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
3924 { }
3925
3926 /**
3927 * @brief Resets the distribution state.
3928 */
3929 void
3931 {
3932 _M_gd_x.reset();
3933 _M_gd_y.reset();
3934 }
3935
3936 /**
3937 *
3938 */
3939 _RealType
3940 m() const
3941 { return _M_param.m(); }
3942
3943 _RealType
3944 n() const
3945 { return _M_param.n(); }
3946
3947 /**
3948 * @brief Returns the parameter set of the distribution.
3949 */
3951 param() const
3952 { return _M_param; }
3953
3954 /**
3955 * @brief Sets the parameter set of the distribution.
3956 * @param __param The new parameter set of the distribution.
3957 */
3958 void
3959 param(const param_type& __param)
3960 {
3961 _M_param = __param;
3962
3963 using param_type
3965 _M_gd_x.param(param_type(__param.m() / 2));
3966 _M_gd_y.param(param_type(__param.n() / 2));
3967 }
3968
3969 /**
3970 * @brief Returns the greatest lower bound value of the distribution.
3971 */
3972 result_type
3973 min() const
3974 { return result_type(0); }
3975
3976 /**
3977 * @brief Returns the least upper bound value of the distribution.
3978 */
3979 result_type
3980 max() const
3982
3983 /**
3984 * @brief Generating functions.
3985 */
3986 template<typename _UniformRandomNumberGenerator>
3987 result_type
3988 operator()(_UniformRandomNumberGenerator& __urng)
3989 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
3990
3991 template<typename _UniformRandomNumberGenerator>
3992 result_type
3993 operator()(_UniformRandomNumberGenerator& __urng,
3994 const param_type& __p)
3995 {
3997 param_type;
3998 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
3999 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
4000 }
4001
4002 template<typename _ForwardIterator,
4003 typename _UniformRandomNumberGenerator>
4004 void
4005 __generate(_ForwardIterator __f, _ForwardIterator __t,
4006 _UniformRandomNumberGenerator& __urng)
4007 { this->__generate_impl(__f, __t, __urng); }
4008
4009 template<typename _ForwardIterator,
4010 typename _UniformRandomNumberGenerator>
4011 void
4012 __generate(_ForwardIterator __f, _ForwardIterator __t,
4013 _UniformRandomNumberGenerator& __urng,
4014 const param_type& __p)
4015 { this->__generate_impl(__f, __t, __urng, __p); }
4016
4017 template<typename _UniformRandomNumberGenerator>
4018 void
4019 __generate(result_type* __f, result_type* __t,
4020 _UniformRandomNumberGenerator& __urng)
4021 { this->__generate_impl(__f, __t, __urng); }
4022
4023 template<typename _UniformRandomNumberGenerator>
4024 void
4025 __generate(result_type* __f, result_type* __t,
4026 _UniformRandomNumberGenerator& __urng,
4027 const param_type& __p)
4028 { this->__generate_impl(__f, __t, __urng, __p); }
4029
4030 /**
4031 * @brief Return true if two Fisher f distributions have
4032 * the same parameters and the sequences that would
4033 * be generated are equal.
4034 */
4035 friend bool
4036 operator==(const fisher_f_distribution& __d1,
4037 const fisher_f_distribution& __d2)
4038 { return (__d1._M_param == __d2._M_param
4039 && __d1._M_gd_x == __d2._M_gd_x
4040 && __d1._M_gd_y == __d2._M_gd_y); }
4041
4042 /**
4043 * @brief Inserts a %fisher_f_distribution random number distribution
4044 * @p __x into the output stream @p __os.
4045 *
4046 * @param __os An output stream.
4047 * @param __x A %fisher_f_distribution random number distribution.
4048 *
4049 * @returns The output stream with the state of @p __x inserted or in
4050 * an error state.
4051 */
4052 template<typename _RealType1, typename _CharT, typename _Traits>
4056
4057 /**
4058 * @brief Extracts a %fisher_f_distribution random number distribution
4059 * @p __x from the input stream @p __is.
4060 *
4061 * @param __is An input stream.
4062 * @param __x A %fisher_f_distribution random number
4063 * generator engine.
4064 *
4065 * @returns The input stream with @p __x extracted or in an error state.
4066 */
4067 template<typename _RealType1, typename _CharT, typename _Traits>
4071
4072 private:
4073 template<typename _ForwardIterator,
4074 typename _UniformRandomNumberGenerator>
4075 void
4076 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4077 _UniformRandomNumberGenerator& __urng);
4078
4079 template<typename _ForwardIterator,
4080 typename _UniformRandomNumberGenerator>
4081 void
4082 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4083 _UniformRandomNumberGenerator& __urng,
4084 const param_type& __p);
4085
4086 param_type _M_param;
4087
4088 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
4089 };
4090
4091#if __cpp_impl_three_way_comparison < 201907L
4092 /**
4093 * @brief Return true if two Fisher f distributions are different.
4094 */
4095 template<typename _RealType>
4096 inline bool
4097 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
4099 { return !(__d1 == __d2); }
4100#endif
4101
4102 /**
4103 * @brief A student_t_distribution random number distribution.
4104 *
4105 * The formula for the normal probability mass function is:
4106 * @f[
4107 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
4108 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
4109 * @f]
4110 *
4111 * @headerfile random
4112 * @since C++11
4113 */
4114 template<typename _RealType = double>
4115 class student_t_distribution
4116 {
4118 "result_type must be a floating point type");
4119
4120 public:
4121 /** The type of the range of the distribution. */
4122 typedef _RealType result_type;
4123
4124 /** Parameter type. */
4125 struct param_type
4126 {
4127 typedef student_t_distribution<_RealType> distribution_type;
4128
4129 param_type() : param_type(1) { }
4130
4131 explicit
4132 param_type(_RealType __n)
4133 : _M_n(__n)
4134 { }
4135
4136 _RealType
4137 n() const
4138 { return _M_n; }
4139
4140 friend bool
4141 operator==(const param_type& __p1, const param_type& __p2)
4142 { return __p1._M_n == __p2._M_n; }
4143
4144#if __cpp_impl_three_way_comparison < 201907L
4145 friend bool
4146 operator!=(const param_type& __p1, const param_type& __p2)
4147 { return !(__p1 == __p2); }
4148#endif
4149
4150 private:
4151 _RealType _M_n;
4152 };
4153
4154 student_t_distribution() : student_t_distribution(1.0) { }
4155
4156 explicit
4157 student_t_distribution(_RealType __n)
4158 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
4159 { }
4160
4161 explicit
4162 student_t_distribution(const param_type& __p)
4163 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
4164 { }
4165
4166 /**
4167 * @brief Resets the distribution state.
4168 */
4169 void
4171 {
4172 _M_nd.reset();
4173 _M_gd.reset();
4174 }
4175
4176 /**
4177 *
4178 */
4179 _RealType
4180 n() const
4181 { return _M_param.n(); }
4182
4183 /**
4184 * @brief Returns the parameter set of the distribution.
4185 */
4186 param_type
4187 param() const
4188 { return _M_param; }
4189
4190 /**
4191 * @brief Sets the parameter set of the distribution.
4192 * @param __param The new parameter set of the distribution.
4193 */
4194 void
4195 param(const param_type& __param)
4196 {
4197 _M_param = __param;
4198
4199 using param_type
4201 _M_gd.param(param_type(__param.n() / 2, 2));
4202 }
4203
4204 /**
4205 * @brief Returns the greatest lower bound value of the distribution.
4206 */
4207 result_type
4210
4211 /**
4212 * @brief Returns the least upper bound value of the distribution.
4213 */
4214 result_type
4215 max() const
4217
4218 /**
4219 * @brief Generating functions.
4220 */
4221 template<typename _UniformRandomNumberGenerator>
4222 result_type
4223 operator()(_UniformRandomNumberGenerator& __urng)
4224 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
4225
4226 template<typename _UniformRandomNumberGenerator>
4227 result_type
4228 operator()(_UniformRandomNumberGenerator& __urng,
4229 const param_type& __p)
4230 {
4232 param_type;
4233
4234 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
4235 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
4236 }
4237
4238 template<typename _ForwardIterator,
4239 typename _UniformRandomNumberGenerator>
4240 void
4241 __generate(_ForwardIterator __f, _ForwardIterator __t,
4242 _UniformRandomNumberGenerator& __urng)
4243 { this->__generate_impl(__f, __t, __urng); }
4244
4245 template<typename _ForwardIterator,
4246 typename _UniformRandomNumberGenerator>
4247 void
4248 __generate(_ForwardIterator __f, _ForwardIterator __t,
4249 _UniformRandomNumberGenerator& __urng,
4250 const param_type& __p)
4251 { this->__generate_impl(__f, __t, __urng, __p); }
4252
4253 template<typename _UniformRandomNumberGenerator>
4254 void
4255 __generate(result_type* __f, result_type* __t,
4256 _UniformRandomNumberGenerator& __urng)
4257 { this->__generate_impl(__f, __t, __urng); }
4258
4259 template<typename _UniformRandomNumberGenerator>
4260 void
4261 __generate(result_type* __f, result_type* __t,
4262 _UniformRandomNumberGenerator& __urng,
4263 const param_type& __p)
4264 { this->__generate_impl(__f, __t, __urng, __p); }
4265
4266 /**
4267 * @brief Return true if two Student t distributions have
4268 * the same parameters and the sequences that would
4269 * be generated are equal.
4270 */
4271 friend bool
4272 operator==(const student_t_distribution& __d1,
4273 const student_t_distribution& __d2)
4274 { return (__d1._M_param == __d2._M_param
4275 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
4276
4277 /**
4278 * @brief Inserts a %student_t_distribution random number distribution
4279 * @p __x into the output stream @p __os.
4280 *
4281 * @param __os An output stream.
4282 * @param __x A %student_t_distribution random number distribution.
4283 *
4284 * @returns The output stream with the state of @p __x inserted or in
4285 * an error state.
4286 */
4287 template<typename _RealType1, typename _CharT, typename _Traits>
4291
4292 /**
4293 * @brief Extracts a %student_t_distribution random number distribution
4294 * @p __x from the input stream @p __is.
4295 *
4296 * @param __is An input stream.
4297 * @param __x A %student_t_distribution random number
4298 * generator engine.
4299 *
4300 * @returns The input stream with @p __x extracted or in an error state.
4301 */
4302 template<typename _RealType1, typename _CharT, typename _Traits>
4306
4307 private:
4308 template<typename _ForwardIterator,
4309 typename _UniformRandomNumberGenerator>
4310 void
4311 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4312 _UniformRandomNumberGenerator& __urng);
4313 template<typename _ForwardIterator,
4314 typename _UniformRandomNumberGenerator>
4315 void
4316 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4317 _UniformRandomNumberGenerator& __urng,
4318 const param_type& __p);
4319
4320 param_type _M_param;
4321
4324 };
4325
4326#if __cpp_impl_three_way_comparison < 201907L
4327 /**
4328 * @brief Return true if two Student t distributions are different.
4329 */
4330 template<typename _RealType>
4331 inline bool
4332 operator!=(const std::student_t_distribution<_RealType>& __d1,
4334 { return !(__d1 == __d2); }
4335#endif
4336
4337 /// @} group random_distributions_normal
4338
4339 /**
4340 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
4341 * @ingroup random_distributions
4342 * @{
4343 */
4344
4345 /**
4346 * @brief A Bernoulli random number distribution.
4347 *
4348 * Generates a sequence of true and false values with likelihood @f$p@f$
4349 * that true will come up and @f$(1 - p)@f$ that false will appear.
4350 *
4351 * @headerfile random
4352 * @since C++11
4353 */
4355 {
4356 public:
4357 /** The type of the range of the distribution. */
4358 typedef bool result_type;
4359
4360 /** Parameter type. */
4361 struct param_type
4362 {
4363 typedef bernoulli_distribution distribution_type;
4364
4365 param_type() : param_type(0.5) { }
4366
4367 explicit
4368 param_type(double __p)
4369 : _M_p(__p)
4370 {
4371 __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0));
4372 }
4373
4374 double
4375 p() const
4376 { return _M_p; }
4377
4378 friend bool
4379 operator==(const param_type& __p1, const param_type& __p2)
4380 { return __p1._M_p == __p2._M_p; }
4381
4382#if __cpp_impl_three_way_comparison < 201907L
4383 friend bool
4384 operator!=(const param_type& __p1, const param_type& __p2)
4385 { return !(__p1 == __p2); }
4386#endif
4387
4388 private:
4389 double _M_p;
4390 };
4391
4392 public:
4393 /**
4394 * @brief Constructs a Bernoulli distribution with likelihood 0.5.
4395 */
4397
4398 /**
4399 * @brief Constructs a Bernoulli distribution with likelihood @p p.
4400 *
4401 * @param __p [IN] The likelihood of a true result being returned.
4402 * Must be in the interval @f$[0, 1]@f$.
4403 */
4404 explicit
4406 : _M_param(__p)
4407 { }
4408
4409 explicit
4410 bernoulli_distribution(const param_type& __p)
4411 : _M_param(__p)
4412 { }
4413
4414 /**
4415 * @brief Resets the distribution state.
4416 *
4417 * Does nothing for a Bernoulli distribution.
4418 */
4419 void
4420 reset() { }
4421
4422 /**
4423 * @brief Returns the @p p parameter of the distribution.
4424 */
4425 double
4426 p() const
4427 { return _M_param.p(); }
4428
4429 /**
4430 * @brief Returns the parameter set of the distribution.
4431 */
4432 param_type
4433 param() const
4434 { return _M_param; }
4435
4436 /**
4437 * @brief Sets the parameter set of the distribution.
4438 * @param __param The new parameter set of the distribution.
4439 */
4440 void
4441 param(const param_type& __param)
4442 { _M_param = __param; }
4443
4444 /**
4445 * @brief Returns the greatest lower bound value of the distribution.
4446 */
4447 result_type
4448 min() const
4450
4451 /**
4452 * @brief Returns the least upper bound value of the distribution.
4453 */
4454 result_type
4455 max() const
4457
4458 /**
4459 * @brief Generating functions.
4460 */
4461 template<typename _UniformRandomNumberGenerator>
4462 result_type
4463 operator()(_UniformRandomNumberGenerator& __urng)
4464 { return this->operator()(__urng, _M_param); }
4465
4466 template<typename _UniformRandomNumberGenerator>
4467 result_type
4468 operator()(_UniformRandomNumberGenerator& __urng,
4469 const param_type& __p)
4470 {
4471 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
4472 __aurng(__urng);
4473 if ((__aurng() - __aurng.min())
4474 < __p.p() * (__aurng.max() - __aurng.min()))
4475 return true;
4476 return false;
4477 }
4478
4479 template<typename _ForwardIterator,
4480 typename _UniformRandomNumberGenerator>
4481 void
4482 __generate(_ForwardIterator __f, _ForwardIterator __t,
4483 _UniformRandomNumberGenerator& __urng)
4484 { this->__generate(__f, __t, __urng, _M_param); }
4485
4486 template<typename _ForwardIterator,
4487 typename _UniformRandomNumberGenerator>
4488 void
4489 __generate(_ForwardIterator __f, _ForwardIterator __t,
4490 _UniformRandomNumberGenerator& __urng, const param_type& __p)
4491 { this->__generate_impl(__f, __t, __urng, __p); }
4492
4493 template<typename _UniformRandomNumberGenerator>
4494 void
4495 __generate(result_type* __f, result_type* __t,
4496 _UniformRandomNumberGenerator& __urng,
4497 const param_type& __p)
4498 { this->__generate_impl(__f, __t, __urng, __p); }
4499
4500 /**
4501 * @brief Return true if two Bernoulli distributions have
4502 * the same parameters.
4503 */
4504 friend bool
4506 const bernoulli_distribution& __d2)
4507 { return __d1._M_param == __d2._M_param; }
4508
4509 private:
4510 template<typename _ForwardIterator,
4511 typename _UniformRandomNumberGenerator>
4512 void
4513 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4514 _UniformRandomNumberGenerator& __urng,
4515 const param_type& __p);
4516
4517 param_type _M_param;
4518 };
4519
4520#if __cpp_impl_three_way_comparison < 201907L
4521 /**
4522 * @brief Return true if two Bernoulli distributions have
4523 * different parameters.
4524 */
4525 inline bool
4526 operator!=(const std::bernoulli_distribution& __d1,
4527 const std::bernoulli_distribution& __d2)
4528 { return !(__d1 == __d2); }
4529#endif
4530
4531 /**
4532 * @brief Inserts a %bernoulli_distribution random number distribution
4533 * @p __x into the output stream @p __os.
4534 *
4535 * @param __os An output stream.
4536 * @param __x A %bernoulli_distribution random number distribution.
4537 *
4538 * @returns The output stream with the state of @p __x inserted or in
4539 * an error state.
4540 */
4541 template<typename _CharT, typename _Traits>
4542 std::basic_ostream<_CharT, _Traits>&
4543 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4544 const std::bernoulli_distribution& __x);
4545
4546 /**
4547 * @brief Extracts a %bernoulli_distribution random number distribution
4548 * @p __x from the input stream @p __is.
4549 *
4550 * @param __is An input stream.
4551 * @param __x A %bernoulli_distribution random number generator engine.
4552 *
4553 * @returns The input stream with @p __x extracted or in an error state.
4554 */
4555 template<typename _CharT, typename _Traits>
4556 inline std::basic_istream<_CharT, _Traits>&
4559 {
4560 double __p;
4561 if (__is >> __p)
4563 return __is;
4564 }
4565
4566
4567 /**
4568 * @brief A discrete binomial random number distribution.
4569 *
4570 * The formula for the binomial probability density function is
4571 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4572 * and @f$p@f$ are the parameters of the distribution.
4573 *
4574 * @headerfile random
4575 * @since C++11
4576 */
4577 template<typename _IntType = int>
4578 class binomial_distribution
4579 {
4581 "result_type must be an integral type");
4582
4583 public:
4584 /** The type of the range of the distribution. */
4585 typedef _IntType result_type;
4586
4587 /** Parameter type. */
4588 struct param_type
4589 {
4590 typedef binomial_distribution<_IntType> distribution_type;
4591 friend class binomial_distribution<_IntType>;
4592
4593 param_type() : param_type(1) { }
4594
4595 explicit
4596 param_type(_IntType __t, double __p = 0.5)
4597 : _M_t(__t), _M_p(__p)
4598 {
4599 __glibcxx_assert((_M_t >= _IntType(0))
4600 && (_M_p >= 0.0)
4601 && (_M_p <= 1.0));
4602 _M_initialize();
4603 }
4604
4605 _IntType
4606 t() const
4607 { return _M_t; }
4608
4609 double
4610 p() const
4611 { return _M_p; }
4612
4613 friend bool
4614 operator==(const param_type& __p1, const param_type& __p2)
4615 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
4616
4617#if __cpp_impl_three_way_comparison < 201907L
4618 friend bool
4619 operator!=(const param_type& __p1, const param_type& __p2)
4620 { return !(__p1 == __p2); }
4621#endif
4622
4623 private:
4624 void
4625 _M_initialize();
4626
4627 _IntType _M_t;
4628 double _M_p;
4629
4630 double _M_q;
4631#if _GLIBCXX_USE_C99_MATH_FUNCS
4632 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
4633 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
4634#endif
4635 bool _M_easy;
4636 };
4637
4638 // constructors and member functions
4639
4640 binomial_distribution() : binomial_distribution(1) { }
4641
4642 explicit
4643 binomial_distribution(_IntType __t, double __p = 0.5)
4644 : _M_param(__t, __p), _M_nd()
4645 { }
4646
4647 explicit
4648 binomial_distribution(const param_type& __p)
4649 : _M_param(__p), _M_nd()
4650 { }
4651
4652 /**
4653 * @brief Resets the distribution state.
4654 */
4655 void
4657 { _M_nd.reset(); }
4658
4659 /**
4660 * @brief Returns the distribution @p t parameter.
4661 */
4662 _IntType
4663 t() const
4664 { return _M_param.t(); }
4665
4666 /**
4667 * @brief Returns the distribution @p p parameter.
4668 */
4669 double
4670 p() const
4671 { return _M_param.p(); }
4672
4673 /**
4674 * @brief Returns the parameter set of the distribution.
4675 */
4676 param_type
4677 param() const
4678 { return _M_param; }
4679
4680 /**
4681 * @brief Sets the parameter set of the distribution.
4682 * @param __param The new parameter set of the distribution.
4683 */
4684 void
4685 param(const param_type& __param)
4686 { _M_param = __param; }
4687
4688 /**
4689 * @brief Returns the greatest lower bound value of the distribution.
4690 */
4691 result_type
4692 min() const
4693 { return 0; }
4694
4695 /**
4696 * @brief Returns the least upper bound value of the distribution.
4697 */
4698 result_type
4699 max() const
4700 { return _M_param.t(); }
4701
4702 /**
4703 * @brief Generating functions.
4704 */
4705 template<typename _UniformRandomNumberGenerator>
4706 result_type
4707 operator()(_UniformRandomNumberGenerator& __urng)
4708 { return this->operator()(__urng, _M_param); }
4709
4710 template<typename _UniformRandomNumberGenerator>
4711 result_type
4712 operator()(_UniformRandomNumberGenerator& __urng,
4713 const param_type& __p);
4714
4715 template<typename _ForwardIterator,
4716 typename _UniformRandomNumberGenerator>
4717 void
4718 __generate(_ForwardIterator __f, _ForwardIterator __t,
4719 _UniformRandomNumberGenerator& __urng)
4720 { this->__generate(__f, __t, __urng, _M_param); }
4721
4722 template<typename _ForwardIterator,
4723 typename _UniformRandomNumberGenerator>
4724 void
4725 __generate(_ForwardIterator __f, _ForwardIterator __t,
4726 _UniformRandomNumberGenerator& __urng,
4727 const param_type& __p)
4728 { this->__generate_impl(__f, __t, __urng, __p); }
4729
4730 template<typename _UniformRandomNumberGenerator>
4731 void
4732 __generate(result_type* __f, result_type* __t,
4733 _UniformRandomNumberGenerator& __urng,
4734 const param_type& __p)
4735 { this->__generate_impl(__f, __t, __urng, __p); }
4736
4737 /**
4738 * @brief Return true if two binomial distributions have
4739 * the same parameters and the sequences that would
4740 * be generated are equal.
4741 */
4742 friend bool
4743 operator==(const binomial_distribution& __d1,
4744 const binomial_distribution& __d2)
4745#ifdef _GLIBCXX_USE_C99_MATH_FUNCS
4746 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4747#else
4748 { return __d1._M_param == __d2._M_param; }
4749#endif
4750
4751 /**
4752 * @brief Inserts a %binomial_distribution random number distribution
4753 * @p __x into the output stream @p __os.
4754 *
4755 * @param __os An output stream.
4756 * @param __x A %binomial_distribution random number distribution.
4757 *
4758 * @returns The output stream with the state of @p __x inserted or in
4759 * an error state.
4760 */
4761 template<typename _IntType1,
4762 typename _CharT, typename _Traits>
4766
4767 /**
4768 * @brief Extracts a %binomial_distribution random number distribution
4769 * @p __x from the input stream @p __is.
4770 *
4771 * @param __is An input stream.
4772 * @param __x A %binomial_distribution random number generator engine.
4773 *
4774 * @returns The input stream with @p __x extracted or in an error
4775 * state.
4776 */
4777 template<typename _IntType1,
4778 typename _CharT, typename _Traits>
4782
4783 private:
4784 template<typename _ForwardIterator,
4785 typename _UniformRandomNumberGenerator>
4786 void
4787 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4788 _UniformRandomNumberGenerator& __urng,
4789 const param_type& __p);
4790
4791 template<typename _UniformRandomNumberGenerator>
4793 _M_waiting(_UniformRandomNumberGenerator& __urng,
4794 _IntType __t, double __q);
4795
4796 param_type _M_param;
4797
4798 // NB: Unused when _GLIBCXX_USE_C99_MATH_FUNCS is undefined.
4800 };
4801
4802#if __cpp_impl_three_way_comparison < 201907L
4803 /**
4804 * @brief Return true if two binomial distributions are different.
4805 */
4806 template<typename _IntType>
4807 inline bool
4808 operator!=(const std::binomial_distribution<_IntType>& __d1,
4810 { return !(__d1 == __d2); }
4811#endif
4812
4813 /**
4814 * @brief A discrete geometric random number distribution.
4815 *
4816 * The formula for the geometric probability density function is
4817 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
4818 * distribution.
4819 *
4820 * @headerfile random
4821 * @since C++11
4822 */
4823 template<typename _IntType = int>
4824 class geometric_distribution
4825 {
4827 "result_type must be an integral type");
4828
4829 public:
4830 /** The type of the range of the distribution. */
4831 typedef _IntType result_type;
4832
4833 /** Parameter type. */
4834 struct param_type
4835 {
4836 typedef geometric_distribution<_IntType> distribution_type;
4837 friend class geometric_distribution<_IntType>;
4838
4839 param_type() : param_type(0.5) { }
4840
4841 explicit
4842 param_type(double __p)
4843 : _M_p(__p)
4844 {
4845 __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0));
4846 _M_initialize();
4847 }
4848
4849 double
4850 p() const
4851 { return _M_p; }
4852
4853 friend bool
4854 operator==(const param_type& __p1, const param_type& __p2)
4855 { return __p1._M_p == __p2._M_p; }
4856
4857#if __cpp_impl_three_way_comparison < 201907L
4858 friend bool
4859 operator!=(const param_type& __p1, const param_type& __p2)
4860 { return !(__p1 == __p2); }
4861#endif
4862
4863 private:
4864 void
4865 _M_initialize()
4866 { _M_log_1_p = std::log(1.0 - _M_p); }
4867
4868 double _M_p;
4869
4870 double _M_log_1_p;
4871 };
4872
4873 // constructors and member functions
4874
4875 geometric_distribution() : geometric_distribution(0.5) { }
4876
4877 explicit
4878 geometric_distribution(double __p)
4879 : _M_param(__p)
4880 { }
4881
4882 explicit
4883 geometric_distribution(const param_type& __p)
4884 : _M_param(__p)
4885 { }
4886
4887 /**
4888 * @brief Resets the distribution state.
4889 *
4890 * Does nothing for the geometric distribution.
4891 */
4892 void
4893 reset() { }
4894
4895 /**
4896 * @brief Returns the distribution parameter @p p.
4897 */
4898 double
4899 p() const
4900 { return _M_param.p(); }
4901
4902 /**
4903 * @brief Returns the parameter set of the distribution.
4904 */
4905 param_type
4906 param() const
4907 { return _M_param; }
4908
4909 /**
4910 * @brief Sets the parameter set of the distribution.
4911 * @param __param The new parameter set of the distribution.
4912 */
4913 void
4914 param(const param_type& __param)
4915 { _M_param = __param; }
4916
4917 /**
4918 * @brief Returns the greatest lower bound value of the distribution.
4919 */
4920 result_type
4921 min() const
4922 { return 0; }
4923
4924 /**
4925 * @brief Returns the least upper bound value of the distribution.
4926 */
4927 result_type
4928 max() const
4930
4931 /**
4932 * @brief Generating functions.
4933 */
4934 template<typename _UniformRandomNumberGenerator>
4935 result_type
4936 operator()(_UniformRandomNumberGenerator& __urng)
4937 { return this->operator()(__urng, _M_param); }
4938
4939 template<typename _UniformRandomNumberGenerator>
4940 result_type
4941 operator()(_UniformRandomNumberGenerator& __urng,
4942 const param_type& __p);
4943
4944 template<typename _ForwardIterator,
4945 typename _UniformRandomNumberGenerator>
4946 void
4947 __generate(_ForwardIterator __f, _ForwardIterator __t,
4948 _UniformRandomNumberGenerator& __urng)
4949 { this->__generate(__f, __t, __urng, _M_param); }
4950
4951 template<typename _ForwardIterator,
4952 typename _UniformRandomNumberGenerator>
4953 void
4954 __generate(_ForwardIterator __f, _ForwardIterator __t,
4955 _UniformRandomNumberGenerator& __urng,
4956 const param_type& __p)
4957 { this->__generate_impl(__f, __t, __urng, __p); }
4958
4959 template<typename _UniformRandomNumberGenerator>
4960 void
4961 __generate(result_type* __f, result_type* __t,
4962 _UniformRandomNumberGenerator& __urng,
4963 const param_type& __p)
4964 { this->__generate_impl(__f, __t, __urng, __p); }
4965
4966 /**
4967 * @brief Return true if two geometric distributions have
4968 * the same parameters.
4969 */
4970 friend bool
4971 operator==(const geometric_distribution& __d1,
4972 const geometric_distribution& __d2)
4973 { return __d1._M_param == __d2._M_param; }
4974
4975 private:
4976 template<typename _ForwardIterator,
4977 typename _UniformRandomNumberGenerator>
4978 void
4979 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4980 _UniformRandomNumberGenerator& __urng,
4981 const param_type& __p);
4982
4983 param_type _M_param;
4984 };
4985
4986#if __cpp_impl_three_way_comparison < 201907L
4987 /**
4988 * @brief Return true if two geometric distributions have
4989 * different parameters.
4990 */
4991 template<typename _IntType>
4992 inline bool
4993 operator!=(const std::geometric_distribution<_IntType>& __d1,
4995 { return !(__d1 == __d2); }
4996#endif
4997
4998 /**
4999 * @brief Inserts a %geometric_distribution random number distribution
5000 * @p __x into the output stream @p __os.
5001 *
5002 * @param __os An output stream.
5003 * @param __x A %geometric_distribution random number distribution.
5004 *
5005 * @returns The output stream with the state of @p __x inserted or in
5006 * an error state.
5007 */
5008 template<typename _IntType,
5009 typename _CharT, typename _Traits>
5010 std::basic_ostream<_CharT, _Traits>&
5011 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5012 const std::geometric_distribution<_IntType>& __x);
5013
5014 /**
5015 * @brief Extracts a %geometric_distribution random number distribution
5016 * @p __x from the input stream @p __is.
5017 *
5018 * @param __is An input stream.
5019 * @param __x A %geometric_distribution random number generator engine.
5020 *
5021 * @returns The input stream with @p __x extracted or in an error state.
5022 */
5023 template<typename _IntType,
5024 typename _CharT, typename _Traits>
5025 std::basic_istream<_CharT, _Traits>&
5026 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5027 std::geometric_distribution<_IntType>& __x);
5028
5029
5030 /**
5031 * @brief A negative_binomial_distribution random number distribution.
5032 *
5033 * The formula for the negative binomial probability mass function is
5034 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
5035 * and @f$p@f$ are the parameters of the distribution.
5036 *
5037 * @headerfile random
5038 * @since C++11
5039 */
5040 template<typename _IntType = int>
5041 class negative_binomial_distribution
5042 {
5044 "result_type must be an integral type");
5045
5046 public:
5047 /** The type of the range of the distribution. */
5048 typedef _IntType result_type;
5049
5050 /** Parameter type. */
5051 struct param_type
5052 {
5053 typedef negative_binomial_distribution<_IntType> distribution_type;
5054
5055 param_type() : param_type(1) { }
5056
5057 explicit
5058 param_type(_IntType __k, double __p = 0.5)
5059 : _M_k(__k), _M_p(__p)
5060 {
5061 __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
5062 }
5063
5064 _IntType
5065 k() const
5066 { return _M_k; }
5067
5068 double
5069 p() const
5070 { return _M_p; }
5071
5072 friend bool
5073 operator==(const param_type& __p1, const param_type& __p2)
5074 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
5075
5076#if __cpp_impl_three_way_comparison < 201907L
5077 friend bool
5078 operator!=(const param_type& __p1, const param_type& __p2)
5079 { return !(__p1 == __p2); }
5080#endif
5081
5082 private:
5083 _IntType _M_k;
5084 double _M_p;
5085 };
5086
5087 negative_binomial_distribution() : negative_binomial_distribution(1) { }
5088
5089 explicit
5090 negative_binomial_distribution(_IntType __k, double __p = 0.5)
5091 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
5092 { }
5093
5094 explicit
5095 negative_binomial_distribution(const param_type& __p)
5096 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
5097 { }
5098
5099 /**
5100 * @brief Resets the distribution state.
5101 */
5102 void
5104 { _M_gd.reset(); }
5105
5106 /**
5107 * @brief Return the @f$k@f$ parameter of the distribution.
5108 */
5109 _IntType
5110 k() const
5111 { return _M_param.k(); }
5112
5113 /**
5114 * @brief Return the @f$p@f$ parameter of the distribution.
5115 */
5116 double
5117 p() const
5118 { return _M_param.p(); }
5119
5120 /**
5121 * @brief Returns the parameter set of the distribution.
5122 */
5123 param_type
5124 param() const
5125 { return _M_param; }
5126
5127 /**
5128 * @brief Sets the parameter set of the distribution.
5129 * @param __param The new parameter set of the distribution.
5130 */
5131 void
5132 param(const param_type& __param)
5133 {
5134 _M_param = __param;
5135
5136 using param_type
5138 _M_gd.param(param_type(__param.k(), (1.0 - __param.p()) / __param.p()));
5139 }
5140
5141 /**
5142 * @brief Returns the greatest lower bound value of the distribution.
5143 */
5144 result_type
5145 min() const
5146 { return result_type(0); }
5147
5148 /**
5149 * @brief Returns the least upper bound value of the distribution.
5150 */
5151 result_type
5152 max() const
5154
5155 /**
5156 * @brief Generating functions.
5157 */
5158 template<typename _UniformRandomNumberGenerator>
5159 result_type
5160 operator()(_UniformRandomNumberGenerator& __urng);
5161
5162 template<typename _UniformRandomNumberGenerator>
5164 operator()(_UniformRandomNumberGenerator& __urng,
5165 const param_type& __p);
5166
5167 template<typename _ForwardIterator,
5168 typename _UniformRandomNumberGenerator>
5169 void
5170 __generate(_ForwardIterator __f, _ForwardIterator __t,
5171 _UniformRandomNumberGenerator& __urng)
5172 { this->__generate_impl(__f, __t, __urng); }
5173
5174 template<typename _ForwardIterator,
5175 typename _UniformRandomNumberGenerator>
5176 void
5177 __generate(_ForwardIterator __f, _ForwardIterator __t,
5178 _UniformRandomNumberGenerator& __urng,
5179 const param_type& __p)
5180 { this->__generate_impl(__f, __t, __urng, __p); }
5181
5182 template<typename _UniformRandomNumberGenerator>
5183 void
5184 __generate(result_type* __f, result_type* __t,
5185 _UniformRandomNumberGenerator& __urng)
5186 { this->__generate_impl(__f, __t, __urng); }
5187
5188 template<typename _UniformRandomNumberGenerator>
5189 void
5190 __generate(result_type* __f, result_type* __t,
5191 _UniformRandomNumberGenerator& __urng,
5192 const param_type& __p)
5193 { this->__generate_impl(__f, __t, __urng, __p); }
5194
5195 /**
5196 * @brief Return true if two negative binomial distributions have
5197 * the same parameters and the sequences that would be
5198 * generated are equal.
5199 */
5200 friend bool
5201 operator==(const negative_binomial_distribution& __d1,
5202 const negative_binomial_distribution& __d2)
5203 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
5204
5205 /**
5206 * @brief Inserts a %negative_binomial_distribution random
5207 * number distribution @p __x into the output stream @p __os.
5208 *
5209 * @param __os An output stream.
5210 * @param __x A %negative_binomial_distribution random number
5211 * distribution.
5212 *
5213 * @returns The output stream with the state of @p __x inserted or in
5214 * an error state.
5215 */
5216 template<typename _IntType1, typename _CharT, typename _Traits>
5220
5221 /**
5222 * @brief Extracts a %negative_binomial_distribution random number
5223 * distribution @p __x from the input stream @p __is.
5224 *
5225 * @param __is An input stream.
5226 * @param __x A %negative_binomial_distribution random number
5227 * generator engine.
5228 *
5229 * @returns The input stream with @p __x extracted or in an error state.
5230 */
5231 template<typename _IntType1, typename _CharT, typename _Traits>
5235
5236 private:
5237 template<typename _ForwardIterator,
5238 typename _UniformRandomNumberGenerator>
5239 void
5240 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5241 _UniformRandomNumberGenerator& __urng);
5242 template<typename _ForwardIterator,
5243 typename _UniformRandomNumberGenerator>
5244 void
5245 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5246 _UniformRandomNumberGenerator& __urng,
5247 const param_type& __p);
5248
5249 param_type _M_param;
5250
5252 };
5253
5254#if __cpp_impl_three_way_comparison < 201907L
5255 /**
5256 * @brief Return true if two negative binomial distributions are different.
5257 */
5258 template<typename _IntType>
5259 inline bool
5260 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
5262 { return !(__d1 == __d2); }
5263#endif
5264
5265 /// @} group random_distributions_bernoulli
5266
5267 /**
5268 * @addtogroup random_distributions_poisson Poisson Distributions
5269 * @ingroup random_distributions
5270 * @{
5271 */
5272
5273 /**
5274 * @brief A discrete Poisson random number distribution.
5275 *
5276 * The formula for the Poisson probability density function is
5277 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
5278 * parameter of the distribution.
5279 *
5280 * @headerfile random
5281 * @since C++11
5282 */
5283 template<typename _IntType = int>
5284 class poisson_distribution
5285 {
5287 "result_type must be an integral type");
5288
5289 public:
5290 /** The type of the range of the distribution. */
5291 typedef _IntType result_type;
5292
5293 /** Parameter type. */
5294 struct param_type
5295 {
5296 typedef poisson_distribution<_IntType> distribution_type;
5297 friend class poisson_distribution<_IntType>;
5298
5299 param_type() : param_type(1.0) { }
5300
5301 explicit
5302 param_type(double __mean)
5303 : _M_mean(__mean)
5304 {
5305 __glibcxx_assert(_M_mean > 0.0);
5306 _M_initialize();
5307 }
5308
5309 double
5310 mean() const
5311 { return _M_mean; }
5312
5313 friend bool
5314 operator==(const param_type& __p1, const param_type& __p2)
5315 { return __p1._M_mean == __p2._M_mean; }
5316
5317#if __cpp_impl_three_way_comparison < 201907L
5318 friend bool
5319 operator!=(const param_type& __p1, const param_type& __p2)
5320 { return !(__p1 == __p2); }
5321#endif
5322
5323 private:
5324 // Hosts either log(mean) or the threshold of the simple method.
5325 void
5326 _M_initialize();
5327
5328 double _M_mean;
5329
5330 double _M_lm_thr;
5331#if _GLIBCXX_USE_C99_MATH_FUNCS
5332 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
5333#endif
5334 };
5335
5336 // constructors and member functions
5337
5338 poisson_distribution() : poisson_distribution(1.0) { }
5339
5340 explicit
5341 poisson_distribution(double __mean)
5342 : _M_param(__mean), _M_nd()
5343 { }
5344
5345 explicit
5346 poisson_distribution(const param_type& __p)
5347 : _M_param(__p), _M_nd()
5348 { }
5349
5350 /**
5351 * @brief Resets the distribution state.
5352 */
5353 void
5355 { _M_nd.reset(); }
5356
5357 /**
5358 * @brief Returns the distribution parameter @p mean.
5359 */
5360 double
5361 mean() const
5362 { return _M_param.mean(); }
5363
5364 /**
5365 * @brief Returns the parameter set of the distribution.
5366 */
5367 param_type
5368 param() const
5369 { return _M_param; }
5370
5371 /**
5372 * @brief Sets the parameter set of the distribution.
5373 * @param __param The new parameter set of the distribution.
5374 */
5375 void
5376 param(const param_type& __param)
5377 { _M_param = __param; }
5378
5379 /**
5380 * @brief Returns the greatest lower bound value of the distribution.
5381 */
5382 result_type
5383 min() const
5384 { return 0; }
5385
5386 /**
5387 * @brief Returns the least upper bound value of the distribution.
5388 */
5389 result_type
5390 max() const
5392
5393 /**
5394 * @brief Generating functions.
5395 */
5396 template<typename _UniformRandomNumberGenerator>
5397 result_type
5398 operator()(_UniformRandomNumberGenerator& __urng)
5399 { return this->operator()(__urng, _M_param); }
5400
5401 template<typename _UniformRandomNumberGenerator>
5402 result_type
5403 operator()(_UniformRandomNumberGenerator& __urng,
5404 const param_type& __p);
5405
5406 template<typename _ForwardIterator,
5407 typename _UniformRandomNumberGenerator>
5408 void
5409 __generate(_ForwardIterator __f, _ForwardIterator __t,
5410 _UniformRandomNumberGenerator& __urng)
5411 { this->__generate(__f, __t, __urng, _M_param); }
5412
5413 template<typename _ForwardIterator,
5414 typename _UniformRandomNumberGenerator>
5415 void
5416 __generate(_ForwardIterator __f, _ForwardIterator __t,
5417 _UniformRandomNumberGenerator& __urng,
5418 const param_type& __p)
5419 { this->__generate_impl(__f, __t, __urng, __p); }
5420
5421 template<typename _UniformRandomNumberGenerator>
5422 void
5423 __generate(result_type* __f, result_type* __t,
5424 _UniformRandomNumberGenerator& __urng,
5425 const param_type& __p)
5426 { this->__generate_impl(__f, __t, __urng, __p); }
5427
5428 /**
5429 * @brief Return true if two Poisson distributions have the same
5430 * parameters and the sequences that would be generated
5431 * are equal.
5432 */
5433 friend bool
5434 operator==(const poisson_distribution& __d1,
5435 const poisson_distribution& __d2)
5436#ifdef _GLIBCXX_USE_C99_MATH_FUNCS
5437 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
5438#else
5439 { return __d1._M_param == __d2._M_param; }
5440#endif
5441
5442 /**
5443 * @brief Inserts a %poisson_distribution random number distribution
5444 * @p __x into the output stream @p __os.
5445 *
5446 * @param __os An output stream.
5447 * @param __x A %poisson_distribution random number distribution.
5448 *
5449 * @returns The output stream with the state of @p __x inserted or in
5450 * an error state.
5451 */
5452 template<typename _IntType1, typename _CharT, typename _Traits>
5456
5457 /**
5458 * @brief Extracts a %poisson_distribution random number distribution
5459 * @p __x from the input stream @p __is.
5460 *
5461 * @param __is An input stream.
5462 * @param __x A %poisson_distribution random number generator engine.
5463 *
5464 * @returns The input stream with @p __x extracted or in an error
5465 * state.
5466 */
5467 template<typename _IntType1, typename _CharT, typename _Traits>
5471
5472 private:
5473 template<typename _ForwardIterator,
5474 typename _UniformRandomNumberGenerator>
5475 void
5476 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5477 _UniformRandomNumberGenerator& __urng,
5478 const param_type& __p);
5479
5480 param_type _M_param;
5481
5482 // NB: Unused when _GLIBCXX_USE_C99_MATH_FUNCS is undefined.
5484 };
5485
5486#if __cpp_impl_three_way_comparison < 201907L
5487 /**
5488 * @brief Return true if two Poisson distributions are different.
5489 */
5490 template<typename _IntType>
5491 inline bool
5492 operator!=(const std::poisson_distribution<_IntType>& __d1,
5494 { return !(__d1 == __d2); }
5495#endif
5496
5497 /**
5498 * @brief An exponential continuous distribution for random numbers.
5499 *
5500 * The formula for the exponential probability density function is
5501 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
5502 *
5503 * <table border=1 cellpadding=10 cellspacing=0>
5504 * <caption align=top>Distribution Statistics</caption>
5505 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
5506 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
5507 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
5508 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
5509 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
5510 * </table>
5511 *
5512 * @headerfile random
5513 * @since C++11
5514 */
5515 template<typename _RealType = double>
5517 {
5519 "result_type must be a floating point type");
5520
5521 public:
5522 /** The type of the range of the distribution. */
5523 typedef _RealType result_type;
5524
5525 /** Parameter type. */
5526 struct param_type
5527 {
5528 typedef exponential_distribution<_RealType> distribution_type;
5529
5530 param_type() : param_type(1.0) { }
5531
5532 explicit
5533 param_type(_RealType __lambda)
5534 : _M_lambda(__lambda)
5535 {
5536 __glibcxx_assert(_M_lambda > _RealType(0));
5537 }
5538
5539 _RealType
5540 lambda() const
5541 { return _M_lambda; }
5542
5543 friend bool
5544 operator==(const param_type& __p1, const param_type& __p2)
5545 { return __p1._M_lambda == __p2._M_lambda; }
5546
5547#if __cpp_impl_three_way_comparison < 201907L
5548 friend bool
5549 operator!=(const param_type& __p1, const param_type& __p2)
5550 { return !(__p1 == __p2); }
5551#endif
5552
5553 private:
5554 _RealType _M_lambda;
5555 };
5556
5557 public:
5558 /**
5559 * @brief Constructs an exponential distribution with inverse scale
5560 * parameter 1.0
5561 */
5563
5564 /**
5565 * @brief Constructs an exponential distribution with inverse scale
5566 * parameter @f$\lambda@f$.
5567 */
5568 explicit
5569 exponential_distribution(_RealType __lambda)
5570 : _M_param(__lambda)
5571 { }
5572
5573 explicit
5574 exponential_distribution(const param_type& __p)
5575 : _M_param(__p)
5576 { }
5577
5578 /**
5579 * @brief Resets the distribution state.
5580 *
5581 * Has no effect on exponential distributions.
5582 */
5583 void
5584 reset() { }
5585
5586 /**
5587 * @brief Returns the inverse scale parameter of the distribution.
5588 */
5589 _RealType
5590 lambda() const
5591 { return _M_param.lambda(); }
5592
5593 /**
5594 * @brief Returns the parameter set of the distribution.
5595 */
5596 param_type
5597 param() const
5598 { return _M_param; }
5599
5600 /**
5601 * @brief Sets the parameter set of the distribution.
5602 * @param __param The new parameter set of the distribution.
5603 */
5604 void
5605 param(const param_type& __param)
5606 { _M_param = __param; }
5607
5608 /**
5609 * @brief Returns the greatest lower bound value of the distribution.
5610 */
5611 result_type
5612 min() const
5613 { return result_type(0); }
5614
5615 /**
5616 * @brief Returns the least upper bound value of the distribution.
5617 */
5618 result_type
5619 max() const
5621
5622 /**
5623 * @brief Generating functions.
5624 */
5625 template<typename _UniformRandomNumberGenerator>
5626 result_type
5627 operator()(_UniformRandomNumberGenerator& __urng)
5628 { return this->operator()(__urng, _M_param); }
5629
5630 template<typename _UniformRandomNumberGenerator>
5631 result_type
5632 operator()(_UniformRandomNumberGenerator& __urng,
5633 const param_type& __p)
5634 {
5635 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
5636 __aurng(__urng);
5637 return -std::log(result_type(1) - __aurng()) / __p.lambda();
5638 }
5639
5640 template<typename _ForwardIterator,
5641 typename _UniformRandomNumberGenerator>
5642 void
5643 __generate(_ForwardIterator __f, _ForwardIterator __t,
5644 _UniformRandomNumberGenerator& __urng)
5645 { this->__generate(__f, __t, __urng, _M_param); }
5646
5647 template<typename _ForwardIterator,
5648 typename _UniformRandomNumberGenerator>
5649 void
5650 __generate(_ForwardIterator __f, _ForwardIterator __t,
5651 _UniformRandomNumberGenerator& __urng,
5652 const param_type& __p)
5653 { this->__generate_impl(__f, __t, __urng, __p); }
5654
5655 template<typename _UniformRandomNumberGenerator>
5656 void
5657 __generate(result_type* __f, result_type* __t,
5658 _UniformRandomNumberGenerator& __urng,
5659 const param_type& __p)
5660 { this->__generate_impl(__f, __t, __urng, __p); }
5661
5662 /**
5663 * @brief Return true if two exponential distributions have the same
5664 * parameters.
5665 */
5666 friend bool
5668 const exponential_distribution& __d2)
5669 { return __d1._M_param == __d2._M_param; }
5670
5671 private:
5672 template<typename _ForwardIterator,
5673 typename _UniformRandomNumberGenerator>
5674 void
5675 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5676 _UniformRandomNumberGenerator& __urng,
5677 const param_type& __p);
5678
5679 param_type _M_param;
5680 };
5681
5682#if __cpp_impl_three_way_comparison < 201907L
5683 /**
5684 * @brief Return true if two exponential distributions have different
5685 * parameters.
5686 */
5687 template<typename _RealType>
5688 inline bool
5689 operator!=(const std::exponential_distribution<_RealType>& __d1,
5691 { return !(__d1 == __d2); }
5692#endif
5693
5694 /**
5695 * @brief Inserts a %exponential_distribution random number distribution
5696 * @p __x into the output stream @p __os.
5697 *
5698 * @param __os An output stream.
5699 * @param __x A %exponential_distribution random number distribution.
5700 *
5701 * @returns The output stream with the state of @p __x inserted or in
5702 * an error state.
5703 */
5704 template<typename _RealType, typename _CharT, typename _Traits>
5705 std::basic_ostream<_CharT, _Traits>&
5706 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5707 const std::exponential_distribution<_RealType>& __x);
5708
5709 /**
5710 * @brief Extracts a %exponential_distribution random number distribution
5711 * @p __x from the input stream @p __is.
5712 *
5713 * @param __is An input stream.
5714 * @param __x A %exponential_distribution random number
5715 * generator engine.
5716 *
5717 * @returns The input stream with @p __x extracted or in an error state.
5718 */
5719 template<typename _RealType, typename _CharT, typename _Traits>
5720 std::basic_istream<_CharT, _Traits>&
5721 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5722 std::exponential_distribution<_RealType>& __x);
5723
5724
5725 /**
5726 * @brief A weibull_distribution random number distribution.
5727 *
5728 * The formula for the normal probability density function is:
5729 * @f[
5730 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
5731 * \exp{(-(\frac{x}{\beta})^\alpha)}
5732 * @f]
5733 *
5734 * @headerfile random
5735 * @since C++11
5736 */
5737 template<typename _RealType = double>
5738 class weibull_distribution
5739 {
5741 "result_type must be a floating point type");
5742
5743 public:
5744 /** The type of the range of the distribution. */
5745 typedef _RealType result_type;
5746
5747 /** Parameter type. */
5748 struct param_type
5749 {
5750 typedef weibull_distribution<_RealType> distribution_type;
5751
5752 param_type() : param_type(1.0) { }
5753
5754 explicit
5755 param_type(_RealType __a, _RealType __b = _RealType(1.0))
5756 : _M_a(__a), _M_b(__b)
5757 { }
5758
5759 _RealType
5760 a() const
5761 { return _M_a; }
5762
5763 _RealType
5764 b() const
5765 { return _M_b; }
5766
5767 friend bool
5768 operator==(const param_type& __p1, const param_type& __p2)
5769 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5770
5771#if __cpp_impl_three_way_comparison < 201907L
5772 friend bool
5773 operator!=(const param_type& __p1, const param_type& __p2)
5774 { return !(__p1 == __p2); }
5775#endif
5776
5777 private:
5778 _RealType _M_a;
5779 _RealType _M_b;
5780 };
5781
5782 weibull_distribution() : weibull_distribution(1.0) { }
5783
5784 explicit
5785 weibull_distribution(_RealType __a, _RealType __b = _RealType(1))
5786 : _M_param(__a, __b)
5787 { }
5788
5789 explicit
5790 weibull_distribution(const param_type& __p)
5791 : _M_param(__p)
5792 { }
5793
5794 /**
5795 * @brief Resets the distribution state.
5796 */
5797 void
5799 { }
5800
5801 /**
5802 * @brief Return the @f$a@f$ parameter of the distribution.
5803 */
5804 _RealType
5805 a() const
5806 { return _M_param.a(); }
5807
5808 /**
5809 * @brief Return the @f$b@f$ parameter of the distribution.
5810 */
5811 _RealType
5812 b() const
5813 { return _M_param.b(); }
5814
5815 /**
5816 * @brief Returns the parameter set of the distribution.
5817 */
5818 param_type
5819 param() const
5820 { return _M_param; }
5821
5822 /**
5823 * @brief Sets the parameter set of the distribution.
5824 * @param __param The new parameter set of the distribution.
5825 */
5826 void
5827 param(const param_type& __param)
5828 { _M_param = __param; }
5829
5830 /**
5831 * @brief Returns the greatest lower bound value of the distribution.
5832 */
5833 result_type
5834 min() const
5835 { return result_type(0); }
5836
5837 /**
5838 * @brief Returns the least upper bound value of the distribution.
5839 */
5840 result_type
5841 max() const
5843
5844 /**
5845 * @brief Generating functions.
5846 */
5847 template<typename _UniformRandomNumberGenerator>
5848 result_type
5849 operator()(_UniformRandomNumberGenerator& __urng)
5850 { return this->operator()(__urng, _M_param); }
5851
5852 template<typename _UniformRandomNumberGenerator>
5853 result_type
5854 operator()(_UniformRandomNumberGenerator& __urng,
5855 const param_type& __p);
5856
5857 template<typename _ForwardIterator,
5858 typename _UniformRandomNumberGenerator>
5859 void
5860 __generate(_ForwardIterator __f, _ForwardIterator __t,
5861 _UniformRandomNumberGenerator& __urng)
5862 { this->__generate(__f, __t, __urng, _M_param); }
5863
5864 template<typename _ForwardIterator,
5865 typename _UniformRandomNumberGenerator>
5866 void
5867 __generate(_ForwardIterator __f, _ForwardIterator __t,
5868 _UniformRandomNumberGenerator& __urng,
5869 const param_type& __p)
5870 { this->__generate_impl(__f, __t, __urng, __p); }
5871
5872 template<typename _UniformRandomNumberGenerator>
5873 void
5874 __generate(result_type* __f, result_type* __t,
5875 _UniformRandomNumberGenerator& __urng,
5876 const param_type& __p)
5877 { this->__generate_impl(__f, __t, __urng, __p); }
5878
5879 /**
5880 * @brief Return true if two Weibull distributions have the same
5881 * parameters.
5882 */
5883 friend bool
5884 operator==(const weibull_distribution& __d1,
5885 const weibull_distribution& __d2)
5886 { return __d1._M_param == __d2._M_param; }
5887
5888 private:
5889 template<typename _ForwardIterator,
5890 typename _UniformRandomNumberGenerator>
5891 void
5892 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5893 _UniformRandomNumberGenerator& __urng,
5894 const param_type& __p);
5895
5896 param_type _M_param;
5897 };
5898
5899#if __cpp_impl_three_way_comparison < 201907L
5900 /**
5901 * @brief Return true if two Weibull distributions have different
5902 * parameters.
5903 */
5904 template<typename _RealType>
5905 inline bool
5906 operator!=(const std::weibull_distribution<_RealType>& __d1,
5908 { return !(__d1 == __d2); }
5909#endif
5910
5911 /**
5912 * @brief Inserts a %weibull_distribution random number distribution
5913 * @p __x into the output stream @p __os.
5914 *
5915 * @param __os An output stream.
5916 * @param __x A %weibull_distribution random number distribution.
5917 *
5918 * @returns The output stream with the state of @p __x inserted or in
5919 * an error state.
5920 */
5921 template<typename _RealType, typename _CharT, typename _Traits>
5922 std::basic_ostream<_CharT, _Traits>&
5923 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5924 const std::weibull_distribution<_RealType>& __x);
5925
5926 /**
5927 * @brief Extracts a %weibull_distribution random number distribution
5928 * @p __x from the input stream @p __is.
5929 *
5930 * @param __is An input stream.
5931 * @param __x A %weibull_distribution random number
5932 * generator engine.
5933 *
5934 * @returns The input stream with @p __x extracted or in an error state.
5935 */
5936 template<typename _RealType, typename _CharT, typename _Traits>
5937 std::basic_istream<_CharT, _Traits>&
5938 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5939 std::weibull_distribution<_RealType>& __x);
5940
5941
5942 /**
5943 * @brief A extreme_value_distribution random number distribution.
5944 *
5945 * The formula for the normal probability mass function is
5946 * @f[
5947 * p(x|a,b) = \frac{1}{b}
5948 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5949 * @f]
5950 *
5951 * @headerfile random
5952 * @since C++11
5953 */
5954 template<typename _RealType = double>
5955 class extreme_value_distribution
5956 {
5958 "result_type must be a floating point type");
5959
5960 public:
5961 /** The type of the range of the distribution. */
5962 typedef _RealType result_type;
5963
5964 /** Parameter type. */
5965 struct param_type
5966 {
5967 typedef extreme_value_distribution<_RealType> distribution_type;
5968
5969 param_type() : param_type(0.0) { }
5970
5971 explicit
5972 param_type(_RealType __a, _RealType __b = _RealType(1.0))
5973 : _M_a(__a), _M_b(__b)
5974 { }
5975
5976 _RealType
5977 a() const
5978 { return _M_a; }
5979
5980 _RealType
5981 b() const
5982 { return _M_b; }
5983
5984 friend bool
5985 operator==(const param_type& __p1, const param_type& __p2)
5986 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5987
5988#if __cpp_impl_three_way_comparison < 201907L
5989 friend bool
5990 operator!=(const param_type& __p1, const param_type& __p2)
5991 { return !(__p1 == __p2); }
5992#endif
5993
5994 private:
5995 _RealType _M_a;
5996 _RealType _M_b;
5997 };
5998
5999 extreme_value_distribution() : extreme_value_distribution(0.0) { }
6000
6001 explicit
6002 extreme_value_distribution(_RealType __a, _RealType __b = _RealType(1))
6003 : _M_param(__a, __b)
6004 { }
6005
6006 explicit
6007 extreme_value_distribution(const param_type& __p)
6008 : _M_param(__p)
6009 { }
6010
6011 /**
6012 * @brief Resets the distribution state.
6013 */
6014 void
6016 { }
6017
6018 /**
6019 * @brief Return the @f$a@f$ parameter of the distribution.
6020 */
6021 _RealType
6022 a() const
6023 { return _M_param.a(); }
6024
6025 /**
6026 * @brief Return the @f$b@f$ parameter of the distribution.
6027 */
6028 _RealType
6029 b() const
6030 { return _M_param.b(); }
6031
6032 /**
6033 * @brief Returns the parameter set of the distribution.
6034 */
6035 param_type
6036 param() const
6037 { return _M_param; }
6038
6039 /**
6040 * @brief Sets the parameter set of the distribution.
6041 * @param __param The new parameter set of the distribution.
6042 */
6043 void
6044 param(const param_type& __param)
6045 { _M_param = __param; }
6046
6047 /**
6048 * @brief Returns the greatest lower bound value of the distribution.
6049 */
6050 result_type
6053
6054 /**
6055 * @brief Returns the least upper bound value of the distribution.
6056 */
6057 result_type
6058 max() const
6060
6061 /**
6062 * @brief Generating functions.
6063 */
6064 template<typename _UniformRandomNumberGenerator>
6065 result_type
6066 operator()(_UniformRandomNumberGenerator& __urng)
6067 { return this->operator()(__urng, _M_param); }
6068
6069 template<typename _UniformRandomNumberGenerator>
6070 result_type
6071 operator()(_UniformRandomNumberGenerator& __urng,
6072 const param_type& __p);
6073
6074 template<typename _ForwardIterator,
6075 typename _UniformRandomNumberGenerator>
6076 void
6077 __generate(_ForwardIterator __f, _ForwardIterator __t,
6078 _UniformRandomNumberGenerator& __urng)
6079 { this->__generate(__f, __t, __urng, _M_param); }
6080
6081 template<typename _ForwardIterator,
6082 typename _UniformRandomNumberGenerator>
6083 void
6084 __generate(_ForwardIterator __f, _ForwardIterator __t,
6085 _UniformRandomNumberGenerator& __urng,
6086 const param_type& __p)
6087 { this->__generate_impl(__f, __t, __urng, __p); }
6088
6089 template<typename _UniformRandomNumberGenerator>
6090 void
6091 __generate(result_type* __f, result_type* __t,
6092 _UniformRandomNumberGenerator& __urng,
6093 const param_type& __p)
6094 { this->__generate_impl(__f, __t, __urng, __p); }
6095
6096 /**
6097 * @brief Return true if two extreme value distributions have the same
6098 * parameters.
6099 */
6100 friend bool
6101 operator==(const extreme_value_distribution& __d1,
6102 const extreme_value_distribution& __d2)
6103 { return __d1._M_param == __d2._M_param; }
6104
6105 private:
6106 template<typename _ForwardIterator,
6107 typename _UniformRandomNumberGenerator>
6108 void
6109 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6110 _UniformRandomNumberGenerator& __urng,
6111 const param_type& __p);
6112
6113 param_type _M_param;
6114 };
6115
6116#if __cpp_impl_three_way_comparison < 201907L
6117 /**
6118 * @brief Return true if two extreme value distributions have different
6119 * parameters.
6120 */
6121 template<typename _RealType>
6122 inline bool
6123 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
6125 { return !(__d1 == __d2); }
6126#endif
6127
6128 /**
6129 * @brief Inserts a %extreme_value_distribution random number distribution
6130 * @p __x into the output stream @p __os.
6131 *
6132 * @param __os An output stream.
6133 * @param __x A %extreme_value_distribution random number distribution.
6134 *
6135 * @returns The output stream with the state of @p __x inserted or in
6136 * an error state.
6137 */
6138 template<typename _RealType, typename _CharT, typename _Traits>
6139 std::basic_ostream<_CharT, _Traits>&
6140 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
6141 const std::extreme_value_distribution<_RealType>& __x);
6142
6143 /**
6144 * @brief Extracts a %extreme_value_distribution random number
6145 * distribution @p __x from the input stream @p __is.
6146 *
6147 * @param __is An input stream.
6148 * @param __x A %extreme_value_distribution random number
6149 * generator engine.
6150 *
6151 * @returns The input stream with @p __x extracted or in an error state.
6152 */
6153 template<typename _RealType, typename _CharT, typename _Traits>
6154 std::basic_istream<_CharT, _Traits>&
6155 operator>>(std::basic_istream<_CharT, _Traits>& __is,
6156 std::extreme_value_distribution<_RealType>& __x);
6157
6158 /// @} group random_distributions_poisson
6159
6160 /**
6161 * @addtogroup random_distributions_sampling Sampling Distributions
6162 * @ingroup random_distributions
6163 * @{
6164 */
6165
6166 /**
6167 * @brief A discrete_distribution random number distribution.
6168 *
6169 * This distribution produces random numbers @f$ i, 0 \leq i < n @f$,
6170 * distributed according to the probability mass function
6171 * @f$ p(i | p_0, ..., p_{n-1}) = p_i @f$.
6172 *
6173 * @headerfile random
6174 * @since C++11
6175 */
6176 template<typename _IntType = int>
6177 class discrete_distribution
6178 {
6180 "result_type must be an integral type");
6181
6182 public:
6183 /** The type of the range of the distribution. */
6184 typedef _IntType result_type;
6185
6186 /** Parameter type. */
6187 struct param_type
6188 {
6189 typedef discrete_distribution<_IntType> distribution_type;
6190 friend class discrete_distribution<_IntType>;
6191
6192 param_type()
6193 : _M_prob(), _M_cp()
6194 { }
6195
6196 template<typename _InputIterator>
6197 param_type(_InputIterator __wbegin,
6198 _InputIterator __wend)
6199 : _M_prob(__wbegin, __wend), _M_cp()
6200 { _M_initialize(); }
6201
6202 param_type(initializer_list<double> __wil)
6203 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
6204 { _M_initialize(); }
6205
6206 template<typename _Func>
6207 param_type(size_t __nw, double __xmin, double __xmax,
6208 _Func __fw);
6209
6210 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6211 param_type(const param_type&) = default;
6212 param_type& operator=(const param_type&) = default;
6213
6215 probabilities() const
6216 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
6217
6218 friend bool
6219 operator==(const param_type& __p1, const param_type& __p2)
6220 { return __p1._M_prob == __p2._M_prob; }
6221
6222#if __cpp_impl_three_way_comparison < 201907L
6223 friend bool
6224 operator!=(const param_type& __p1, const param_type& __p2)
6225 { return !(__p1 == __p2); }
6226#endif
6227
6228 private:
6229 void
6230 _M_initialize();
6231
6232 std::vector<double> _M_prob;
6233 std::vector<double> _M_cp;
6234 };
6235
6236 discrete_distribution()
6237 : _M_param()
6238 { }
6239
6240 template<typename _InputIterator>
6241 discrete_distribution(_InputIterator __wbegin,
6242 _InputIterator __wend)
6243 : _M_param(__wbegin, __wend)
6244 { }
6245
6246 discrete_distribution(initializer_list<double> __wl)
6247 : _M_param(__wl)
6248 { }
6249
6250 template<typename _Func>
6251 discrete_distribution(size_t __nw, double __xmin, double __xmax,
6252 _Func __fw)
6253 : _M_param(__nw, __xmin, __xmax, __fw)
6254 { }
6255
6256 explicit
6257 discrete_distribution(const param_type& __p)
6258 : _M_param(__p)
6259 { }
6260
6261 /**
6262 * @brief Resets the distribution state.
6263 */
6264 void
6266 { }
6267
6268 /**
6269 * @brief Returns the probabilities of the distribution.
6270 */
6273 {
6274 return _M_param._M_prob.empty()
6275 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
6276 }
6277
6278 /**
6279 * @brief Returns the parameter set of the distribution.
6280 */
6281 param_type
6282 param() const
6283 { return _M_param; }
6284
6285 /**
6286 * @brief Sets the parameter set of the distribution.
6287 * @param __param The new parameter set of the distribution.
6288 */
6289 void
6290 param(const param_type& __param)
6291 { _M_param = __param; }
6292
6293 /**
6294 * @brief Returns the greatest lower bound value of the distribution.
6295 */
6296 result_type
6297 min() const
6298 { return result_type(0); }
6299
6300 /**
6301 * @brief Returns the least upper bound value of the distribution.
6302 */
6303 result_type
6304 max() const
6305 {
6306 return _M_param._M_prob.empty()
6307 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
6308 }
6309
6310 /**
6311 * @brief Generating functions.
6312 */
6313 template<typename _UniformRandomNumberGenerator>
6314 result_type
6315 operator()(_UniformRandomNumberGenerator& __urng)
6316 { return this->operator()(__urng, _M_param); }
6317
6318 template<typename _UniformRandomNumberGenerator>
6319 result_type
6320 operator()(_UniformRandomNumberGenerator& __urng,
6321 const param_type& __p);
6322
6323 template<typename _ForwardIterator,
6324 typename _UniformRandomNumberGenerator>
6325 void
6326 __generate(_ForwardIterator __f, _ForwardIterator __t,
6327 _UniformRandomNumberGenerator& __urng)
6328 { this->__generate(__f, __t, __urng, _M_param); }
6329
6330 template<typename _ForwardIterator,
6331 typename _UniformRandomNumberGenerator>
6332 void
6333 __generate(_ForwardIterator __f, _ForwardIterator __t,
6334 _UniformRandomNumberGenerator& __urng,
6335 const param_type& __p)
6336 { this->__generate_impl(__f, __t, __urng, __p); }
6337
6338 template<typename _UniformRandomNumberGenerator>
6339 void
6340 __generate(result_type* __f, result_type* __t,
6341 _UniformRandomNumberGenerator& __urng,
6342 const param_type& __p)
6343 { this->__generate_impl(__f, __t, __urng, __p); }
6344
6345 /**
6346 * @brief Return true if two discrete distributions have the same
6347 * parameters.
6348 */
6349 friend bool
6350 operator==(const discrete_distribution& __d1,
6351 const discrete_distribution& __d2)
6352 { return __d1._M_param == __d2._M_param; }
6353
6354 /**
6355 * @brief Inserts a %discrete_distribution random number distribution
6356 * @p __x into the output stream @p __os.
6357 *
6358 * @param __os An output stream.
6359 * @param __x A %discrete_distribution random number distribution.
6360 *
6361 * @returns The output stream with the state of @p __x inserted or in
6362 * an error state.
6363 */
6364 template<typename _IntType1, typename _CharT, typename _Traits>
6368
6369 /**
6370 * @brief Extracts a %discrete_distribution random number distribution
6371 * @p __x from the input stream @p __is.
6372 *
6373 * @param __is An input stream.
6374 * @param __x A %discrete_distribution random number
6375 * generator engine.
6376 *
6377 * @returns The input stream with @p __x extracted or in an error
6378 * state.
6379 */
6380 template<typename _IntType1, typename _CharT, typename _Traits>
6384
6385 private:
6386 template<typename _ForwardIterator,
6387 typename _UniformRandomNumberGenerator>
6388 void
6389 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6390 _UniformRandomNumberGenerator& __urng,
6391 const param_type& __p);
6392
6393 param_type _M_param;
6394 };
6395
6396#if __cpp_impl_three_way_comparison < 201907L
6397 /**
6398 * @brief Return true if two discrete distributions have different
6399 * parameters.
6400 */
6401 template<typename _IntType>
6402 inline bool
6403 operator!=(const std::discrete_distribution<_IntType>& __d1,
6405 { return !(__d1 == __d2); }
6406#endif
6407
6408 /**
6409 * @brief A piecewise_constant_distribution random number distribution.
6410 *
6411 * This distribution produces random numbers @f$ x, b_0 \leq x < b_n @f$,
6412 * uniformly distributed over each subinterval @f$ [b_i, b_{i+1}) @f$
6413 * according to the probability mass function
6414 * @f[
6415 * p(x | b_0, ..., b_n, \rho_0, ..., \rho_{n-1})
6416 * = \rho_i \cdot \frac{b_{i+1} - x}{b_{i+1} - b_i}
6417 * + \rho_{i+1} \cdot \frac{ x - b_i}{b_{i+1} - b_i}
6418 * @f]
6419 * for @f$ b_i \leq x < b_{i+1} @f$.
6420 *
6421 * @headerfile random
6422 * @since C++11
6423 */
6424 template<typename _RealType = double>
6425 class piecewise_constant_distribution
6426 {
6428 "result_type must be a floating point type");
6429
6430 public:
6431 /** The type of the range of the distribution. */
6432 typedef _RealType result_type;
6433
6434 /** Parameter type. */
6435 struct param_type
6436 {
6437 typedef piecewise_constant_distribution<_RealType> distribution_type;
6438 friend class piecewise_constant_distribution<_RealType>;
6439
6440 param_type()
6441 : _M_int(), _M_den(), _M_cp()
6442 { }
6443
6444 template<typename _InputIteratorB, typename _InputIteratorW>
6445 param_type(_InputIteratorB __bfirst,
6446 _InputIteratorB __bend,
6447 _InputIteratorW __wbegin);
6448
6449 template<typename _Func>
6450 param_type(initializer_list<_RealType> __bi, _Func __fw);
6451
6452 template<typename _Func>
6453 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
6454 _Func __fw);
6455
6456 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6457 param_type(const param_type&) = default;
6458 param_type& operator=(const param_type&) = default;
6459
6461 intervals() const
6462 {
6463 if (_M_int.empty())
6464 {
6465 std::vector<_RealType> __tmp(2);
6466 __tmp[1] = _RealType(1);
6467 return __tmp;
6468 }
6469 else
6470 return _M_int;
6471 }
6472
6474 densities() const
6475 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
6476
6477 friend bool
6478 operator==(const param_type& __p1, const param_type& __p2)
6479 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
6480
6481#if __cpp_impl_three_way_comparison < 201907L
6482 friend bool
6483 operator!=(const param_type& __p1, const param_type& __p2)
6484 { return !(__p1 == __p2); }
6485#endif
6486
6487 private:
6488 void
6489 _M_initialize();
6490
6492 std::vector<double> _M_den;
6493 std::vector<double> _M_cp;
6494 };
6495
6496 piecewise_constant_distribution()
6497 : _M_param()
6498 { }
6499
6500 template<typename _InputIteratorB, typename _InputIteratorW>
6501 piecewise_constant_distribution(_InputIteratorB __bfirst,
6502 _InputIteratorB __bend,
6503 _InputIteratorW __wbegin)
6504 : _M_param(__bfirst, __bend, __wbegin)
6505 { }
6506
6507 template<typename _Func>
6508 piecewise_constant_distribution(initializer_list<_RealType> __bl,
6509 _Func __fw)
6510 : _M_param(__bl, __fw)
6511 { }
6512
6513 template<typename _Func>
6514 piecewise_constant_distribution(size_t __nw,
6515 _RealType __xmin, _RealType __xmax,
6516 _Func __fw)
6517 : _M_param(__nw, __xmin, __xmax, __fw)
6518 { }
6519
6520 explicit
6521 piecewise_constant_distribution(const param_type& __p)
6522 : _M_param(__p)
6523 { }
6524
6525 /**
6526 * @brief Resets the distribution state.
6527 */
6528 void
6530 { }
6531
6532 /**
6533 * @brief Returns a vector of the intervals.
6534 */
6537 {
6538 if (_M_param._M_int.empty())
6539 {
6540 std::vector<_RealType> __tmp(2);
6541 __tmp[1] = _RealType(1);
6542 return __tmp;
6543 }
6544 else
6545 return _M_param._M_int;
6546 }
6547
6548 /**
6549 * @brief Returns a vector of the probability densities.
6550 */
6553 {
6554 return _M_param._M_den.empty()
6555 ? std::vector<double>(1, 1.0) : _M_param._M_den;
6556 }
6557
6558 /**
6559 * @brief Returns the parameter set of the distribution.
6560 */
6561 param_type
6562 param() const
6563 { return _M_param; }
6564
6565 /**
6566 * @brief Sets the parameter set of the distribution.
6567 * @param __param The new parameter set of the distribution.
6568 */
6569 void
6570 param(const param_type& __param)
6571 { _M_param = __param; }
6572
6573 /**
6574 * @brief Returns the greatest lower bound value of the distribution.
6575 */
6576 result_type
6577 min() const
6578 {
6579 return _M_param._M_int.empty()
6580 ? result_type(0) : _M_param._M_int.front();
6581 }
6582
6583 /**
6584 * @brief Returns the least upper bound value of the distribution.
6585 */
6586 result_type
6587 max() const
6588 {
6589 return _M_param._M_int.empty()
6590 ? result_type(1) : _M_param._M_int.back();
6591 }
6592
6593 /**
6594 * @brief Generating functions.
6595 */
6596 template<typename _UniformRandomNumberGenerator>
6597 result_type
6598 operator()(_UniformRandomNumberGenerator& __urng)
6599 { return this->operator()(__urng, _M_param); }
6600
6601 template<typename _UniformRandomNumberGenerator>
6602 result_type
6603 operator()(_UniformRandomNumberGenerator& __urng,
6604 const param_type& __p);
6605
6606 template<typename _ForwardIterator,
6607 typename _UniformRandomNumberGenerator>
6608 void
6609 __generate(_ForwardIterator __f, _ForwardIterator __t,
6610 _UniformRandomNumberGenerator& __urng)
6611 { this->__generate(__f, __t, __urng, _M_param); }
6612
6613 template<typename _ForwardIterator,
6614 typename _UniformRandomNumberGenerator>
6615 void
6616 __generate(_ForwardIterator __f, _ForwardIterator __t,
6617 _UniformRandomNumberGenerator& __urng,
6618 const param_type& __p)
6619 { this->__generate_impl(__f, __t, __urng, __p); }
6620
6621 template<typename _UniformRandomNumberGenerator>
6622 void
6623 __generate(result_type* __f, result_type* __t,
6624 _UniformRandomNumberGenerator& __urng,
6625 const param_type& __p)
6626 { this->__generate_impl(__f, __t, __urng, __p); }
6627
6628 /**
6629 * @brief Return true if two piecewise constant distributions have the
6630 * same parameters.
6631 */
6632 friend bool
6633 operator==(const piecewise_constant_distribution& __d1,
6634 const piecewise_constant_distribution& __d2)
6635 { return __d1._M_param == __d2._M_param; }
6636
6637 /**
6638 * @brief Inserts a %piecewise_constant_distribution random
6639 * number distribution @p __x into the output stream @p __os.
6640 *
6641 * @param __os An output stream.
6642 * @param __x A %piecewise_constant_distribution random number
6643 * distribution.
6644 *
6645 * @returns The output stream with the state of @p __x inserted or in
6646 * an error state.
6647 */
6648 template<typename _RealType1, typename _CharT, typename _Traits>
6652
6653 /**
6654 * @brief Extracts a %piecewise_constant_distribution random
6655 * number distribution @p __x from the input stream @p __is.
6656 *
6657 * @param __is An input stream.
6658 * @param __x A %piecewise_constant_distribution random number
6659 * generator engine.
6660 *
6661 * @returns The input stream with @p __x extracted or in an error
6662 * state.
6663 */
6664 template<typename _RealType1, typename _CharT, typename _Traits>
6668
6669 private:
6670 template<typename _ForwardIterator,
6671 typename _UniformRandomNumberGenerator>
6672 void
6673 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6674 _UniformRandomNumberGenerator& __urng,
6675 const param_type& __p);
6676
6677 param_type _M_param;
6678 };
6679
6680#if __cpp_impl_three_way_comparison < 201907L
6681 /**
6682 * @brief Return true if two piecewise constant distributions have
6683 * different parameters.
6684 */
6685 template<typename _RealType>
6686 inline bool
6689 { return !(__d1 == __d2); }
6690#endif
6691
6692 /**
6693 * @brief A piecewise_linear_distribution random number distribution.
6694 *
6695 * This distribution produces random numbers @f$ x, b_0 \leq x < b_n @f$,
6696 * distributed over each subinterval @f$ [b_i, b_{i+1}) @f$
6697 * according to the probability mass function
6698 * @f$ p(x | b_0, ..., b_n, \rho_0, ..., \rho_n) = \rho_i @f$,
6699 * for @f$ b_i \leq x < b_{i+1} @f$.
6700 *
6701 * @headerfile random
6702 * @since C++11
6703 */
6704 template<typename _RealType = double>
6705 class piecewise_linear_distribution
6706 {
6708 "result_type must be a floating point type");
6709
6710 public:
6711 /** The type of the range of the distribution. */
6712 typedef _RealType result_type;
6713
6714 /** Parameter type. */
6715 struct param_type
6716 {
6717 typedef piecewise_linear_distribution<_RealType> distribution_type;
6718 friend class piecewise_linear_distribution<_RealType>;
6719
6720 param_type()
6721 : _M_int(), _M_den(), _M_cp(), _M_m()
6722 { }
6723
6724 template<typename _InputIteratorB, typename _InputIteratorW>
6725 param_type(_InputIteratorB __bfirst,
6726 _InputIteratorB __bend,
6727 _InputIteratorW __wbegin);
6728
6729 template<typename _Func>
6730 param_type(initializer_list<_RealType> __bl, _Func __fw);
6731
6732 template<typename _Func>
6733 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
6734 _Func __fw);
6735
6736 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6737 param_type(const param_type&) = default;
6738 param_type& operator=(const param_type&) = default;
6739
6741 intervals() const
6742 {
6743 if (_M_int.empty())
6744 {
6745 std::vector<_RealType> __tmp(2);
6746 __tmp[1] = _RealType(1);
6747 return __tmp;
6748 }
6749 else
6750 return _M_int;
6751 }
6752
6754 densities() const
6755 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
6756
6757 friend bool
6758 operator==(const param_type& __p1, const param_type& __p2)
6759 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
6760
6761#if __cpp_impl_three_way_comparison < 201907L
6762 friend bool
6763 operator!=(const param_type& __p1, const param_type& __p2)
6764 { return !(__p1 == __p2); }
6765#endif
6766
6767 private:
6768 void
6769 _M_initialize();
6770
6772 std::vector<double> _M_den;
6773 std::vector<double> _M_cp;
6775 };
6776
6777 piecewise_linear_distribution()
6778 : _M_param()
6779 { }
6780
6781 template<typename _InputIteratorB, typename _InputIteratorW>
6782 piecewise_linear_distribution(_InputIteratorB __bfirst,
6783 _InputIteratorB __bend,
6784 _InputIteratorW __wbegin)
6785 : _M_param(__bfirst, __bend, __wbegin)
6786 { }
6787
6788 template<typename _Func>
6789 piecewise_linear_distribution(initializer_list<_RealType> __bl,
6790 _Func __fw)
6791 : _M_param(__bl, __fw)
6792 { }
6793
6794 template<typename _Func>
6795 piecewise_linear_distribution(size_t __nw,
6796 _RealType __xmin, _RealType __xmax,
6797 _Func __fw)
6798 : _M_param(__nw, __xmin, __xmax, __fw)
6799 { }
6800
6801 explicit
6802 piecewise_linear_distribution(const param_type& __p)
6803 : _M_param(__p)
6804 { }
6805
6806 /**
6807 * Resets the distribution state.
6808 */
6809 void
6811 { }
6812
6813 /**
6814 * @brief Return the intervals of the distribution.
6815 */
6818 {
6819 if (_M_param._M_int.empty())
6820 {
6821 std::vector<_RealType> __tmp(2);
6822 __tmp[1] = _RealType(1);
6823 return __tmp;
6824 }
6825 else
6826 return _M_param._M_int;
6827 }
6828
6829 /**
6830 * @brief Return a vector of the probability densities of the
6831 * distribution.
6832 */
6835 {
6836 return _M_param._M_den.empty()
6837 ? std::vector<double>(2, 1.0) : _M_param._M_den;
6838 }
6839
6840 /**
6841 * @brief Returns the parameter set of the distribution.
6842 */
6843 param_type
6844 param() const
6845 { return _M_param; }
6846
6847 /**
6848 * @brief Sets the parameter set of the distribution.
6849 * @param __param The new parameter set of the distribution.
6850 */
6851 void
6852 param(const param_type& __param)
6853 { _M_param = __param; }
6854
6855 /**
6856 * @brief Returns the greatest lower bound value of the distribution.
6857 */
6858 result_type
6859 min() const
6860 {
6861 return _M_param._M_int.empty()
6862 ? result_type(0) : _M_param._M_int.front();
6863 }
6864
6865 /**
6866 * @brief Returns the least upper bound value of the distribution.
6867 */
6868 result_type
6869 max() const
6870 {
6871 return _M_param._M_int.empty()
6872 ? result_type(1) : _M_param._M_int.back();
6873 }
6874
6875 /**
6876 * @brief Generating functions.
6877 */
6878 template<typename _UniformRandomNumberGenerator>
6879 result_type
6880 operator()(_UniformRandomNumberGenerator& __urng)
6881 { return this->operator()(__urng, _M_param); }
6882
6883 template<typename _UniformRandomNumberGenerator>
6884 result_type
6885 operator()(_UniformRandomNumberGenerator& __urng,
6886 const param_type& __p);
6887
6888 template<typename _ForwardIterator,
6889 typename _UniformRandomNumberGenerator>
6890 void
6891 __generate(_ForwardIterator __f, _ForwardIterator __t,
6892 _UniformRandomNumberGenerator& __urng)
6893 { this->__generate(__f, __t, __urng, _M_param); }
6894
6895 template<typename _ForwardIterator,
6896 typename _UniformRandomNumberGenerator>
6897 void
6898 __generate(_ForwardIterator __f, _ForwardIterator __t,
6899 _UniformRandomNumberGenerator& __urng,
6900 const param_type& __p)
6901 { this->__generate_impl(__f, __t, __urng, __p); }
6902
6903 template<typename _UniformRandomNumberGenerator>
6904 void
6905 __generate(result_type* __f, result_type* __t,
6906 _UniformRandomNumberGenerator& __urng,
6907 const param_type& __p)
6908 { this->__generate_impl(__f, __t, __urng, __p); }
6909
6910 /**
6911 * @brief Return true if two piecewise linear distributions have the
6912 * same parameters.
6913 */
6914 friend bool
6915 operator==(const piecewise_linear_distribution& __d1,
6916 const piecewise_linear_distribution& __d2)
6917 { return __d1._M_param == __d2._M_param; }
6918
6919 /**
6920 * @brief Inserts a %piecewise_linear_distribution random number
6921 * distribution @p __x into the output stream @p __os.
6922 *
6923 * @param __os An output stream.
6924 * @param __x A %piecewise_linear_distribution random number
6925 * distribution.
6926 *
6927 * @returns The output stream with the state of @p __x inserted or in
6928 * an error state.
6929 */
6930 template<typename _RealType1, typename _CharT, typename _Traits>
6934
6935 /**
6936 * @brief Extracts a %piecewise_linear_distribution random number
6937 * distribution @p __x from the input stream @p __is.
6938 *
6939 * @param __is An input stream.
6940 * @param __x A %piecewise_linear_distribution random number
6941 * generator engine.
6942 *
6943 * @returns The input stream with @p __x extracted or in an error
6944 * state.
6945 */
6946 template<typename _RealType1, typename _CharT, typename _Traits>
6950
6951 private:
6952 template<typename _ForwardIterator,
6953 typename _UniformRandomNumberGenerator>
6954 void
6955 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6956 _UniformRandomNumberGenerator& __urng,
6957 const param_type& __p);
6958
6959 param_type _M_param;
6960 };
6961
6962#if __cpp_impl_three_way_comparison < 201907L
6963 /**
6964 * @brief Return true if two piecewise linear distributions have
6965 * different parameters.
6966 */
6967 template<typename _RealType>
6968 inline bool
6969 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
6971 { return !(__d1 == __d2); }
6972#endif
6973
6974 /// @} group random_distributions_sampling
6975
6976 /// @} *group random_distributions
6977
6978 /**
6979 * @addtogroup random_utilities Random Number Utilities
6980 * @ingroup random
6981 * @{
6982 */
6983
6984 /**
6985 * @brief The seed_seq class generates sequences of seeds for random
6986 * number generators.
6987 *
6988 * @headerfile random
6989 * @since C++11
6990 */
6992 {
6993 public:
6994 /** The type of the seed vales. */
6995 typedef uint_least32_t result_type;
6996
6997 /** Default constructor. */
6998 seed_seq() noexcept
6999 : _M_v()
7000 { }
7001
7002 template<typename _IntType, typename = _Require<is_integral<_IntType>>>
7004
7005 template<typename _InputIterator>
7006 seed_seq(_InputIterator __begin, _InputIterator __end);
7007
7008 // generating functions
7009 template<typename _RandomAccessIterator>
7010 void
7011 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
7012
7013 // property functions
7014 size_t size() const noexcept
7015 { return _M_v.size(); }
7016
7017 template<typename _OutputIterator>
7018 void
7019 param(_OutputIterator __dest) const
7020 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
7021
7022 // no copy functions
7023 seed_seq(const seed_seq&) = delete;
7024 seed_seq& operator=(const seed_seq&) = delete;
7025
7026 private:
7027 std::vector<result_type> _M_v;
7028 };
7029
7030 /// @} group random_utilities
7031
7032 /// @} group random
7033
7034_GLIBCXX_END_NAMESPACE_VERSION
7035} // namespace std
7036
7037#endif
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:859
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:873
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
Definition chrono.h:783
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:826
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:866
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Definition complex:434
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
Definition complex:404
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
Definition complex:1158
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Definition complex:374
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
Definition complex:1131
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
Definition complex:464
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
Definition complex:1267
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2718
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
basic_string< char > string
A string of char.
Definition stringfwd.h:79
linear_congruential_engine< uint_fast32_t, 48271UL, 0UL, 2147483647UL > minstd_rand
Definition random.h:2295
philox_engine< uint_fast32_t, 32, 4, 10, 0xCD9E8D57, 0x9E3779B9, 0xD2511F53, 0xBB67AE85 > philox4x32
32-bit four-word Philox engine.
Definition random.h:2346
linear_congruential_engine< uint_fast32_t, 16807UL, 0UL, 2147483647UL > minstd_rand0
Definition random.h:2289
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
Definition random.h:2311
mersenne_twister_engine< uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, 17, 0x71d67fffeda60000ULL, 37, 0xfff7eee000000000ULL, 43, 6364136223846793005ULL > mt19937_64
Definition random.h:2323
philox_engine< uint_fast64_t, 64, 4, 10, 0xCA5A826395121157, 0x9E3779B97F4A7C15, 0xD2E7470EE14C6C93, 0xBB67AE8584CAA73B > philox4x64
64-bit four-word Philox engine.
Definition random.h:2353
ISO C++ entities toplevel namespace is std.
constexpr _Tp __lg(_Tp __n)
This is a helper function for the sort routines and for random.tcc.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1638
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1658
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1757
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1628
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1618
Implementation details not part of the namespace std interface.
initializer_list
A standard container for storing a fixed size sequence of elements.
Definition array:103
char_type widen(char __c) const
Widens characters.
Definition basic_ios.h:465
char_type fill() const
Retrieves the empty character.
Definition basic_ios.h:388
Template class basic_istream.
Definition istream:67
Template class basic_ostream.
Definition ostream.h:67
static constexpr int digits
Definition limits:218
static constexpr _Tp max() noexcept
Definition limits:328
static constexpr _Tp lowest() noexcept
Definition limits:334
static constexpr _Tp min() noexcept
Definition limits:324
is_integral
Definition type_traits:541
is_floating_point
Definition type_traits:601
is_unsigned
Definition type_traits:1066
static const fmtflags skipws
Skips leading white space before certain input operations.
Definition ios_base.h:423
_Ios_Fmtflags fmtflags
This is a bitmask type.
Definition ios_base.h:378
static const fmtflags dec
Converts integer input or generates integer output in decimal base.
Definition ios_base.h:384
fmtflags flags() const
Access to format flags.
Definition ios_base.h:694
static const fmtflags left
Adds fill characters on the right (final positions) of certain generated output. (I....
Definition ios_base.h:399
A model of a linear congruential random number generator.
Definition random.h:704
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &__lcr)
Sets the state of the engine by reading its textual representation from __is.
static constexpr result_type min()
Gets the smallest possible value in the output range.
Definition random.h:782
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition random.h:796
linear_congruential_engine()
Constructs a linear_congruential_engine random number generator engine with seed 1.
Definition random.h:730
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s.
friend bool operator==(const linear_congruential_engine &__lhs, const linear_congruential_engine &__rhs)
Compares two linear congruential random number generator objects of the same type for equality.
Definition random.h:824
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &__lcr)
Writes the textual representation of the state x(i) of x to __os.
result_type operator()()
Gets the next random number in the sequence.
Definition random.h:806
static constexpr result_type max()
Gets the largest possible value in the output range.
Definition random.h:789
void discard(unsigned long long __z)
Discard a sequence of random numbers.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > &__x)
Extracts the current state of a % mersenne_twister_engine random number generator engine __x from the...
static constexpr result_type max()
Gets the largest possible value in the output range.
Definition random.h:1015
friend bool operator==(const mersenne_twister_engine &__lhs, const mersenne_twister_engine &__rhs)
Compares two % mersenne_twister_engine random number generator objects of the same type for equality.
Definition random.h:1040
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::mersenne_twister_engine< _UIntType1, __w1, __n1, __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1 > &__x)
Inserts the current state of a % mersenne_twister_engine random number generator engine __x into the ...
static constexpr result_type min()
Gets the smallest possible value in the output range.
Definition random.h:1008
The Marsaglia-Zaman generator.
Definition random.h:1151
void seed(result_type __sd=0u)
Seeds the initial state of the random number generator.
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > &__x)
Inserts the current state of a % subtract_with_carry_engine random number generator engine __x into t...
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition random.h:1238
result_type operator()()
Gets the next random number in the sequence.
static constexpr result_type min()
Gets the inclusive minimum value of the range of random integers returned by this generator.
Definition random.h:1223
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::subtract_with_carry_engine< _UIntType1, __w1, __s1, __r1 > &__x)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
friend bool operator==(const subtract_with_carry_engine &__lhs, const subtract_with_carry_engine &__rhs)
Compares two % subtract_with_carry_engine random number generator objects of the same type for equali...
Definition random.h:1263
static constexpr result_type max()
Gets the inclusive maximum value of the range of random integers returned by this generator.
Definition random.h:1231
static constexpr result_type min()
Gets the minimum value in the generated random number range.
Definition random.h:1460
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::discard_block_engine< _RandomNumberEngine1, __p1, __r1 > &__x)
Inserts the current state of a discard_block_engine random number generator engine __x into the outpu...
const _RandomNumberEngine & base() const noexcept
Gets a const reference to the underlying generator engine object.
Definition random.h:1453
void seed()
Reseeds the discard_block_engine object with the default seed for the underlying base class generator...
Definition random.h:1418
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition random.h:1474
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::discard_block_engine< _RandomNumberEngine1, __p1, __r1 > &__x)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
static constexpr result_type max()
Gets the maximum value in the generated random number range.
Definition random.h:1467
discard_block_engine()
Constructs a default discard_block_engine engine.
Definition random.h:1369
friend bool operator==(const discard_block_engine &__lhs, const discard_block_engine &__rhs)
Compares two discard_block_engine random number generator objects of the same type for equality.
Definition random.h:1498
result_type operator()()
Gets the next value in the generated random number sequence.
_RandomNumberEngine::result_type result_type
Definition random.h:1354
static constexpr result_type min()
Gets the minimum value in the generated random number range.
Definition random.h:1675
result_type operator()()
Gets the next value in the generated random number sequence.
void seed()
Reseeds the independent_bits_engine object with the default seed for the underlying base class genera...
Definition random.h:1642
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition random.h:1689
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::independent_bits_engine< _RandomNumberEngine, __w, _UIntType > &__x)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
Definition random.h:1732
friend bool operator==(const independent_bits_engine &__lhs, const independent_bits_engine &__rhs)
Compares two independent_bits_engine random number generator objects of the same type for equality.
Definition random.h:1714
static constexpr result_type max()
Gets the maximum value in the generated random number range.
Definition random.h:1682
independent_bits_engine()
Constructs a default independent_bits_engine engine.
Definition random.h:1593
const _RandomNumberEngine & base() const noexcept
Gets a const reference to the underlying generator engine object.
Definition random.h:1668
Produces random numbers by reordering random numbers from some base engine.
Definition random.h:1801
static constexpr result_type min()
Definition random.h:1914
shuffle_order_engine()
Constructs a default shuffle_order_engine engine.
Definition random.h:1820
static constexpr result_type max()
Definition random.h:1921
const _RandomNumberEngine & base() const noexcept
Definition random.h:1907
void seed()
Reseeds the shuffle_order_engine object with the default seed for the underlying base class generator...
Definition random.h:1873
_RandomNumberEngine::result_type result_type
Definition random.h:1807
friend bool operator==(const shuffle_order_engine &__lhs, const shuffle_order_engine &__rhs)
Definition random.h:1952
void discard(unsigned long long __z)
Definition random.h:1928
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::shuffle_order_engine< _RandomNumberEngine1, __k1 > &__x)
Inserts the current state of a shuffle_order_engine random number generator engine __x into the outpu...
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::shuffle_order_engine< _RandomNumberEngine1, __k1 > &__x)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
A discrete pseudorandom number generator with weak cryptographic properties.
Definition random.h:2060
void set_counter(const array< result_type, __n > &__counter)
sets the internal counter "cleartext"
Definition random.h:2154
friend basic_istream< _CharT, _Traits > & operator>>(basic_istream< _CharT, _Traits > &__is, philox_engine &__x)
takes input to set the state of the philox_engine object
Definition random.h:2227
void discard(unsigned long long __z)
discards __z numbers
Definition random.h:2185
void seed(_Sseq &__q)
seeds philox_engine by seed sequence
static constexpr result_type max()
The maximum value that this engine can return.
Definition random.h:2103
philox_engine(_Sseq &__q)
seed sequence constructor for philox_engine
Definition random.h:2126
result_type operator()()
outputs a single w-bit number and handles state advancement
Definition random.h:2174
friend bool operator==(const philox_engine &, const philox_engine &)=default
compares two philox_engine objects
static constexpr result_type min()
The minimum value that this engine can return.
Definition random.h:2098
friend basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const philox_engine &__x)
outputs the state of the generator
Definition random.h:2200
unsigned int result_type
Definition random.h:2367
Uniform continuous distribution for random numbers.
Definition random.h:2493
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:2582
void reset()
Resets the distribution state.
Definition random.h:2568
uniform_real_distribution(_RealType __a, _RealType __b=_RealType(1))
Constructs a uniform_real_distribution object.
Definition random.h:2553
result_type min() const
Returns the inclusive lower bound of the distribution range.
Definition random.h:2597
friend bool operator==(const uniform_real_distribution &__d1, const uniform_real_distribution &__d2)
Return true if two uniform real distributions have the same parameters.
Definition random.h:2652
result_type max() const
Returns the inclusive upper bound of the distribution range.
Definition random.h:2604
uniform_real_distribution()
Constructs a uniform_real_distribution object.
Definition random.h:2544
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:2612
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:2590
A normal continuous distribution for random numbers.
Definition random.h:2730
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
_RealType stddev() const
Returns the standard deviation of the distribution.
Definition random.h:2812
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:2819
void reset()
Resets the distribution state.
Definition random.h:2798
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::normal_distribution< _RealType1 > &__x)
Extracts a normal_distribution random number distribution __x from the input stream __is.
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:2827
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:2834
_RealType mean() const
Returns the mean of the distribution.
Definition random.h:2805
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::normal_distribution< _RealType1 > &__x)
Inserts a normal_distribution random number distribution __x into the output stream __os.
normal_distribution(result_type __mean, result_type __stddev=result_type(1))
Definition random.h:2784
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:2841
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:2849
friend bool operator==(const std::normal_distribution< _RealType1 > &__d1, const std::normal_distribution< _RealType1 > &__d2)
Return true if two normal distributions have the same parameters and the sequences that would be gene...
A lognormal_distribution random number distribution.
Definition random.h:2957
friend bool operator==(const lognormal_distribution &__d1, const lognormal_distribution &__d2)
Return true if two lognormal distributions have the same parameters and the sequences that would be g...
Definition random.h:3101
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3034
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::lognormal_distribution< _RealType1 > &__x)
Extracts a lognormal_distribution random number distribution __x from the input stream __is.
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3049
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::lognormal_distribution< _RealType1 > &__x)
Inserts a lognormal_distribution random number distribution __x into the output stream __os.
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3042
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3056
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3064
A gamma continuous distribution for random numbers.
Definition random.h:3182
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
gamma_distribution(_RealType __alpha_val, _RealType __beta_val=_RealType(1))
Constructs a gamma distribution with parameters and .
Definition random.h:3246
void reset()
Resets the distribution state.
Definition random.h:3260
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::gamma_distribution< _RealType1 > &__x)
Inserts a gamma_distribution random number distribution __x into the output stream __os.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3311
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3296
_RealType alpha() const
Returns the of the distribution.
Definition random.h:3267
gamma_distribution()
Constructs a gamma distribution with parameters 1 and 1.
Definition random.h:3239
friend bool operator==(const gamma_distribution &__d1, const gamma_distribution &__d2)
Return true if two gamma distributions have the same parameters and the sequences that would be gener...
Definition random.h:3347
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3289
_RealType beta() const
Returns the of the distribution.
Definition random.h:3274
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::gamma_distribution< _RealType1 > &__x)
Extracts a gamma_distribution random number distribution __x from the input stream __is.
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3281
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3303
A chi_squared_distribution random number distribution.
Definition random.h:3424
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3528
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3492
friend bool operator==(const chi_squared_distribution &__d1, const chi_squared_distribution &__d2)
Return true if two Chi-squared distributions have the same parameters and the sequences that would be...
Definition random.h:3579
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3513
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::chi_squared_distribution< _RealType1 > &__x)
Inserts a chi_squared_distribution random number distribution __x into the output stream __os.
void reset()
Resets the distribution state.
Definition random.h:3478
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3500
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3520
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::chi_squared_distribution< _RealType1 > &__x)
Extracts a chi_squared_distribution random number distribution __x from the input stream __is.
A cauchy_distribution random number distribution.
Definition random.h:3655
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3747
friend bool operator==(const cauchy_distribution &__d1, const cauchy_distribution &__d2)
Return true if two Cauchy distributions have the same parameters.
Definition random.h:3797
void reset()
Resets the distribution state.
Definition random.h:3714
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3732
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3762
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3754
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3740
A fisher_f_distribution random number distribution.
Definition random.h:3870
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3959
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3980
void reset()
Resets the distribution state.
Definition random.h:3930
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3951
friend bool operator==(const fisher_f_distribution &__d1, const fisher_f_distribution &__d2)
Return true if two Fisher f distributions have the same parameters and the sequences that would be ge...
Definition random.h:4036
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3973
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3988
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::fisher_f_distribution< _RealType1 > &__x)
Inserts a fisher_f_distribution random number distribution __x into the output stream __os.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::fisher_f_distribution< _RealType1 > &__x)
Extracts a fisher_f_distribution random number distribution __x from the input stream __is.
A student_t_distribution random number distribution.
Definition random.h:4116
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4195
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4215
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4208
void reset()
Resets the distribution state.
Definition random.h:4170
friend bool operator==(const student_t_distribution &__d1, const student_t_distribution &__d2)
Return true if two Student t distributions have the same parameters and the sequences that would be g...
Definition random.h:4272
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4223
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::student_t_distribution< _RealType1 > &__x)
Inserts a student_t_distribution random number distribution __x into the output stream __os.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::student_t_distribution< _RealType1 > &__x)
Extracts a student_t_distribution random number distribution __x from the input stream __is.
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4187
A Bernoulli random number distribution.
Definition random.h:4355
void reset()
Resets the distribution state.
Definition random.h:4420
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4455
friend bool operator==(const bernoulli_distribution &__d1, const bernoulli_distribution &__d2)
Return true if two Bernoulli distributions have the same parameters.
Definition random.h:4505
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4433
bernoulli_distribution()
Constructs a Bernoulli distribution with likelihood 0.5.
Definition random.h:4396
bernoulli_distribution(double __p)
Constructs a Bernoulli distribution with likelihood p.
Definition random.h:4405
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4448
double p() const
Returns the p parameter of the distribution.
Definition random.h:4426
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4441
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4463
A discrete binomial random number distribution.
Definition random.h:4579
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4692
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4699
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4685
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4707
friend bool operator==(const binomial_distribution &__d1, const binomial_distribution &__d2)
Return true if two binomial distributions have the same parameters and the sequences that would be ge...
Definition random.h:4743
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4677
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::binomial_distribution< _IntType1 > &__x)
Extracts a binomial_distribution random number distribution __x from the input stream __is.
_IntType t() const
Returns the distribution t parameter.
Definition random.h:4663
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::binomial_distribution< _IntType1 > &__x)
Inserts a binomial_distribution random number distribution __x into the output stream __os.
void reset()
Resets the distribution state.
Definition random.h:4656
double p() const
Returns the distribution p parameter.
Definition random.h:4670
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
A discrete geometric random number distribution.
Definition random.h:4825
double p() const
Returns the distribution parameter p.
Definition random.h:4899
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4936
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4928
friend bool operator==(const geometric_distribution &__d1, const geometric_distribution &__d2)
Return true if two geometric distributions have the same parameters.
Definition random.h:4971
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4906
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4914
void reset()
Resets the distribution state.
Definition random.h:4893
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4921
A negative_binomial_distribution random number distribution.
Definition random.h:5042
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::negative_binomial_distribution< _IntType1 > &__x)
Inserts a negative_binomial_distribution random number distribution __x into the output stream __os.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::negative_binomial_distribution< _IntType1 > &__x)
Extracts a negative_binomial_distribution random number distribution __x from the input stream __is.
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5132
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5145
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5152
double p() const
Return the parameter of the distribution.
Definition random.h:5117
friend bool operator==(const negative_binomial_distribution &__d1, const negative_binomial_distribution &__d2)
Return true if two negative binomial distributions have the same parameters and the sequences that wo...
Definition random.h:5201
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5124
_IntType k() const
Return the parameter of the distribution.
Definition random.h:5110
void reset()
Resets the distribution state.
Definition random.h:5103
A discrete Poisson random number distribution.
Definition random.h:5285
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
void reset()
Resets the distribution state.
Definition random.h:5354
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5398
double mean() const
Returns the distribution parameter mean.
Definition random.h:5361
friend bool operator==(const poisson_distribution &__d1, const poisson_distribution &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
Definition random.h:5434
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5390
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5376
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::poisson_distribution< _IntType1 > &__x)
Inserts a poisson_distribution random number distribution __x into the output stream __os.
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5368
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::poisson_distribution< _IntType1 > &__x)
Extracts a poisson_distribution random number distribution __x from the input stream __is.
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5383
An exponential continuous distribution for random numbers.
Definition random.h:5517
_RealType lambda() const
Returns the inverse scale parameter of the distribution.
Definition random.h:5590
exponential_distribution()
Constructs an exponential distribution with inverse scale parameter 1.0.
Definition random.h:5562
exponential_distribution(_RealType __lambda)
Constructs an exponential distribution with inverse scale parameter .
Definition random.h:5569
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5627
void reset()
Resets the distribution state.
Definition random.h:5584
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5612
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5597
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5619
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5605
friend bool operator==(const exponential_distribution &__d1, const exponential_distribution &__d2)
Return true if two exponential distributions have the same parameters.
Definition random.h:5667
A weibull_distribution random number distribution.
Definition random.h:5739
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5819
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5834
void reset()
Resets the distribution state.
Definition random.h:5798
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5849
friend bool operator==(const weibull_distribution &__d1, const weibull_distribution &__d2)
Return true if two Weibull distributions have the same parameters.
Definition random.h:5884
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5827
_RealType b() const
Return the parameter of the distribution.
Definition random.h:5812
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5841
_RealType a() const
Return the parameter of the distribution.
Definition random.h:5805
A extreme_value_distribution random number distribution.
Definition random.h:5956
void reset()
Resets the distribution state.
Definition random.h:6015
_RealType b() const
Return the parameter of the distribution.
Definition random.h:6029
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6066
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6044
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6051
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6058
_RealType a() const
Return the parameter of the distribution.
Definition random.h:6022
friend bool operator==(const extreme_value_distribution &__d1, const extreme_value_distribution &__d2)
Return true if two extreme value distributions have the same parameters.
Definition random.h:6101
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6036
A discrete_distribution random number distribution.
Definition random.h:6178
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::discrete_distribution< _IntType1 > &__x)
Inserts a discrete_distribution random number distribution __x into the output stream __os.
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6297
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::discrete_distribution< _IntType1 > &__x)
Extracts a discrete_distribution random number distribution __x from the input stream __is.
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6304
void reset()
Resets the distribution state.
Definition random.h:6265
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6282
friend bool operator==(const discrete_distribution &__d1, const discrete_distribution &__d2)
Return true if two discrete distributions have the same parameters.
Definition random.h:6350
std::vector< double > probabilities() const
Returns the probabilities of the distribution.
Definition random.h:6272
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6315
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6290
A piecewise_constant_distribution random number distribution.
Definition random.h:6426
std::vector< double > densities() const
Returns a vector of the probability densities.
Definition random.h:6552
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6570
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6577
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6587
void reset()
Resets the distribution state.
Definition random.h:6529
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::piecewise_constant_distribution< _RealType1 > &__x)
Inserts a piecewise_constant_distribution random number distribution __x into the output stream __os.
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6562
friend bool operator==(const piecewise_constant_distribution &__d1, const piecewise_constant_distribution &__d2)
Return true if two piecewise constant distributions have the same parameters.
Definition random.h:6633
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6598
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::piecewise_constant_distribution< _RealType1 > &__x)
Extracts a piecewise_constant_distribution random number distribution __x from the input stream __is.
std::vector< _RealType > intervals() const
Returns a vector of the intervals.
Definition random.h:6536
A piecewise_linear_distribution random number distribution.
Definition random.h:6706
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6880
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6869
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::piecewise_linear_distribution< _RealType1 > &__x)
Extracts a piecewise_linear_distribution random number distribution __x from the input stream __is.
std::vector< _RealType > intervals() const
Return the intervals of the distribution.
Definition random.h:6817
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6844
friend bool operator==(const piecewise_linear_distribution &__d1, const piecewise_linear_distribution &__d2)
Return true if two piecewise linear distributions have the same parameters.
Definition random.h:6915
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6852
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6859
std::vector< double > densities() const
Return a vector of the probability densities of the distribution.
Definition random.h:6834
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::piecewise_linear_distribution< _RealType1 > &__x)
Inserts a piecewise_linear_distribution random number distribution __x into the output stream __os.
seed_seq() noexcept
Definition random.h:6998
uint_least32_t result_type
Definition random.h:6995
A standard container which offers fixed time access to individual elements in any order.
Definition stl_vector.h:461
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
Definition stl_vector.h:988
constexpr bool empty() const noexcept
constexpr size_type size() const noexcept