libstdc++
random.h
Go to the documentation of this file.
1// random number generation -*- C++ -*-
2
3// Copyright (C) 2009-2025 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
2098 min()
2099 { return 0; }
2100
2101 /// The maximum value that this engine can return
2102 static constexpr result_type
2103 max()
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
2111 philox_engine()
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
2154 set_counter(const array<result_type, __n>& __counter)
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
2174 operator()()
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>
2199 friend basic_ostream<_CharT, _Traits>&
2200 operator<<(basic_ostream<_CharT, _Traits>& __os,
2201 const philox_engine& __x)
2202 {
2203 const typename ios_base::fmtflags __flags = __os.flags();
2204 const _CharT __fill = __os.fill();
2205 __os.flags(ios_base::dec | ios_base::left);
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>
2226 friend basic_istream<_CharT, _Traits>&
2227 operator>>(basic_istream<_CharT, _Traits>& __is,
2228 philox_engine& __x)
2229 {
2230 const typename ios_base::fmtflags __flags = __is.flags();
2231 __is.flags(ios_base::dec | ios_base::skipws);
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
2262 array<_UIntType, __n> _M_x;
2263 array<_UIntType, __n / 2> _M_k;
2264 array<_UIntType, __n> _M_y;
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 */
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;
3504 param_type;
3505 _M_gd.param(param_type{__param.n() / 2});
3506 }
3507
3508 /**
3509 * @brief Returns the greatest lower bound value of the distribution.
3510 */
3511 result_type
3512 min() const
3513 { return result_type(0); }
3514
3515 /**
3516 * @brief Returns the least upper bound value of the distribution.
3517 */
3518 result_type
3519 max() const
3521
3522 /**
3523 * @brief Generating functions.
3524 */
3525 template<typename _UniformRandomNumberGenerator>
3526 result_type
3527 operator()(_UniformRandomNumberGenerator& __urng)
3528 { return 2 * _M_gd(__urng); }
3529
3530 template<typename _UniformRandomNumberGenerator>
3531 result_type
3532 operator()(_UniformRandomNumberGenerator& __urng,
3533 const param_type& __p)
3534 {
3536 param_type;
3537 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
3538 }
3539
3540 template<typename _ForwardIterator,
3541 typename _UniformRandomNumberGenerator>
3542 void
3543 __generate(_ForwardIterator __f, _ForwardIterator __t,
3544 _UniformRandomNumberGenerator& __urng)
3545 { this->__generate_impl(__f, __t, __urng); }
3546
3547 template<typename _ForwardIterator,
3548 typename _UniformRandomNumberGenerator>
3549 void
3550 __generate(_ForwardIterator __f, _ForwardIterator __t,
3551 _UniformRandomNumberGenerator& __urng,
3552 const param_type& __p)
3553 { typename std::gamma_distribution<result_type>::param_type
3554 __p2(__p.n() / 2);
3555 this->__generate_impl(__f, __t, __urng, __p2); }
3556
3557 template<typename _UniformRandomNumberGenerator>
3558 void
3559 __generate(result_type* __f, result_type* __t,
3560 _UniformRandomNumberGenerator& __urng)
3561 { this->__generate_impl(__f, __t, __urng); }
3562
3563 template<typename _UniformRandomNumberGenerator>
3564 void
3565 __generate(result_type* __f, result_type* __t,
3566 _UniformRandomNumberGenerator& __urng,
3567 const param_type& __p)
3568 { typename std::gamma_distribution<result_type>::param_type
3569 __p2(__p.n() / 2);
3570 this->__generate_impl(__f, __t, __urng, __p2); }
3571
3572 /**
3573 * @brief Return true if two Chi-squared distributions have
3574 * the same parameters and the sequences that would be
3575 * generated are equal.
3576 */
3577 friend bool
3578 operator==(const chi_squared_distribution& __d1,
3579 const chi_squared_distribution& __d2)
3580 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
3581
3582 /**
3583 * @brief Inserts a %chi_squared_distribution random number distribution
3584 * @p __x into the output stream @p __os.
3585 *
3586 * @param __os An output stream.
3587 * @param __x A %chi_squared_distribution random number distribution.
3588 *
3589 * @returns The output stream with the state of @p __x inserted or in
3590 * an error state.
3591 */
3592 template<typename _RealType1, typename _CharT, typename _Traits>
3596
3597 /**
3598 * @brief Extracts a %chi_squared_distribution random number distribution
3599 * @p __x from the input stream @p __is.
3600 *
3601 * @param __is An input stream.
3602 * @param __x A %chi_squared_distribution random number
3603 * generator engine.
3604 *
3605 * @returns The input stream with @p __x extracted or in an error state.
3606 */
3607 template<typename _RealType1, typename _CharT, typename _Traits>
3611
3612 private:
3613 template<typename _ForwardIterator,
3614 typename _UniformRandomNumberGenerator>
3615 void
3616 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3617 _UniformRandomNumberGenerator& __urng);
3618
3619 template<typename _ForwardIterator,
3620 typename _UniformRandomNumberGenerator>
3621 void
3622 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3623 _UniformRandomNumberGenerator& __urng,
3624 const typename
3626
3627 param_type _M_param;
3628
3630 };
3631
3632#if __cpp_impl_three_way_comparison < 201907L
3633 /**
3634 * @brief Return true if two Chi-squared distributions are different.
3635 */
3636 template<typename _RealType>
3637 inline bool
3638 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
3640 { return !(__d1 == __d2); }
3641#endif
3642
3643 /**
3644 * @brief A cauchy_distribution random number distribution.
3645 *
3646 * The formula for the normal probability mass function is
3647 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
3648 *
3649 * @headerfile random
3650 * @since C++11
3651 */
3652 template<typename _RealType = double>
3653 class cauchy_distribution
3654 {
3656 "result_type must be a floating point type");
3657
3658 public:
3659 /** The type of the range of the distribution. */
3660 typedef _RealType result_type;
3661
3662 /** Parameter type. */
3663 struct param_type
3664 {
3665 typedef cauchy_distribution<_RealType> distribution_type;
3666
3667 param_type() : param_type(0) { }
3668
3669 explicit
3670 param_type(_RealType __a, _RealType __b = _RealType(1))
3671 : _M_a(__a), _M_b(__b)
3672 { }
3673
3674 _RealType
3675 a() const
3676 { return _M_a; }
3677
3678 _RealType
3679 b() const
3680 { return _M_b; }
3681
3682 friend bool
3683 operator==(const param_type& __p1, const param_type& __p2)
3684 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
3685
3686#if __cpp_impl_three_way_comparison < 201907L
3687 friend bool
3688 operator!=(const param_type& __p1, const param_type& __p2)
3689 { return !(__p1 == __p2); }
3690#endif
3691
3692 private:
3693 _RealType _M_a;
3694 _RealType _M_b;
3695 };
3696
3697 cauchy_distribution() : cauchy_distribution(0.0) { }
3698
3699 explicit
3700 cauchy_distribution(_RealType __a, _RealType __b = 1.0)
3701 : _M_param(__a, __b)
3702 { }
3703
3704 explicit
3705 cauchy_distribution(const param_type& __p)
3706 : _M_param(__p)
3707 { }
3708
3709 /**
3710 * @brief Resets the distribution state.
3711 */
3712 void
3714 { }
3715
3716 /**
3717 *
3718 */
3719 _RealType
3720 a() const
3721 { return _M_param.a(); }
3722
3723 _RealType
3724 b() const
3725 { return _M_param.b(); }
3726
3727 /**
3728 * @brief Returns the parameter set of the distribution.
3729 */
3731 param() const
3732 { return _M_param; }
3733
3734 /**
3735 * @brief Sets the parameter set of the distribution.
3736 * @param __param The new parameter set of the distribution.
3737 */
3738 void
3739 param(const param_type& __param)
3740 { _M_param = __param; }
3741
3742 /**
3743 * @brief Returns the greatest lower bound value of the distribution.
3744 */
3745 result_type
3748
3749 /**
3750 * @brief Returns the least upper bound value of the distribution.
3751 */
3752 result_type
3753 max() const
3755
3756 /**
3757 * @brief Generating functions.
3758 */
3759 template<typename _UniformRandomNumberGenerator>
3760 result_type
3761 operator()(_UniformRandomNumberGenerator& __urng)
3762 { return this->operator()(__urng, _M_param); }
3763
3764 template<typename _UniformRandomNumberGenerator>
3765 result_type
3766 operator()(_UniformRandomNumberGenerator& __urng,
3767 const param_type& __p);
3768
3769 template<typename _ForwardIterator,
3770 typename _UniformRandomNumberGenerator>
3771 void
3772 __generate(_ForwardIterator __f, _ForwardIterator __t,
3773 _UniformRandomNumberGenerator& __urng)
3774 { this->__generate(__f, __t, __urng, _M_param); }
3775
3776 template<typename _ForwardIterator,
3777 typename _UniformRandomNumberGenerator>
3778 void
3779 __generate(_ForwardIterator __f, _ForwardIterator __t,
3780 _UniformRandomNumberGenerator& __urng,
3781 const param_type& __p)
3782 { this->__generate_impl(__f, __t, __urng, __p); }
3783
3784 template<typename _UniformRandomNumberGenerator>
3785 void
3786 __generate(result_type* __f, result_type* __t,
3787 _UniformRandomNumberGenerator& __urng,
3788 const param_type& __p)
3789 { this->__generate_impl(__f, __t, __urng, __p); }
3790
3791 /**
3792 * @brief Return true if two Cauchy distributions have
3793 * the same parameters.
3794 */
3795 friend bool
3796 operator==(const cauchy_distribution& __d1,
3797 const cauchy_distribution& __d2)
3798 { return __d1._M_param == __d2._M_param; }
3799
3800 private:
3801 template<typename _ForwardIterator,
3802 typename _UniformRandomNumberGenerator>
3803 void
3804 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3805 _UniformRandomNumberGenerator& __urng,
3806 const param_type& __p);
3807
3808 param_type _M_param;
3809 };
3810
3811#if __cpp_impl_three_way_comparison < 201907L
3812 /**
3813 * @brief Return true if two Cauchy distributions have
3814 * different parameters.
3815 */
3816 template<typename _RealType>
3817 inline bool
3818 operator!=(const std::cauchy_distribution<_RealType>& __d1,
3820 { return !(__d1 == __d2); }
3821#endif
3822
3823 /**
3824 * @brief Inserts a %cauchy_distribution random number distribution
3825 * @p __x into the output stream @p __os.
3826 *
3827 * @param __os An output stream.
3828 * @param __x A %cauchy_distribution random number distribution.
3829 *
3830 * @returns The output stream with the state of @p __x inserted or in
3831 * an error state.
3832 */
3833 template<typename _RealType, typename _CharT, typename _Traits>
3834 std::basic_ostream<_CharT, _Traits>&
3835 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3836 const std::cauchy_distribution<_RealType>& __x);
3837
3838 /**
3839 * @brief Extracts a %cauchy_distribution random number distribution
3840 * @p __x from the input stream @p __is.
3841 *
3842 * @param __is An input stream.
3843 * @param __x A %cauchy_distribution random number
3844 * generator engine.
3845 *
3846 * @returns The input stream with @p __x extracted or in an error state.
3847 */
3848 template<typename _RealType, typename _CharT, typename _Traits>
3849 std::basic_istream<_CharT, _Traits>&
3850 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3851 std::cauchy_distribution<_RealType>& __x);
3852
3853
3854 /**
3855 * @brief A fisher_f_distribution random number distribution.
3856 *
3857 * The formula for the normal probability mass function is
3858 * @f[
3859 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3860 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3861 * (1 + \frac{mx}{n})^{-(m+n)/2}
3862 * @f]
3863 *
3864 * @headerfile random
3865 * @since C++11
3866 */
3867 template<typename _RealType = double>
3868 class fisher_f_distribution
3869 {
3871 "result_type must be a floating point type");
3872
3873 public:
3874 /** The type of the range of the distribution. */
3875 typedef _RealType result_type;
3876
3877 /** Parameter type. */
3878 struct param_type
3879 {
3880 typedef fisher_f_distribution<_RealType> distribution_type;
3881
3882 param_type() : param_type(1) { }
3883
3884 explicit
3885 param_type(_RealType __m, _RealType __n = _RealType(1))
3886 : _M_m(__m), _M_n(__n)
3887 { }
3888
3889 _RealType
3890 m() const
3891 { return _M_m; }
3892
3893 _RealType
3894 n() const
3895 { return _M_n; }
3896
3897 friend bool
3898 operator==(const param_type& __p1, const param_type& __p2)
3899 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
3900
3901#if __cpp_impl_three_way_comparison < 201907L
3902 friend bool
3903 operator!=(const param_type& __p1, const param_type& __p2)
3904 { return !(__p1 == __p2); }
3905#endif
3906
3907 private:
3908 _RealType _M_m;
3909 _RealType _M_n;
3910 };
3911
3912 fisher_f_distribution() : fisher_f_distribution(1.0) { }
3913
3914 explicit
3915 fisher_f_distribution(_RealType __m,
3916 _RealType __n = _RealType(1))
3917 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
3918 { }
3919
3920 explicit
3921 fisher_f_distribution(const param_type& __p)
3922 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
3923 { }
3924
3925 /**
3926 * @brief Resets the distribution state.
3927 */
3928 void
3930 {
3931 _M_gd_x.reset();
3932 _M_gd_y.reset();
3933 }
3934
3935 /**
3936 *
3937 */
3938 _RealType
3939 m() const
3940 { return _M_param.m(); }
3941
3942 _RealType
3943 n() const
3944 { return _M_param.n(); }
3945
3946 /**
3947 * @brief Returns the parameter set of the distribution.
3948 */
3950 param() const
3951 { return _M_param; }
3952
3953 /**
3954 * @brief Sets the parameter set of the distribution.
3955 * @param __param The new parameter set of the distribution.
3956 */
3957 void
3958 param(const param_type& __param)
3959 { _M_param = __param; }
3960
3961 /**
3962 * @brief Returns the greatest lower bound value of the distribution.
3963 */
3964 result_type
3965 min() const
3966 { return result_type(0); }
3967
3968 /**
3969 * @brief Returns the least upper bound value of the distribution.
3970 */
3971 result_type
3972 max() const
3974
3975 /**
3976 * @brief Generating functions.
3977 */
3978 template<typename _UniformRandomNumberGenerator>
3979 result_type
3980 operator()(_UniformRandomNumberGenerator& __urng)
3981 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
3982
3983 template<typename _UniformRandomNumberGenerator>
3984 result_type
3985 operator()(_UniformRandomNumberGenerator& __urng,
3986 const param_type& __p)
3987 {
3989 param_type;
3990 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
3991 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
3992 }
3993
3994 template<typename _ForwardIterator,
3995 typename _UniformRandomNumberGenerator>
3996 void
3997 __generate(_ForwardIterator __f, _ForwardIterator __t,
3998 _UniformRandomNumberGenerator& __urng)
3999 { this->__generate_impl(__f, __t, __urng); }
4000
4001 template<typename _ForwardIterator,
4002 typename _UniformRandomNumberGenerator>
4003 void
4004 __generate(_ForwardIterator __f, _ForwardIterator __t,
4005 _UniformRandomNumberGenerator& __urng,
4006 const param_type& __p)
4007 { this->__generate_impl(__f, __t, __urng, __p); }
4008
4009 template<typename _UniformRandomNumberGenerator>
4010 void
4011 __generate(result_type* __f, result_type* __t,
4012 _UniformRandomNumberGenerator& __urng)
4013 { this->__generate_impl(__f, __t, __urng); }
4014
4015 template<typename _UniformRandomNumberGenerator>
4016 void
4017 __generate(result_type* __f, result_type* __t,
4018 _UniformRandomNumberGenerator& __urng,
4019 const param_type& __p)
4020 { this->__generate_impl(__f, __t, __urng, __p); }
4021
4022 /**
4023 * @brief Return true if two Fisher f distributions have
4024 * the same parameters and the sequences that would
4025 * be generated are equal.
4026 */
4027 friend bool
4028 operator==(const fisher_f_distribution& __d1,
4029 const fisher_f_distribution& __d2)
4030 { return (__d1._M_param == __d2._M_param
4031 && __d1._M_gd_x == __d2._M_gd_x
4032 && __d1._M_gd_y == __d2._M_gd_y); }
4033
4034 /**
4035 * @brief Inserts a %fisher_f_distribution random number distribution
4036 * @p __x into the output stream @p __os.
4037 *
4038 * @param __os An output stream.
4039 * @param __x A %fisher_f_distribution random number distribution.
4040 *
4041 * @returns The output stream with the state of @p __x inserted or in
4042 * an error state.
4043 */
4044 template<typename _RealType1, typename _CharT, typename _Traits>
4048
4049 /**
4050 * @brief Extracts a %fisher_f_distribution random number distribution
4051 * @p __x from the input stream @p __is.
4052 *
4053 * @param __is An input stream.
4054 * @param __x A %fisher_f_distribution random number
4055 * generator engine.
4056 *
4057 * @returns The input stream with @p __x extracted or in an error state.
4058 */
4059 template<typename _RealType1, typename _CharT, typename _Traits>
4063
4064 private:
4065 template<typename _ForwardIterator,
4066 typename _UniformRandomNumberGenerator>
4067 void
4068 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4069 _UniformRandomNumberGenerator& __urng);
4070
4071 template<typename _ForwardIterator,
4072 typename _UniformRandomNumberGenerator>
4073 void
4074 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4075 _UniformRandomNumberGenerator& __urng,
4076 const param_type& __p);
4077
4078 param_type _M_param;
4079
4080 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
4081 };
4082
4083#if __cpp_impl_three_way_comparison < 201907L
4084 /**
4085 * @brief Return true if two Fisher f distributions are different.
4086 */
4087 template<typename _RealType>
4088 inline bool
4089 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
4091 { return !(__d1 == __d2); }
4092#endif
4093
4094 /**
4095 * @brief A student_t_distribution random number distribution.
4096 *
4097 * The formula for the normal probability mass function is:
4098 * @f[
4099 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
4100 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
4101 * @f]
4102 *
4103 * @headerfile random
4104 * @since C++11
4105 */
4106 template<typename _RealType = double>
4107 class student_t_distribution
4108 {
4110 "result_type must be a floating point type");
4111
4112 public:
4113 /** The type of the range of the distribution. */
4114 typedef _RealType result_type;
4115
4116 /** Parameter type. */
4117 struct param_type
4118 {
4119 typedef student_t_distribution<_RealType> distribution_type;
4120
4121 param_type() : param_type(1) { }
4122
4123 explicit
4124 param_type(_RealType __n)
4125 : _M_n(__n)
4126 { }
4127
4128 _RealType
4129 n() const
4130 { return _M_n; }
4131
4132 friend bool
4133 operator==(const param_type& __p1, const param_type& __p2)
4134 { return __p1._M_n == __p2._M_n; }
4135
4136#if __cpp_impl_three_way_comparison < 201907L
4137 friend bool
4138 operator!=(const param_type& __p1, const param_type& __p2)
4139 { return !(__p1 == __p2); }
4140#endif
4141
4142 private:
4143 _RealType _M_n;
4144 };
4145
4146 student_t_distribution() : student_t_distribution(1.0) { }
4147
4148 explicit
4149 student_t_distribution(_RealType __n)
4150 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
4151 { }
4152
4153 explicit
4154 student_t_distribution(const param_type& __p)
4155 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
4156 { }
4157
4158 /**
4159 * @brief Resets the distribution state.
4160 */
4161 void
4163 {
4164 _M_nd.reset();
4165 _M_gd.reset();
4166 }
4167
4168 /**
4169 *
4170 */
4171 _RealType
4172 n() const
4173 { return _M_param.n(); }
4174
4175 /**
4176 * @brief Returns the parameter set of the distribution.
4177 */
4178 param_type
4179 param() const
4180 { return _M_param; }
4181
4182 /**
4183 * @brief Sets the parameter set of the distribution.
4184 * @param __param The new parameter set of the distribution.
4185 */
4186 void
4187 param(const param_type& __param)
4188 { _M_param = __param; }
4189
4190 /**
4191 * @brief Returns the greatest lower bound value of the distribution.
4192 */
4193 result_type
4196
4197 /**
4198 * @brief Returns the least upper bound value of the distribution.
4199 */
4200 result_type
4201 max() const
4203
4204 /**
4205 * @brief Generating functions.
4206 */
4207 template<typename _UniformRandomNumberGenerator>
4208 result_type
4209 operator()(_UniformRandomNumberGenerator& __urng)
4210 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
4211
4212 template<typename _UniformRandomNumberGenerator>
4213 result_type
4214 operator()(_UniformRandomNumberGenerator& __urng,
4215 const param_type& __p)
4216 {
4218 param_type;
4219
4220 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
4221 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
4222 }
4223
4224 template<typename _ForwardIterator,
4225 typename _UniformRandomNumberGenerator>
4226 void
4227 __generate(_ForwardIterator __f, _ForwardIterator __t,
4228 _UniformRandomNumberGenerator& __urng)
4229 { this->__generate_impl(__f, __t, __urng); }
4230
4231 template<typename _ForwardIterator,
4232 typename _UniformRandomNumberGenerator>
4233 void
4234 __generate(_ForwardIterator __f, _ForwardIterator __t,
4235 _UniformRandomNumberGenerator& __urng,
4236 const param_type& __p)
4237 { this->__generate_impl(__f, __t, __urng, __p); }
4238
4239 template<typename _UniformRandomNumberGenerator>
4240 void
4241 __generate(result_type* __f, result_type* __t,
4242 _UniformRandomNumberGenerator& __urng)
4243 { this->__generate_impl(__f, __t, __urng); }
4244
4245 template<typename _UniformRandomNumberGenerator>
4246 void
4247 __generate(result_type* __f, result_type* __t,
4248 _UniformRandomNumberGenerator& __urng,
4249 const param_type& __p)
4250 { this->__generate_impl(__f, __t, __urng, __p); }
4251
4252 /**
4253 * @brief Return true if two Student t distributions have
4254 * the same parameters and the sequences that would
4255 * be generated are equal.
4256 */
4257 friend bool
4258 operator==(const student_t_distribution& __d1,
4259 const student_t_distribution& __d2)
4260 { return (__d1._M_param == __d2._M_param
4261 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
4262
4263 /**
4264 * @brief Inserts a %student_t_distribution random number distribution
4265 * @p __x into the output stream @p __os.
4266 *
4267 * @param __os An output stream.
4268 * @param __x A %student_t_distribution random number distribution.
4269 *
4270 * @returns The output stream with the state of @p __x inserted or in
4271 * an error state.
4272 */
4273 template<typename _RealType1, typename _CharT, typename _Traits>
4277
4278 /**
4279 * @brief Extracts a %student_t_distribution random number distribution
4280 * @p __x from the input stream @p __is.
4281 *
4282 * @param __is An input stream.
4283 * @param __x A %student_t_distribution random number
4284 * generator engine.
4285 *
4286 * @returns The input stream with @p __x extracted or in an error state.
4287 */
4288 template<typename _RealType1, typename _CharT, typename _Traits>
4292
4293 private:
4294 template<typename _ForwardIterator,
4295 typename _UniformRandomNumberGenerator>
4296 void
4297 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4298 _UniformRandomNumberGenerator& __urng);
4299 template<typename _ForwardIterator,
4300 typename _UniformRandomNumberGenerator>
4301 void
4302 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4303 _UniformRandomNumberGenerator& __urng,
4304 const param_type& __p);
4305
4306 param_type _M_param;
4307
4310 };
4311
4312#if __cpp_impl_three_way_comparison < 201907L
4313 /**
4314 * @brief Return true if two Student t distributions are different.
4315 */
4316 template<typename _RealType>
4317 inline bool
4318 operator!=(const std::student_t_distribution<_RealType>& __d1,
4320 { return !(__d1 == __d2); }
4321#endif
4322
4323 /// @} group random_distributions_normal
4324
4325 /**
4326 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
4327 * @ingroup random_distributions
4328 * @{
4329 */
4330
4331 /**
4332 * @brief A Bernoulli random number distribution.
4333 *
4334 * Generates a sequence of true and false values with likelihood @f$p@f$
4335 * that true will come up and @f$(1 - p)@f$ that false will appear.
4336 *
4337 * @headerfile random
4338 * @since C++11
4339 */
4341 {
4342 public:
4343 /** The type of the range of the distribution. */
4344 typedef bool result_type;
4345
4346 /** Parameter type. */
4347 struct param_type
4348 {
4349 typedef bernoulli_distribution distribution_type;
4350
4351 param_type() : param_type(0.5) { }
4352
4353 explicit
4354 param_type(double __p)
4355 : _M_p(__p)
4356 {
4357 __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0));
4358 }
4359
4360 double
4361 p() const
4362 { return _M_p; }
4363
4364 friend bool
4365 operator==(const param_type& __p1, const param_type& __p2)
4366 { return __p1._M_p == __p2._M_p; }
4367
4368#if __cpp_impl_three_way_comparison < 201907L
4369 friend bool
4370 operator!=(const param_type& __p1, const param_type& __p2)
4371 { return !(__p1 == __p2); }
4372#endif
4373
4374 private:
4375 double _M_p;
4376 };
4377
4378 public:
4379 /**
4380 * @brief Constructs a Bernoulli distribution with likelihood 0.5.
4381 */
4383
4384 /**
4385 * @brief Constructs a Bernoulli distribution with likelihood @p p.
4386 *
4387 * @param __p [IN] The likelihood of a true result being returned.
4388 * Must be in the interval @f$[0, 1]@f$.
4389 */
4390 explicit
4392 : _M_param(__p)
4393 { }
4394
4395 explicit
4396 bernoulli_distribution(const param_type& __p)
4397 : _M_param(__p)
4398 { }
4399
4400 /**
4401 * @brief Resets the distribution state.
4402 *
4403 * Does nothing for a Bernoulli distribution.
4404 */
4405 void
4406 reset() { }
4407
4408 /**
4409 * @brief Returns the @p p parameter of the distribution.
4410 */
4411 double
4412 p() const
4413 { return _M_param.p(); }
4414
4415 /**
4416 * @brief Returns the parameter set of the distribution.
4417 */
4418 param_type
4419 param() const
4420 { return _M_param; }
4421
4422 /**
4423 * @brief Sets the parameter set of the distribution.
4424 * @param __param The new parameter set of the distribution.
4425 */
4426 void
4427 param(const param_type& __param)
4428 { _M_param = __param; }
4429
4430 /**
4431 * @brief Returns the greatest lower bound value of the distribution.
4432 */
4433 result_type
4434 min() const
4436
4437 /**
4438 * @brief Returns the least upper bound value of the distribution.
4439 */
4440 result_type
4441 max() const
4443
4444 /**
4445 * @brief Generating functions.
4446 */
4447 template<typename _UniformRandomNumberGenerator>
4448 result_type
4449 operator()(_UniformRandomNumberGenerator& __urng)
4450 { return this->operator()(__urng, _M_param); }
4451
4452 template<typename _UniformRandomNumberGenerator>
4453 result_type
4454 operator()(_UniformRandomNumberGenerator& __urng,
4455 const param_type& __p)
4456 {
4457 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
4458 __aurng(__urng);
4459 if ((__aurng() - __aurng.min())
4460 < __p.p() * (__aurng.max() - __aurng.min()))
4461 return true;
4462 return false;
4463 }
4464
4465 template<typename _ForwardIterator,
4466 typename _UniformRandomNumberGenerator>
4467 void
4468 __generate(_ForwardIterator __f, _ForwardIterator __t,
4469 _UniformRandomNumberGenerator& __urng)
4470 { this->__generate(__f, __t, __urng, _M_param); }
4471
4472 template<typename _ForwardIterator,
4473 typename _UniformRandomNumberGenerator>
4474 void
4475 __generate(_ForwardIterator __f, _ForwardIterator __t,
4476 _UniformRandomNumberGenerator& __urng, const param_type& __p)
4477 { this->__generate_impl(__f, __t, __urng, __p); }
4478
4479 template<typename _UniformRandomNumberGenerator>
4480 void
4481 __generate(result_type* __f, result_type* __t,
4482 _UniformRandomNumberGenerator& __urng,
4483 const param_type& __p)
4484 { this->__generate_impl(__f, __t, __urng, __p); }
4485
4486 /**
4487 * @brief Return true if two Bernoulli distributions have
4488 * the same parameters.
4489 */
4490 friend bool
4492 const bernoulli_distribution& __d2)
4493 { return __d1._M_param == __d2._M_param; }
4494
4495 private:
4496 template<typename _ForwardIterator,
4497 typename _UniformRandomNumberGenerator>
4498 void
4499 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4500 _UniformRandomNumberGenerator& __urng,
4501 const param_type& __p);
4502
4503 param_type _M_param;
4504 };
4505
4506#if __cpp_impl_three_way_comparison < 201907L
4507 /**
4508 * @brief Return true if two Bernoulli distributions have
4509 * different parameters.
4510 */
4511 inline bool
4512 operator!=(const std::bernoulli_distribution& __d1,
4513 const std::bernoulli_distribution& __d2)
4514 { return !(__d1 == __d2); }
4515#endif
4516
4517 /**
4518 * @brief Inserts a %bernoulli_distribution random number distribution
4519 * @p __x into the output stream @p __os.
4520 *
4521 * @param __os An output stream.
4522 * @param __x A %bernoulli_distribution random number distribution.
4523 *
4524 * @returns The output stream with the state of @p __x inserted or in
4525 * an error state.
4526 */
4527 template<typename _CharT, typename _Traits>
4528 std::basic_ostream<_CharT, _Traits>&
4529 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4530 const std::bernoulli_distribution& __x);
4531
4532 /**
4533 * @brief Extracts a %bernoulli_distribution random number distribution
4534 * @p __x from the input stream @p __is.
4535 *
4536 * @param __is An input stream.
4537 * @param __x A %bernoulli_distribution random number generator engine.
4538 *
4539 * @returns The input stream with @p __x extracted or in an error state.
4540 */
4541 template<typename _CharT, typename _Traits>
4542 inline std::basic_istream<_CharT, _Traits>&
4545 {
4546 double __p;
4547 if (__is >> __p)
4549 return __is;
4550 }
4551
4552
4553 /**
4554 * @brief A discrete binomial random number distribution.
4555 *
4556 * The formula for the binomial probability density function is
4557 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4558 * and @f$p@f$ are the parameters of the distribution.
4559 *
4560 * @headerfile random
4561 * @since C++11
4562 */
4563 template<typename _IntType = int>
4564 class binomial_distribution
4565 {
4567 "result_type must be an integral type");
4568
4569 public:
4570 /** The type of the range of the distribution. */
4571 typedef _IntType result_type;
4572
4573 /** Parameter type. */
4574 struct param_type
4575 {
4576 typedef binomial_distribution<_IntType> distribution_type;
4577 friend class binomial_distribution<_IntType>;
4578
4579 param_type() : param_type(1) { }
4580
4581 explicit
4582 param_type(_IntType __t, double __p = 0.5)
4583 : _M_t(__t), _M_p(__p)
4584 {
4585 __glibcxx_assert((_M_t >= _IntType(0))
4586 && (_M_p >= 0.0)
4587 && (_M_p <= 1.0));
4588 _M_initialize();
4589 }
4590
4591 _IntType
4592 t() const
4593 { return _M_t; }
4594
4595 double
4596 p() const
4597 { return _M_p; }
4598
4599 friend bool
4600 operator==(const param_type& __p1, const param_type& __p2)
4601 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
4602
4603#if __cpp_impl_three_way_comparison < 201907L
4604 friend bool
4605 operator!=(const param_type& __p1, const param_type& __p2)
4606 { return !(__p1 == __p2); }
4607#endif
4608
4609 private:
4610 void
4611 _M_initialize();
4612
4613 _IntType _M_t;
4614 double _M_p;
4615
4616 double _M_q;
4617#if _GLIBCXX_USE_C99_MATH_FUNCS
4618 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
4619 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
4620#endif
4621 bool _M_easy;
4622 };
4623
4624 // constructors and member functions
4625
4626 binomial_distribution() : binomial_distribution(1) { }
4627
4628 explicit
4629 binomial_distribution(_IntType __t, double __p = 0.5)
4630 : _M_param(__t, __p), _M_nd()
4631 { }
4632
4633 explicit
4634 binomial_distribution(const param_type& __p)
4635 : _M_param(__p), _M_nd()
4636 { }
4637
4638 /**
4639 * @brief Resets the distribution state.
4640 */
4641 void
4643 { _M_nd.reset(); }
4644
4645 /**
4646 * @brief Returns the distribution @p t parameter.
4647 */
4648 _IntType
4649 t() const
4650 { return _M_param.t(); }
4651
4652 /**
4653 * @brief Returns the distribution @p p parameter.
4654 */
4655 double
4656 p() const
4657 { return _M_param.p(); }
4658
4659 /**
4660 * @brief Returns the parameter set of the distribution.
4661 */
4662 param_type
4663 param() const
4664 { return _M_param; }
4665
4666 /**
4667 * @brief Sets the parameter set of the distribution.
4668 * @param __param The new parameter set of the distribution.
4669 */
4670 void
4671 param(const param_type& __param)
4672 { _M_param = __param; }
4673
4674 /**
4675 * @brief Returns the greatest lower bound value of the distribution.
4676 */
4677 result_type
4678 min() const
4679 { return 0; }
4680
4681 /**
4682 * @brief Returns the least upper bound value of the distribution.
4683 */
4684 result_type
4685 max() const
4686 { return _M_param.t(); }
4687
4688 /**
4689 * @brief Generating functions.
4690 */
4691 template<typename _UniformRandomNumberGenerator>
4692 result_type
4693 operator()(_UniformRandomNumberGenerator& __urng)
4694 { return this->operator()(__urng, _M_param); }
4695
4696 template<typename _UniformRandomNumberGenerator>
4697 result_type
4698 operator()(_UniformRandomNumberGenerator& __urng,
4699 const param_type& __p);
4700
4701 template<typename _ForwardIterator,
4702 typename _UniformRandomNumberGenerator>
4703 void
4704 __generate(_ForwardIterator __f, _ForwardIterator __t,
4705 _UniformRandomNumberGenerator& __urng)
4706 { this->__generate(__f, __t, __urng, _M_param); }
4707
4708 template<typename _ForwardIterator,
4709 typename _UniformRandomNumberGenerator>
4710 void
4711 __generate(_ForwardIterator __f, _ForwardIterator __t,
4712 _UniformRandomNumberGenerator& __urng,
4713 const param_type& __p)
4714 { this->__generate_impl(__f, __t, __urng, __p); }
4715
4716 template<typename _UniformRandomNumberGenerator>
4717 void
4718 __generate(result_type* __f, result_type* __t,
4719 _UniformRandomNumberGenerator& __urng,
4720 const param_type& __p)
4721 { this->__generate_impl(__f, __t, __urng, __p); }
4722
4723 /**
4724 * @brief Return true if two binomial distributions have
4725 * the same parameters and the sequences that would
4726 * be generated are equal.
4727 */
4728 friend bool
4729 operator==(const binomial_distribution& __d1,
4730 const binomial_distribution& __d2)
4731#ifdef _GLIBCXX_USE_C99_MATH_FUNCS
4732 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4733#else
4734 { return __d1._M_param == __d2._M_param; }
4735#endif
4736
4737 /**
4738 * @brief Inserts a %binomial_distribution random number distribution
4739 * @p __x into the output stream @p __os.
4740 *
4741 * @param __os An output stream.
4742 * @param __x A %binomial_distribution random number distribution.
4743 *
4744 * @returns The output stream with the state of @p __x inserted or in
4745 * an error state.
4746 */
4747 template<typename _IntType1,
4748 typename _CharT, typename _Traits>
4752
4753 /**
4754 * @brief Extracts a %binomial_distribution random number distribution
4755 * @p __x from the input stream @p __is.
4756 *
4757 * @param __is An input stream.
4758 * @param __x A %binomial_distribution random number generator engine.
4759 *
4760 * @returns The input stream with @p __x extracted or in an error
4761 * state.
4762 */
4763 template<typename _IntType1,
4764 typename _CharT, typename _Traits>
4768
4769 private:
4770 template<typename _ForwardIterator,
4771 typename _UniformRandomNumberGenerator>
4772 void
4773 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4774 _UniformRandomNumberGenerator& __urng,
4775 const param_type& __p);
4776
4777 template<typename _UniformRandomNumberGenerator>
4779 _M_waiting(_UniformRandomNumberGenerator& __urng,
4780 _IntType __t, double __q);
4781
4782 param_type _M_param;
4783
4784 // NB: Unused when _GLIBCXX_USE_C99_MATH_FUNCS is undefined.
4786 };
4787
4788#if __cpp_impl_three_way_comparison < 201907L
4789 /**
4790 * @brief Return true if two binomial distributions are different.
4791 */
4792 template<typename _IntType>
4793 inline bool
4794 operator!=(const std::binomial_distribution<_IntType>& __d1,
4796 { return !(__d1 == __d2); }
4797#endif
4798
4799 /**
4800 * @brief A discrete geometric random number distribution.
4801 *
4802 * The formula for the geometric probability density function is
4803 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
4804 * distribution.
4805 *
4806 * @headerfile random
4807 * @since C++11
4808 */
4809 template<typename _IntType = int>
4810 class geometric_distribution
4811 {
4813 "result_type must be an integral type");
4814
4815 public:
4816 /** The type of the range of the distribution. */
4817 typedef _IntType result_type;
4818
4819 /** Parameter type. */
4820 struct param_type
4821 {
4822 typedef geometric_distribution<_IntType> distribution_type;
4823 friend class geometric_distribution<_IntType>;
4824
4825 param_type() : param_type(0.5) { }
4826
4827 explicit
4828 param_type(double __p)
4829 : _M_p(__p)
4830 {
4831 __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0));
4832 _M_initialize();
4833 }
4834
4835 double
4836 p() const
4837 { return _M_p; }
4838
4839 friend bool
4840 operator==(const param_type& __p1, const param_type& __p2)
4841 { return __p1._M_p == __p2._M_p; }
4842
4843#if __cpp_impl_three_way_comparison < 201907L
4844 friend bool
4845 operator!=(const param_type& __p1, const param_type& __p2)
4846 { return !(__p1 == __p2); }
4847#endif
4848
4849 private:
4850 void
4851 _M_initialize()
4852 { _M_log_1_p = std::log(1.0 - _M_p); }
4853
4854 double _M_p;
4855
4856 double _M_log_1_p;
4857 };
4858
4859 // constructors and member functions
4860
4861 geometric_distribution() : geometric_distribution(0.5) { }
4862
4863 explicit
4864 geometric_distribution(double __p)
4865 : _M_param(__p)
4866 { }
4867
4868 explicit
4869 geometric_distribution(const param_type& __p)
4870 : _M_param(__p)
4871 { }
4872
4873 /**
4874 * @brief Resets the distribution state.
4875 *
4876 * Does nothing for the geometric distribution.
4877 */
4878 void
4879 reset() { }
4880
4881 /**
4882 * @brief Returns the distribution parameter @p p.
4883 */
4884 double
4885 p() const
4886 { return _M_param.p(); }
4887
4888 /**
4889 * @brief Returns the parameter set of the distribution.
4890 */
4891 param_type
4892 param() const
4893 { return _M_param; }
4894
4895 /**
4896 * @brief Sets the parameter set of the distribution.
4897 * @param __param The new parameter set of the distribution.
4898 */
4899 void
4900 param(const param_type& __param)
4901 { _M_param = __param; }
4902
4903 /**
4904 * @brief Returns the greatest lower bound value of the distribution.
4905 */
4906 result_type
4907 min() const
4908 { return 0; }
4909
4910 /**
4911 * @brief Returns the least upper bound value of the distribution.
4912 */
4913 result_type
4914 max() const
4916
4917 /**
4918 * @brief Generating functions.
4919 */
4920 template<typename _UniformRandomNumberGenerator>
4921 result_type
4922 operator()(_UniformRandomNumberGenerator& __urng)
4923 { return this->operator()(__urng, _M_param); }
4924
4925 template<typename _UniformRandomNumberGenerator>
4926 result_type
4927 operator()(_UniformRandomNumberGenerator& __urng,
4928 const param_type& __p);
4929
4930 template<typename _ForwardIterator,
4931 typename _UniformRandomNumberGenerator>
4932 void
4933 __generate(_ForwardIterator __f, _ForwardIterator __t,
4934 _UniformRandomNumberGenerator& __urng)
4935 { this->__generate(__f, __t, __urng, _M_param); }
4936
4937 template<typename _ForwardIterator,
4938 typename _UniformRandomNumberGenerator>
4939 void
4940 __generate(_ForwardIterator __f, _ForwardIterator __t,
4941 _UniformRandomNumberGenerator& __urng,
4942 const param_type& __p)
4943 { this->__generate_impl(__f, __t, __urng, __p); }
4944
4945 template<typename _UniformRandomNumberGenerator>
4946 void
4947 __generate(result_type* __f, result_type* __t,
4948 _UniformRandomNumberGenerator& __urng,
4949 const param_type& __p)
4950 { this->__generate_impl(__f, __t, __urng, __p); }
4951
4952 /**
4953 * @brief Return true if two geometric distributions have
4954 * the same parameters.
4955 */
4956 friend bool
4957 operator==(const geometric_distribution& __d1,
4958 const geometric_distribution& __d2)
4959 { return __d1._M_param == __d2._M_param; }
4960
4961 private:
4962 template<typename _ForwardIterator,
4963 typename _UniformRandomNumberGenerator>
4964 void
4965 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4966 _UniformRandomNumberGenerator& __urng,
4967 const param_type& __p);
4968
4969 param_type _M_param;
4970 };
4971
4972#if __cpp_impl_three_way_comparison < 201907L
4973 /**
4974 * @brief Return true if two geometric distributions have
4975 * different parameters.
4976 */
4977 template<typename _IntType>
4978 inline bool
4979 operator!=(const std::geometric_distribution<_IntType>& __d1,
4981 { return !(__d1 == __d2); }
4982#endif
4983
4984 /**
4985 * @brief Inserts a %geometric_distribution random number distribution
4986 * @p __x into the output stream @p __os.
4987 *
4988 * @param __os An output stream.
4989 * @param __x A %geometric_distribution random number distribution.
4990 *
4991 * @returns The output stream with the state of @p __x inserted or in
4992 * an error state.
4993 */
4994 template<typename _IntType,
4995 typename _CharT, typename _Traits>
4996 std::basic_ostream<_CharT, _Traits>&
4997 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4998 const std::geometric_distribution<_IntType>& __x);
4999
5000 /**
5001 * @brief Extracts a %geometric_distribution random number distribution
5002 * @p __x from the input stream @p __is.
5003 *
5004 * @param __is An input stream.
5005 * @param __x A %geometric_distribution random number generator engine.
5006 *
5007 * @returns The input stream with @p __x extracted or in an error state.
5008 */
5009 template<typename _IntType,
5010 typename _CharT, typename _Traits>
5011 std::basic_istream<_CharT, _Traits>&
5012 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5013 std::geometric_distribution<_IntType>& __x);
5014
5015
5016 /**
5017 * @brief A negative_binomial_distribution random number distribution.
5018 *
5019 * The formula for the negative binomial probability mass function is
5020 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
5021 * and @f$p@f$ are the parameters of the distribution.
5022 *
5023 * @headerfile random
5024 * @since C++11
5025 */
5026 template<typename _IntType = int>
5027 class negative_binomial_distribution
5028 {
5030 "result_type must be an integral type");
5031
5032 public:
5033 /** The type of the range of the distribution. */
5034 typedef _IntType result_type;
5035
5036 /** Parameter type. */
5037 struct param_type
5038 {
5039 typedef negative_binomial_distribution<_IntType> distribution_type;
5040
5041 param_type() : param_type(1) { }
5042
5043 explicit
5044 param_type(_IntType __k, double __p = 0.5)
5045 : _M_k(__k), _M_p(__p)
5046 {
5047 __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
5048 }
5049
5050 _IntType
5051 k() const
5052 { return _M_k; }
5053
5054 double
5055 p() const
5056 { return _M_p; }
5057
5058 friend bool
5059 operator==(const param_type& __p1, const param_type& __p2)
5060 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
5061
5062#if __cpp_impl_three_way_comparison < 201907L
5063 friend bool
5064 operator!=(const param_type& __p1, const param_type& __p2)
5065 { return !(__p1 == __p2); }
5066#endif
5067
5068 private:
5069 _IntType _M_k;
5070 double _M_p;
5071 };
5072
5073 negative_binomial_distribution() : negative_binomial_distribution(1) { }
5074
5075 explicit
5076 negative_binomial_distribution(_IntType __k, double __p = 0.5)
5077 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
5078 { }
5079
5080 explicit
5081 negative_binomial_distribution(const param_type& __p)
5082 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
5083 { }
5084
5085 /**
5086 * @brief Resets the distribution state.
5087 */
5088 void
5090 { _M_gd.reset(); }
5091
5092 /**
5093 * @brief Return the @f$k@f$ parameter of the distribution.
5094 */
5095 _IntType
5096 k() const
5097 { return _M_param.k(); }
5098
5099 /**
5100 * @brief Return the @f$p@f$ parameter of the distribution.
5101 */
5102 double
5103 p() const
5104 { return _M_param.p(); }
5105
5106 /**
5107 * @brief Returns the parameter set of the distribution.
5108 */
5109 param_type
5110 param() const
5111 { return _M_param; }
5112
5113 /**
5114 * @brief Sets the parameter set of the distribution.
5115 * @param __param The new parameter set of the distribution.
5116 */
5117 void
5118 param(const param_type& __param)
5119 { _M_param = __param; }
5120
5121 /**
5122 * @brief Returns the greatest lower bound value of the distribution.
5123 */
5124 result_type
5125 min() const
5126 { return result_type(0); }
5127
5128 /**
5129 * @brief Returns the least upper bound value of the distribution.
5130 */
5131 result_type
5132 max() const
5134
5135 /**
5136 * @brief Generating functions.
5137 */
5138 template<typename _UniformRandomNumberGenerator>
5139 result_type
5140 operator()(_UniformRandomNumberGenerator& __urng);
5141
5142 template<typename _UniformRandomNumberGenerator>
5144 operator()(_UniformRandomNumberGenerator& __urng,
5145 const param_type& __p);
5146
5147 template<typename _ForwardIterator,
5148 typename _UniformRandomNumberGenerator>
5149 void
5150 __generate(_ForwardIterator __f, _ForwardIterator __t,
5151 _UniformRandomNumberGenerator& __urng)
5152 { this->__generate_impl(__f, __t, __urng); }
5153
5154 template<typename _ForwardIterator,
5155 typename _UniformRandomNumberGenerator>
5156 void
5157 __generate(_ForwardIterator __f, _ForwardIterator __t,
5158 _UniformRandomNumberGenerator& __urng,
5159 const param_type& __p)
5160 { this->__generate_impl(__f, __t, __urng, __p); }
5161
5162 template<typename _UniformRandomNumberGenerator>
5163 void
5164 __generate(result_type* __f, result_type* __t,
5165 _UniformRandomNumberGenerator& __urng)
5166 { this->__generate_impl(__f, __t, __urng); }
5167
5168 template<typename _UniformRandomNumberGenerator>
5169 void
5170 __generate(result_type* __f, result_type* __t,
5171 _UniformRandomNumberGenerator& __urng,
5172 const param_type& __p)
5173 { this->__generate_impl(__f, __t, __urng, __p); }
5174
5175 /**
5176 * @brief Return true if two negative binomial distributions have
5177 * the same parameters and the sequences that would be
5178 * generated are equal.
5179 */
5180 friend bool
5181 operator==(const negative_binomial_distribution& __d1,
5182 const negative_binomial_distribution& __d2)
5183 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
5184
5185 /**
5186 * @brief Inserts a %negative_binomial_distribution random
5187 * number distribution @p __x into the output stream @p __os.
5188 *
5189 * @param __os An output stream.
5190 * @param __x A %negative_binomial_distribution random number
5191 * distribution.
5192 *
5193 * @returns The output stream with the state of @p __x inserted or in
5194 * an error state.
5195 */
5196 template<typename _IntType1, typename _CharT, typename _Traits>
5200
5201 /**
5202 * @brief Extracts a %negative_binomial_distribution random number
5203 * distribution @p __x from the input stream @p __is.
5204 *
5205 * @param __is An input stream.
5206 * @param __x A %negative_binomial_distribution random number
5207 * generator engine.
5208 *
5209 * @returns The input stream with @p __x extracted or in an error state.
5210 */
5211 template<typename _IntType1, typename _CharT, typename _Traits>
5215
5216 private:
5217 template<typename _ForwardIterator,
5218 typename _UniformRandomNumberGenerator>
5219 void
5220 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5221 _UniformRandomNumberGenerator& __urng);
5222 template<typename _ForwardIterator,
5223 typename _UniformRandomNumberGenerator>
5224 void
5225 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5226 _UniformRandomNumberGenerator& __urng,
5227 const param_type& __p);
5228
5229 param_type _M_param;
5230
5232 };
5233
5234#if __cpp_impl_three_way_comparison < 201907L
5235 /**
5236 * @brief Return true if two negative binomial distributions are different.
5237 */
5238 template<typename _IntType>
5239 inline bool
5240 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
5242 { return !(__d1 == __d2); }
5243#endif
5244
5245 /// @} group random_distributions_bernoulli
5246
5247 /**
5248 * @addtogroup random_distributions_poisson Poisson Distributions
5249 * @ingroup random_distributions
5250 * @{
5251 */
5252
5253 /**
5254 * @brief A discrete Poisson random number distribution.
5255 *
5256 * The formula for the Poisson probability density function is
5257 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
5258 * parameter of the distribution.
5259 *
5260 * @headerfile random
5261 * @since C++11
5262 */
5263 template<typename _IntType = int>
5264 class poisson_distribution
5265 {
5267 "result_type must be an integral type");
5268
5269 public:
5270 /** The type of the range of the distribution. */
5271 typedef _IntType result_type;
5272
5273 /** Parameter type. */
5274 struct param_type
5275 {
5276 typedef poisson_distribution<_IntType> distribution_type;
5277 friend class poisson_distribution<_IntType>;
5278
5279 param_type() : param_type(1.0) { }
5280
5281 explicit
5282 param_type(double __mean)
5283 : _M_mean(__mean)
5284 {
5285 __glibcxx_assert(_M_mean > 0.0);
5286 _M_initialize();
5287 }
5288
5289 double
5290 mean() const
5291 { return _M_mean; }
5292
5293 friend bool
5294 operator==(const param_type& __p1, const param_type& __p2)
5295 { return __p1._M_mean == __p2._M_mean; }
5296
5297#if __cpp_impl_three_way_comparison < 201907L
5298 friend bool
5299 operator!=(const param_type& __p1, const param_type& __p2)
5300 { return !(__p1 == __p2); }
5301#endif
5302
5303 private:
5304 // Hosts either log(mean) or the threshold of the simple method.
5305 void
5306 _M_initialize();
5307
5308 double _M_mean;
5309
5310 double _M_lm_thr;
5311#if _GLIBCXX_USE_C99_MATH_FUNCS
5312 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
5313#endif
5314 };
5315
5316 // constructors and member functions
5317
5318 poisson_distribution() : poisson_distribution(1.0) { }
5319
5320 explicit
5321 poisson_distribution(double __mean)
5322 : _M_param(__mean), _M_nd()
5323 { }
5324
5325 explicit
5326 poisson_distribution(const param_type& __p)
5327 : _M_param(__p), _M_nd()
5328 { }
5329
5330 /**
5331 * @brief Resets the distribution state.
5332 */
5333 void
5335 { _M_nd.reset(); }
5336
5337 /**
5338 * @brief Returns the distribution parameter @p mean.
5339 */
5340 double
5341 mean() const
5342 { return _M_param.mean(); }
5343
5344 /**
5345 * @brief Returns the parameter set of the distribution.
5346 */
5347 param_type
5348 param() const
5349 { return _M_param; }
5350
5351 /**
5352 * @brief Sets the parameter set of the distribution.
5353 * @param __param The new parameter set of the distribution.
5354 */
5355 void
5356 param(const param_type& __param)
5357 { _M_param = __param; }
5358
5359 /**
5360 * @brief Returns the greatest lower bound value of the distribution.
5361 */
5362 result_type
5363 min() const
5364 { return 0; }
5365
5366 /**
5367 * @brief Returns the least upper bound value of the distribution.
5368 */
5369 result_type
5370 max() const
5372
5373 /**
5374 * @brief Generating functions.
5375 */
5376 template<typename _UniformRandomNumberGenerator>
5377 result_type
5378 operator()(_UniformRandomNumberGenerator& __urng)
5379 { return this->operator()(__urng, _M_param); }
5380
5381 template<typename _UniformRandomNumberGenerator>
5382 result_type
5383 operator()(_UniformRandomNumberGenerator& __urng,
5384 const param_type& __p);
5385
5386 template<typename _ForwardIterator,
5387 typename _UniformRandomNumberGenerator>
5388 void
5389 __generate(_ForwardIterator __f, _ForwardIterator __t,
5390 _UniformRandomNumberGenerator& __urng)
5391 { this->__generate(__f, __t, __urng, _M_param); }
5392
5393 template<typename _ForwardIterator,
5394 typename _UniformRandomNumberGenerator>
5395 void
5396 __generate(_ForwardIterator __f, _ForwardIterator __t,
5397 _UniformRandomNumberGenerator& __urng,
5398 const param_type& __p)
5399 { this->__generate_impl(__f, __t, __urng, __p); }
5400
5401 template<typename _UniformRandomNumberGenerator>
5402 void
5403 __generate(result_type* __f, result_type* __t,
5404 _UniformRandomNumberGenerator& __urng,
5405 const param_type& __p)
5406 { this->__generate_impl(__f, __t, __urng, __p); }
5407
5408 /**
5409 * @brief Return true if two Poisson distributions have the same
5410 * parameters and the sequences that would be generated
5411 * are equal.
5412 */
5413 friend bool
5414 operator==(const poisson_distribution& __d1,
5415 const poisson_distribution& __d2)
5416#ifdef _GLIBCXX_USE_C99_MATH_FUNCS
5417 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
5418#else
5419 { return __d1._M_param == __d2._M_param; }
5420#endif
5421
5422 /**
5423 * @brief Inserts a %poisson_distribution random number distribution
5424 * @p __x into the output stream @p __os.
5425 *
5426 * @param __os An output stream.
5427 * @param __x A %poisson_distribution random number distribution.
5428 *
5429 * @returns The output stream with the state of @p __x inserted or in
5430 * an error state.
5431 */
5432 template<typename _IntType1, typename _CharT, typename _Traits>
5436
5437 /**
5438 * @brief Extracts a %poisson_distribution random number distribution
5439 * @p __x from the input stream @p __is.
5440 *
5441 * @param __is An input stream.
5442 * @param __x A %poisson_distribution random number generator engine.
5443 *
5444 * @returns The input stream with @p __x extracted or in an error
5445 * state.
5446 */
5447 template<typename _IntType1, typename _CharT, typename _Traits>
5451
5452 private:
5453 template<typename _ForwardIterator,
5454 typename _UniformRandomNumberGenerator>
5455 void
5456 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5457 _UniformRandomNumberGenerator& __urng,
5458 const param_type& __p);
5459
5460 param_type _M_param;
5461
5462 // NB: Unused when _GLIBCXX_USE_C99_MATH_FUNCS is undefined.
5464 };
5465
5466#if __cpp_impl_three_way_comparison < 201907L
5467 /**
5468 * @brief Return true if two Poisson distributions are different.
5469 */
5470 template<typename _IntType>
5471 inline bool
5472 operator!=(const std::poisson_distribution<_IntType>& __d1,
5474 { return !(__d1 == __d2); }
5475#endif
5476
5477 /**
5478 * @brief An exponential continuous distribution for random numbers.
5479 *
5480 * The formula for the exponential probability density function is
5481 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
5482 *
5483 * <table border=1 cellpadding=10 cellspacing=0>
5484 * <caption align=top>Distribution Statistics</caption>
5485 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
5486 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
5487 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
5488 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
5489 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
5490 * </table>
5491 *
5492 * @headerfile random
5493 * @since C++11
5494 */
5495 template<typename _RealType = double>
5497 {
5499 "result_type must be a floating point type");
5500
5501 public:
5502 /** The type of the range of the distribution. */
5503 typedef _RealType result_type;
5504
5505 /** Parameter type. */
5506 struct param_type
5507 {
5508 typedef exponential_distribution<_RealType> distribution_type;
5509
5510 param_type() : param_type(1.0) { }
5511
5512 explicit
5513 param_type(_RealType __lambda)
5514 : _M_lambda(__lambda)
5515 {
5516 __glibcxx_assert(_M_lambda > _RealType(0));
5517 }
5518
5519 _RealType
5520 lambda() const
5521 { return _M_lambda; }
5522
5523 friend bool
5524 operator==(const param_type& __p1, const param_type& __p2)
5525 { return __p1._M_lambda == __p2._M_lambda; }
5526
5527#if __cpp_impl_three_way_comparison < 201907L
5528 friend bool
5529 operator!=(const param_type& __p1, const param_type& __p2)
5530 { return !(__p1 == __p2); }
5531#endif
5532
5533 private:
5534 _RealType _M_lambda;
5535 };
5536
5537 public:
5538 /**
5539 * @brief Constructs an exponential distribution with inverse scale
5540 * parameter 1.0
5541 */
5543
5544 /**
5545 * @brief Constructs an exponential distribution with inverse scale
5546 * parameter @f$\lambda@f$.
5547 */
5548 explicit
5549 exponential_distribution(_RealType __lambda)
5550 : _M_param(__lambda)
5551 { }
5552
5553 explicit
5554 exponential_distribution(const param_type& __p)
5555 : _M_param(__p)
5556 { }
5557
5558 /**
5559 * @brief Resets the distribution state.
5560 *
5561 * Has no effect on exponential distributions.
5562 */
5563 void
5564 reset() { }
5565
5566 /**
5567 * @brief Returns the inverse scale parameter of the distribution.
5568 */
5569 _RealType
5570 lambda() const
5571 { return _M_param.lambda(); }
5572
5573 /**
5574 * @brief Returns the parameter set of the distribution.
5575 */
5576 param_type
5577 param() const
5578 { return _M_param; }
5579
5580 /**
5581 * @brief Sets the parameter set of the distribution.
5582 * @param __param The new parameter set of the distribution.
5583 */
5584 void
5585 param(const param_type& __param)
5586 { _M_param = __param; }
5587
5588 /**
5589 * @brief Returns the greatest lower bound value of the distribution.
5590 */
5591 result_type
5592 min() const
5593 { return result_type(0); }
5594
5595 /**
5596 * @brief Returns the least upper bound value of the distribution.
5597 */
5598 result_type
5599 max() const
5601
5602 /**
5603 * @brief Generating functions.
5604 */
5605 template<typename _UniformRandomNumberGenerator>
5606 result_type
5607 operator()(_UniformRandomNumberGenerator& __urng)
5608 { return this->operator()(__urng, _M_param); }
5609
5610 template<typename _UniformRandomNumberGenerator>
5611 result_type
5612 operator()(_UniformRandomNumberGenerator& __urng,
5613 const param_type& __p)
5614 {
5615 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
5616 __aurng(__urng);
5617 return -std::log(result_type(1) - __aurng()) / __p.lambda();
5618 }
5619
5620 template<typename _ForwardIterator,
5621 typename _UniformRandomNumberGenerator>
5622 void
5623 __generate(_ForwardIterator __f, _ForwardIterator __t,
5624 _UniformRandomNumberGenerator& __urng)
5625 { this->__generate(__f, __t, __urng, _M_param); }
5626
5627 template<typename _ForwardIterator,
5628 typename _UniformRandomNumberGenerator>
5629 void
5630 __generate(_ForwardIterator __f, _ForwardIterator __t,
5631 _UniformRandomNumberGenerator& __urng,
5632 const param_type& __p)
5633 { this->__generate_impl(__f, __t, __urng, __p); }
5634
5635 template<typename _UniformRandomNumberGenerator>
5636 void
5637 __generate(result_type* __f, result_type* __t,
5638 _UniformRandomNumberGenerator& __urng,
5639 const param_type& __p)
5640 { this->__generate_impl(__f, __t, __urng, __p); }
5641
5642 /**
5643 * @brief Return true if two exponential distributions have the same
5644 * parameters.
5645 */
5646 friend bool
5648 const exponential_distribution& __d2)
5649 { return __d1._M_param == __d2._M_param; }
5650
5651 private:
5652 template<typename _ForwardIterator,
5653 typename _UniformRandomNumberGenerator>
5654 void
5655 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5656 _UniformRandomNumberGenerator& __urng,
5657 const param_type& __p);
5658
5659 param_type _M_param;
5660 };
5661
5662#if __cpp_impl_three_way_comparison < 201907L
5663 /**
5664 * @brief Return true if two exponential distributions have different
5665 * parameters.
5666 */
5667 template<typename _RealType>
5668 inline bool
5669 operator!=(const std::exponential_distribution<_RealType>& __d1,
5671 { return !(__d1 == __d2); }
5672#endif
5673
5674 /**
5675 * @brief Inserts a %exponential_distribution random number distribution
5676 * @p __x into the output stream @p __os.
5677 *
5678 * @param __os An output stream.
5679 * @param __x A %exponential_distribution random number distribution.
5680 *
5681 * @returns The output stream with the state of @p __x inserted or in
5682 * an error state.
5683 */
5684 template<typename _RealType, typename _CharT, typename _Traits>
5685 std::basic_ostream<_CharT, _Traits>&
5686 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5687 const std::exponential_distribution<_RealType>& __x);
5688
5689 /**
5690 * @brief Extracts a %exponential_distribution random number distribution
5691 * @p __x from the input stream @p __is.
5692 *
5693 * @param __is An input stream.
5694 * @param __x A %exponential_distribution random number
5695 * generator engine.
5696 *
5697 * @returns The input stream with @p __x extracted or in an error state.
5698 */
5699 template<typename _RealType, typename _CharT, typename _Traits>
5700 std::basic_istream<_CharT, _Traits>&
5701 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5702 std::exponential_distribution<_RealType>& __x);
5703
5704
5705 /**
5706 * @brief A weibull_distribution random number distribution.
5707 *
5708 * The formula for the normal probability density function is:
5709 * @f[
5710 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
5711 * \exp{(-(\frac{x}{\beta})^\alpha)}
5712 * @f]
5713 *
5714 * @headerfile random
5715 * @since C++11
5716 */
5717 template<typename _RealType = double>
5718 class weibull_distribution
5719 {
5721 "result_type must be a floating point type");
5722
5723 public:
5724 /** The type of the range of the distribution. */
5725 typedef _RealType result_type;
5726
5727 /** Parameter type. */
5728 struct param_type
5729 {
5730 typedef weibull_distribution<_RealType> distribution_type;
5731
5732 param_type() : param_type(1.0) { }
5733
5734 explicit
5735 param_type(_RealType __a, _RealType __b = _RealType(1.0))
5736 : _M_a(__a), _M_b(__b)
5737 { }
5738
5739 _RealType
5740 a() const
5741 { return _M_a; }
5742
5743 _RealType
5744 b() const
5745 { return _M_b; }
5746
5747 friend bool
5748 operator==(const param_type& __p1, const param_type& __p2)
5749 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5750
5751#if __cpp_impl_three_way_comparison < 201907L
5752 friend bool
5753 operator!=(const param_type& __p1, const param_type& __p2)
5754 { return !(__p1 == __p2); }
5755#endif
5756
5757 private:
5758 _RealType _M_a;
5759 _RealType _M_b;
5760 };
5761
5762 weibull_distribution() : weibull_distribution(1.0) { }
5763
5764 explicit
5765 weibull_distribution(_RealType __a, _RealType __b = _RealType(1))
5766 : _M_param(__a, __b)
5767 { }
5768
5769 explicit
5770 weibull_distribution(const param_type& __p)
5771 : _M_param(__p)
5772 { }
5773
5774 /**
5775 * @brief Resets the distribution state.
5776 */
5777 void
5779 { }
5780
5781 /**
5782 * @brief Return the @f$a@f$ parameter of the distribution.
5783 */
5784 _RealType
5785 a() const
5786 { return _M_param.a(); }
5787
5788 /**
5789 * @brief Return the @f$b@f$ parameter of the distribution.
5790 */
5791 _RealType
5792 b() const
5793 { return _M_param.b(); }
5794
5795 /**
5796 * @brief Returns the parameter set of the distribution.
5797 */
5798 param_type
5799 param() const
5800 { return _M_param; }
5801
5802 /**
5803 * @brief Sets the parameter set of the distribution.
5804 * @param __param The new parameter set of the distribution.
5805 */
5806 void
5807 param(const param_type& __param)
5808 { _M_param = __param; }
5809
5810 /**
5811 * @brief Returns the greatest lower bound value of the distribution.
5812 */
5813 result_type
5814 min() const
5815 { return result_type(0); }
5816
5817 /**
5818 * @brief Returns the least upper bound value of the distribution.
5819 */
5820 result_type
5821 max() const
5823
5824 /**
5825 * @brief Generating functions.
5826 */
5827 template<typename _UniformRandomNumberGenerator>
5828 result_type
5829 operator()(_UniformRandomNumberGenerator& __urng)
5830 { return this->operator()(__urng, _M_param); }
5831
5832 template<typename _UniformRandomNumberGenerator>
5833 result_type
5834 operator()(_UniformRandomNumberGenerator& __urng,
5835 const param_type& __p);
5836
5837 template<typename _ForwardIterator,
5838 typename _UniformRandomNumberGenerator>
5839 void
5840 __generate(_ForwardIterator __f, _ForwardIterator __t,
5841 _UniformRandomNumberGenerator& __urng)
5842 { this->__generate(__f, __t, __urng, _M_param); }
5843
5844 template<typename _ForwardIterator,
5845 typename _UniformRandomNumberGenerator>
5846 void
5847 __generate(_ForwardIterator __f, _ForwardIterator __t,
5848 _UniformRandomNumberGenerator& __urng,
5849 const param_type& __p)
5850 { this->__generate_impl(__f, __t, __urng, __p); }
5851
5852 template<typename _UniformRandomNumberGenerator>
5853 void
5854 __generate(result_type* __f, result_type* __t,
5855 _UniformRandomNumberGenerator& __urng,
5856 const param_type& __p)
5857 { this->__generate_impl(__f, __t, __urng, __p); }
5858
5859 /**
5860 * @brief Return true if two Weibull distributions have the same
5861 * parameters.
5862 */
5863 friend bool
5864 operator==(const weibull_distribution& __d1,
5865 const weibull_distribution& __d2)
5866 { return __d1._M_param == __d2._M_param; }
5867
5868 private:
5869 template<typename _ForwardIterator,
5870 typename _UniformRandomNumberGenerator>
5871 void
5872 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5873 _UniformRandomNumberGenerator& __urng,
5874 const param_type& __p);
5875
5876 param_type _M_param;
5877 };
5878
5879#if __cpp_impl_three_way_comparison < 201907L
5880 /**
5881 * @brief Return true if two Weibull distributions have different
5882 * parameters.
5883 */
5884 template<typename _RealType>
5885 inline bool
5886 operator!=(const std::weibull_distribution<_RealType>& __d1,
5888 { return !(__d1 == __d2); }
5889#endif
5890
5891 /**
5892 * @brief Inserts a %weibull_distribution random number distribution
5893 * @p __x into the output stream @p __os.
5894 *
5895 * @param __os An output stream.
5896 * @param __x A %weibull_distribution random number distribution.
5897 *
5898 * @returns The output stream with the state of @p __x inserted or in
5899 * an error state.
5900 */
5901 template<typename _RealType, typename _CharT, typename _Traits>
5902 std::basic_ostream<_CharT, _Traits>&
5903 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5904 const std::weibull_distribution<_RealType>& __x);
5905
5906 /**
5907 * @brief Extracts a %weibull_distribution random number distribution
5908 * @p __x from the input stream @p __is.
5909 *
5910 * @param __is An input stream.
5911 * @param __x A %weibull_distribution random number
5912 * generator engine.
5913 *
5914 * @returns The input stream with @p __x extracted or in an error state.
5915 */
5916 template<typename _RealType, typename _CharT, typename _Traits>
5917 std::basic_istream<_CharT, _Traits>&
5918 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5919 std::weibull_distribution<_RealType>& __x);
5920
5921
5922 /**
5923 * @brief A extreme_value_distribution random number distribution.
5924 *
5925 * The formula for the normal probability mass function is
5926 * @f[
5927 * p(x|a,b) = \frac{1}{b}
5928 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5929 * @f]
5930 *
5931 * @headerfile random
5932 * @since C++11
5933 */
5934 template<typename _RealType = double>
5935 class extreme_value_distribution
5936 {
5938 "result_type must be a floating point type");
5939
5940 public:
5941 /** The type of the range of the distribution. */
5942 typedef _RealType result_type;
5943
5944 /** Parameter type. */
5945 struct param_type
5946 {
5947 typedef extreme_value_distribution<_RealType> distribution_type;
5948
5949 param_type() : param_type(0.0) { }
5950
5951 explicit
5952 param_type(_RealType __a, _RealType __b = _RealType(1.0))
5953 : _M_a(__a), _M_b(__b)
5954 { }
5955
5956 _RealType
5957 a() const
5958 { return _M_a; }
5959
5960 _RealType
5961 b() const
5962 { return _M_b; }
5963
5964 friend bool
5965 operator==(const param_type& __p1, const param_type& __p2)
5966 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5967
5968#if __cpp_impl_three_way_comparison < 201907L
5969 friend bool
5970 operator!=(const param_type& __p1, const param_type& __p2)
5971 { return !(__p1 == __p2); }
5972#endif
5973
5974 private:
5975 _RealType _M_a;
5976 _RealType _M_b;
5977 };
5978
5979 extreme_value_distribution() : extreme_value_distribution(0.0) { }
5980
5981 explicit
5982 extreme_value_distribution(_RealType __a, _RealType __b = _RealType(1))
5983 : _M_param(__a, __b)
5984 { }
5985
5986 explicit
5987 extreme_value_distribution(const param_type& __p)
5988 : _M_param(__p)
5989 { }
5990
5991 /**
5992 * @brief Resets the distribution state.
5993 */
5994 void
5996 { }
5997
5998 /**
5999 * @brief Return the @f$a@f$ parameter of the distribution.
6000 */
6001 _RealType
6002 a() const
6003 { return _M_param.a(); }
6004
6005 /**
6006 * @brief Return the @f$b@f$ parameter of the distribution.
6007 */
6008 _RealType
6009 b() const
6010 { return _M_param.b(); }
6011
6012 /**
6013 * @brief Returns the parameter set of the distribution.
6014 */
6015 param_type
6016 param() const
6017 { return _M_param; }
6018
6019 /**
6020 * @brief Sets the parameter set of the distribution.
6021 * @param __param The new parameter set of the distribution.
6022 */
6023 void
6024 param(const param_type& __param)
6025 { _M_param = __param; }
6026
6027 /**
6028 * @brief Returns the greatest lower bound value of the distribution.
6029 */
6030 result_type
6033
6034 /**
6035 * @brief Returns the least upper bound value of the distribution.
6036 */
6037 result_type
6038 max() const
6040
6041 /**
6042 * @brief Generating functions.
6043 */
6044 template<typename _UniformRandomNumberGenerator>
6045 result_type
6046 operator()(_UniformRandomNumberGenerator& __urng)
6047 { return this->operator()(__urng, _M_param); }
6048
6049 template<typename _UniformRandomNumberGenerator>
6050 result_type
6051 operator()(_UniformRandomNumberGenerator& __urng,
6052 const param_type& __p);
6053
6054 template<typename _ForwardIterator,
6055 typename _UniformRandomNumberGenerator>
6056 void
6057 __generate(_ForwardIterator __f, _ForwardIterator __t,
6058 _UniformRandomNumberGenerator& __urng)
6059 { this->__generate(__f, __t, __urng, _M_param); }
6060
6061 template<typename _ForwardIterator,
6062 typename _UniformRandomNumberGenerator>
6063 void
6064 __generate(_ForwardIterator __f, _ForwardIterator __t,
6065 _UniformRandomNumberGenerator& __urng,
6066 const param_type& __p)
6067 { this->__generate_impl(__f, __t, __urng, __p); }
6068
6069 template<typename _UniformRandomNumberGenerator>
6070 void
6071 __generate(result_type* __f, result_type* __t,
6072 _UniformRandomNumberGenerator& __urng,
6073 const param_type& __p)
6074 { this->__generate_impl(__f, __t, __urng, __p); }
6075
6076 /**
6077 * @brief Return true if two extreme value distributions have the same
6078 * parameters.
6079 */
6080 friend bool
6081 operator==(const extreme_value_distribution& __d1,
6082 const extreme_value_distribution& __d2)
6083 { return __d1._M_param == __d2._M_param; }
6084
6085 private:
6086 template<typename _ForwardIterator,
6087 typename _UniformRandomNumberGenerator>
6088 void
6089 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6090 _UniformRandomNumberGenerator& __urng,
6091 const param_type& __p);
6092
6093 param_type _M_param;
6094 };
6095
6096#if __cpp_impl_three_way_comparison < 201907L
6097 /**
6098 * @brief Return true if two extreme value distributions have different
6099 * parameters.
6100 */
6101 template<typename _RealType>
6102 inline bool
6103 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
6105 { return !(__d1 == __d2); }
6106#endif
6107
6108 /**
6109 * @brief Inserts a %extreme_value_distribution random number distribution
6110 * @p __x into the output stream @p __os.
6111 *
6112 * @param __os An output stream.
6113 * @param __x A %extreme_value_distribution random number distribution.
6114 *
6115 * @returns The output stream with the state of @p __x inserted or in
6116 * an error state.
6117 */
6118 template<typename _RealType, typename _CharT, typename _Traits>
6119 std::basic_ostream<_CharT, _Traits>&
6120 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
6121 const std::extreme_value_distribution<_RealType>& __x);
6122
6123 /**
6124 * @brief Extracts a %extreme_value_distribution random number
6125 * distribution @p __x from the input stream @p __is.
6126 *
6127 * @param __is An input stream.
6128 * @param __x A %extreme_value_distribution random number
6129 * generator engine.
6130 *
6131 * @returns The input stream with @p __x extracted or in an error state.
6132 */
6133 template<typename _RealType, typename _CharT, typename _Traits>
6134 std::basic_istream<_CharT, _Traits>&
6135 operator>>(std::basic_istream<_CharT, _Traits>& __is,
6136 std::extreme_value_distribution<_RealType>& __x);
6137
6138 /// @} group random_distributions_poisson
6139
6140 /**
6141 * @addtogroup random_distributions_sampling Sampling Distributions
6142 * @ingroup random_distributions
6143 * @{
6144 */
6145
6146 /**
6147 * @brief A discrete_distribution random number distribution.
6148 *
6149 * This distribution produces random numbers @f$ i, 0 \leq i < n @f$,
6150 * distributed according to the probability mass function
6151 * @f$ p(i | p_0, ..., p_{n-1}) = p_i @f$.
6152 *
6153 * @headerfile random
6154 * @since C++11
6155 */
6156 template<typename _IntType = int>
6157 class discrete_distribution
6158 {
6160 "result_type must be an integral type");
6161
6162 public:
6163 /** The type of the range of the distribution. */
6164 typedef _IntType result_type;
6165
6166 /** Parameter type. */
6167 struct param_type
6168 {
6169 typedef discrete_distribution<_IntType> distribution_type;
6170 friend class discrete_distribution<_IntType>;
6171
6172 param_type()
6173 : _M_prob(), _M_cp()
6174 { }
6175
6176 template<typename _InputIterator>
6177 param_type(_InputIterator __wbegin,
6178 _InputIterator __wend)
6179 : _M_prob(__wbegin, __wend), _M_cp()
6180 { _M_initialize(); }
6181
6182 param_type(initializer_list<double> __wil)
6183 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
6184 { _M_initialize(); }
6185
6186 template<typename _Func>
6187 param_type(size_t __nw, double __xmin, double __xmax,
6188 _Func __fw);
6189
6190 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6191 param_type(const param_type&) = default;
6192 param_type& operator=(const param_type&) = default;
6193
6195 probabilities() const
6196 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
6197
6198 friend bool
6199 operator==(const param_type& __p1, const param_type& __p2)
6200 { return __p1._M_prob == __p2._M_prob; }
6201
6202#if __cpp_impl_three_way_comparison < 201907L
6203 friend bool
6204 operator!=(const param_type& __p1, const param_type& __p2)
6205 { return !(__p1 == __p2); }
6206#endif
6207
6208 private:
6209 void
6210 _M_initialize();
6211
6212 std::vector<double> _M_prob;
6213 std::vector<double> _M_cp;
6214 };
6215
6216 discrete_distribution()
6217 : _M_param()
6218 { }
6219
6220 template<typename _InputIterator>
6221 discrete_distribution(_InputIterator __wbegin,
6222 _InputIterator __wend)
6223 : _M_param(__wbegin, __wend)
6224 { }
6225
6226 discrete_distribution(initializer_list<double> __wl)
6227 : _M_param(__wl)
6228 { }
6229
6230 template<typename _Func>
6231 discrete_distribution(size_t __nw, double __xmin, double __xmax,
6232 _Func __fw)
6233 : _M_param(__nw, __xmin, __xmax, __fw)
6234 { }
6235
6236 explicit
6237 discrete_distribution(const param_type& __p)
6238 : _M_param(__p)
6239 { }
6240
6241 /**
6242 * @brief Resets the distribution state.
6243 */
6244 void
6246 { }
6247
6248 /**
6249 * @brief Returns the probabilities of the distribution.
6250 */
6253 {
6254 return _M_param._M_prob.empty()
6255 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
6256 }
6257
6258 /**
6259 * @brief Returns the parameter set of the distribution.
6260 */
6261 param_type
6262 param() const
6263 { return _M_param; }
6264
6265 /**
6266 * @brief Sets the parameter set of the distribution.
6267 * @param __param The new parameter set of the distribution.
6268 */
6269 void
6270 param(const param_type& __param)
6271 { _M_param = __param; }
6272
6273 /**
6274 * @brief Returns the greatest lower bound value of the distribution.
6275 */
6276 result_type
6277 min() const
6278 { return result_type(0); }
6279
6280 /**
6281 * @brief Returns the least upper bound value of the distribution.
6282 */
6283 result_type
6284 max() const
6285 {
6286 return _M_param._M_prob.empty()
6287 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
6288 }
6289
6290 /**
6291 * @brief Generating functions.
6292 */
6293 template<typename _UniformRandomNumberGenerator>
6294 result_type
6295 operator()(_UniformRandomNumberGenerator& __urng)
6296 { return this->operator()(__urng, _M_param); }
6297
6298 template<typename _UniformRandomNumberGenerator>
6299 result_type
6300 operator()(_UniformRandomNumberGenerator& __urng,
6301 const param_type& __p);
6302
6303 template<typename _ForwardIterator,
6304 typename _UniformRandomNumberGenerator>
6305 void
6306 __generate(_ForwardIterator __f, _ForwardIterator __t,
6307 _UniformRandomNumberGenerator& __urng)
6308 { this->__generate(__f, __t, __urng, _M_param); }
6309
6310 template<typename _ForwardIterator,
6311 typename _UniformRandomNumberGenerator>
6312 void
6313 __generate(_ForwardIterator __f, _ForwardIterator __t,
6314 _UniformRandomNumberGenerator& __urng,
6315 const param_type& __p)
6316 { this->__generate_impl(__f, __t, __urng, __p); }
6317
6318 template<typename _UniformRandomNumberGenerator>
6319 void
6320 __generate(result_type* __f, result_type* __t,
6321 _UniformRandomNumberGenerator& __urng,
6322 const param_type& __p)
6323 { this->__generate_impl(__f, __t, __urng, __p); }
6324
6325 /**
6326 * @brief Return true if two discrete distributions have the same
6327 * parameters.
6328 */
6329 friend bool
6330 operator==(const discrete_distribution& __d1,
6331 const discrete_distribution& __d2)
6332 { return __d1._M_param == __d2._M_param; }
6333
6334 /**
6335 * @brief Inserts a %discrete_distribution random number distribution
6336 * @p __x into the output stream @p __os.
6337 *
6338 * @param __os An output stream.
6339 * @param __x A %discrete_distribution random number distribution.
6340 *
6341 * @returns The output stream with the state of @p __x inserted or in
6342 * an error state.
6343 */
6344 template<typename _IntType1, typename _CharT, typename _Traits>
6348
6349 /**
6350 * @brief Extracts a %discrete_distribution random number distribution
6351 * @p __x from the input stream @p __is.
6352 *
6353 * @param __is An input stream.
6354 * @param __x A %discrete_distribution random number
6355 * generator engine.
6356 *
6357 * @returns The input stream with @p __x extracted or in an error
6358 * state.
6359 */
6360 template<typename _IntType1, typename _CharT, typename _Traits>
6364
6365 private:
6366 template<typename _ForwardIterator,
6367 typename _UniformRandomNumberGenerator>
6368 void
6369 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6370 _UniformRandomNumberGenerator& __urng,
6371 const param_type& __p);
6372
6373 param_type _M_param;
6374 };
6375
6376#if __cpp_impl_three_way_comparison < 201907L
6377 /**
6378 * @brief Return true if two discrete distributions have different
6379 * parameters.
6380 */
6381 template<typename _IntType>
6382 inline bool
6383 operator!=(const std::discrete_distribution<_IntType>& __d1,
6385 { return !(__d1 == __d2); }
6386#endif
6387
6388 /**
6389 * @brief A piecewise_constant_distribution random number distribution.
6390 *
6391 * This distribution produces random numbers @f$ x, b_0 \leq x < b_n @f$,
6392 * uniformly distributed over each subinterval @f$ [b_i, b_{i+1}) @f$
6393 * according to the probability mass function
6394 * @f[
6395 * p(x | b_0, ..., b_n, \rho_0, ..., \rho_{n-1})
6396 * = \rho_i \cdot \frac{b_{i+1} - x}{b_{i+1} - b_i}
6397 * + \rho_{i+1} \cdot \frac{ x - b_i}{b_{i+1} - b_i}
6398 * @f]
6399 * for @f$ b_i \leq x < b_{i+1} @f$.
6400 *
6401 * @headerfile random
6402 * @since C++11
6403 */
6404 template<typename _RealType = double>
6405 class piecewise_constant_distribution
6406 {
6408 "result_type must be a floating point type");
6409
6410 public:
6411 /** The type of the range of the distribution. */
6412 typedef _RealType result_type;
6413
6414 /** Parameter type. */
6415 struct param_type
6416 {
6417 typedef piecewise_constant_distribution<_RealType> distribution_type;
6418 friend class piecewise_constant_distribution<_RealType>;
6419
6420 param_type()
6421 : _M_int(), _M_den(), _M_cp()
6422 { }
6423
6424 template<typename _InputIteratorB, typename _InputIteratorW>
6425 param_type(_InputIteratorB __bfirst,
6426 _InputIteratorB __bend,
6427 _InputIteratorW __wbegin);
6428
6429 template<typename _Func>
6430 param_type(initializer_list<_RealType> __bi, _Func __fw);
6431
6432 template<typename _Func>
6433 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
6434 _Func __fw);
6435
6436 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6437 param_type(const param_type&) = default;
6438 param_type& operator=(const param_type&) = default;
6439
6441 intervals() const
6442 {
6443 if (_M_int.empty())
6444 {
6445 std::vector<_RealType> __tmp(2);
6446 __tmp[1] = _RealType(1);
6447 return __tmp;
6448 }
6449 else
6450 return _M_int;
6451 }
6452
6454 densities() const
6455 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
6456
6457 friend bool
6458 operator==(const param_type& __p1, const param_type& __p2)
6459 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
6460
6461#if __cpp_impl_three_way_comparison < 201907L
6462 friend bool
6463 operator!=(const param_type& __p1, const param_type& __p2)
6464 { return !(__p1 == __p2); }
6465#endif
6466
6467 private:
6468 void
6469 _M_initialize();
6470
6472 std::vector<double> _M_den;
6473 std::vector<double> _M_cp;
6474 };
6475
6476 piecewise_constant_distribution()
6477 : _M_param()
6478 { }
6479
6480 template<typename _InputIteratorB, typename _InputIteratorW>
6481 piecewise_constant_distribution(_InputIteratorB __bfirst,
6482 _InputIteratorB __bend,
6483 _InputIteratorW __wbegin)
6484 : _M_param(__bfirst, __bend, __wbegin)
6485 { }
6486
6487 template<typename _Func>
6488 piecewise_constant_distribution(initializer_list<_RealType> __bl,
6489 _Func __fw)
6490 : _M_param(__bl, __fw)
6491 { }
6492
6493 template<typename _Func>
6494 piecewise_constant_distribution(size_t __nw,
6495 _RealType __xmin, _RealType __xmax,
6496 _Func __fw)
6497 : _M_param(__nw, __xmin, __xmax, __fw)
6498 { }
6499
6500 explicit
6501 piecewise_constant_distribution(const param_type& __p)
6502 : _M_param(__p)
6503 { }
6504
6505 /**
6506 * @brief Resets the distribution state.
6507 */
6508 void
6510 { }
6511
6512 /**
6513 * @brief Returns a vector of the intervals.
6514 */
6517 {
6518 if (_M_param._M_int.empty())
6519 {
6520 std::vector<_RealType> __tmp(2);
6521 __tmp[1] = _RealType(1);
6522 return __tmp;
6523 }
6524 else
6525 return _M_param._M_int;
6526 }
6527
6528 /**
6529 * @brief Returns a vector of the probability densities.
6530 */
6533 {
6534 return _M_param._M_den.empty()
6535 ? std::vector<double>(1, 1.0) : _M_param._M_den;
6536 }
6537
6538 /**
6539 * @brief Returns the parameter set of the distribution.
6540 */
6541 param_type
6542 param() const
6543 { return _M_param; }
6544
6545 /**
6546 * @brief Sets the parameter set of the distribution.
6547 * @param __param The new parameter set of the distribution.
6548 */
6549 void
6550 param(const param_type& __param)
6551 { _M_param = __param; }
6552
6553 /**
6554 * @brief Returns the greatest lower bound value of the distribution.
6555 */
6556 result_type
6557 min() const
6558 {
6559 return _M_param._M_int.empty()
6560 ? result_type(0) : _M_param._M_int.front();
6561 }
6562
6563 /**
6564 * @brief Returns the least upper bound value of the distribution.
6565 */
6566 result_type
6567 max() const
6568 {
6569 return _M_param._M_int.empty()
6570 ? result_type(1) : _M_param._M_int.back();
6571 }
6572
6573 /**
6574 * @brief Generating functions.
6575 */
6576 template<typename _UniformRandomNumberGenerator>
6577 result_type
6578 operator()(_UniformRandomNumberGenerator& __urng)
6579 { return this->operator()(__urng, _M_param); }
6580
6581 template<typename _UniformRandomNumberGenerator>
6582 result_type
6583 operator()(_UniformRandomNumberGenerator& __urng,
6584 const param_type& __p);
6585
6586 template<typename _ForwardIterator,
6587 typename _UniformRandomNumberGenerator>
6588 void
6589 __generate(_ForwardIterator __f, _ForwardIterator __t,
6590 _UniformRandomNumberGenerator& __urng)
6591 { this->__generate(__f, __t, __urng, _M_param); }
6592
6593 template<typename _ForwardIterator,
6594 typename _UniformRandomNumberGenerator>
6595 void
6596 __generate(_ForwardIterator __f, _ForwardIterator __t,
6597 _UniformRandomNumberGenerator& __urng,
6598 const param_type& __p)
6599 { this->__generate_impl(__f, __t, __urng, __p); }
6600
6601 template<typename _UniformRandomNumberGenerator>
6602 void
6603 __generate(result_type* __f, result_type* __t,
6604 _UniformRandomNumberGenerator& __urng,
6605 const param_type& __p)
6606 { this->__generate_impl(__f, __t, __urng, __p); }
6607
6608 /**
6609 * @brief Return true if two piecewise constant distributions have the
6610 * same parameters.
6611 */
6612 friend bool
6613 operator==(const piecewise_constant_distribution& __d1,
6614 const piecewise_constant_distribution& __d2)
6615 { return __d1._M_param == __d2._M_param; }
6616
6617 /**
6618 * @brief Inserts a %piecewise_constant_distribution random
6619 * number distribution @p __x into the output stream @p __os.
6620 *
6621 * @param __os An output stream.
6622 * @param __x A %piecewise_constant_distribution random number
6623 * distribution.
6624 *
6625 * @returns The output stream with the state of @p __x inserted or in
6626 * an error state.
6627 */
6628 template<typename _RealType1, typename _CharT, typename _Traits>
6632
6633 /**
6634 * @brief Extracts a %piecewise_constant_distribution random
6635 * number distribution @p __x from the input stream @p __is.
6636 *
6637 * @param __is An input stream.
6638 * @param __x A %piecewise_constant_distribution random number
6639 * generator engine.
6640 *
6641 * @returns The input stream with @p __x extracted or in an error
6642 * state.
6643 */
6644 template<typename _RealType1, typename _CharT, typename _Traits>
6648
6649 private:
6650 template<typename _ForwardIterator,
6651 typename _UniformRandomNumberGenerator>
6652 void
6653 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6654 _UniformRandomNumberGenerator& __urng,
6655 const param_type& __p);
6656
6657 param_type _M_param;
6658 };
6659
6660#if __cpp_impl_three_way_comparison < 201907L
6661 /**
6662 * @brief Return true if two piecewise constant distributions have
6663 * different parameters.
6664 */
6665 template<typename _RealType>
6666 inline bool
6669 { return !(__d1 == __d2); }
6670#endif
6671
6672 /**
6673 * @brief A piecewise_linear_distribution random number distribution.
6674 *
6675 * This distribution produces random numbers @f$ x, b_0 \leq x < b_n @f$,
6676 * distributed over each subinterval @f$ [b_i, b_{i+1}) @f$
6677 * according to the probability mass function
6678 * @f$ p(x | b_0, ..., b_n, \rho_0, ..., \rho_n) = \rho_i @f$,
6679 * for @f$ b_i \leq x < b_{i+1} @f$.
6680 *
6681 * @headerfile random
6682 * @since C++11
6683 */
6684 template<typename _RealType = double>
6685 class piecewise_linear_distribution
6686 {
6688 "result_type must be a floating point type");
6689
6690 public:
6691 /** The type of the range of the distribution. */
6692 typedef _RealType result_type;
6693
6694 /** Parameter type. */
6695 struct param_type
6696 {
6697 typedef piecewise_linear_distribution<_RealType> distribution_type;
6698 friend class piecewise_linear_distribution<_RealType>;
6699
6700 param_type()
6701 : _M_int(), _M_den(), _M_cp(), _M_m()
6702 { }
6703
6704 template<typename _InputIteratorB, typename _InputIteratorW>
6705 param_type(_InputIteratorB __bfirst,
6706 _InputIteratorB __bend,
6707 _InputIteratorW __wbegin);
6708
6709 template<typename _Func>
6710 param_type(initializer_list<_RealType> __bl, _Func __fw);
6711
6712 template<typename _Func>
6713 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
6714 _Func __fw);
6715
6716 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
6717 param_type(const param_type&) = default;
6718 param_type& operator=(const param_type&) = default;
6719
6721 intervals() const
6722 {
6723 if (_M_int.empty())
6724 {
6725 std::vector<_RealType> __tmp(2);
6726 __tmp[1] = _RealType(1);
6727 return __tmp;
6728 }
6729 else
6730 return _M_int;
6731 }
6732
6734 densities() const
6735 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
6736
6737 friend bool
6738 operator==(const param_type& __p1, const param_type& __p2)
6739 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
6740
6741#if __cpp_impl_three_way_comparison < 201907L
6742 friend bool
6743 operator!=(const param_type& __p1, const param_type& __p2)
6744 { return !(__p1 == __p2); }
6745#endif
6746
6747 private:
6748 void
6749 _M_initialize();
6750
6752 std::vector<double> _M_den;
6753 std::vector<double> _M_cp;
6755 };
6756
6757 piecewise_linear_distribution()
6758 : _M_param()
6759 { }
6760
6761 template<typename _InputIteratorB, typename _InputIteratorW>
6762 piecewise_linear_distribution(_InputIteratorB __bfirst,
6763 _InputIteratorB __bend,
6764 _InputIteratorW __wbegin)
6765 : _M_param(__bfirst, __bend, __wbegin)
6766 { }
6767
6768 template<typename _Func>
6769 piecewise_linear_distribution(initializer_list<_RealType> __bl,
6770 _Func __fw)
6771 : _M_param(__bl, __fw)
6772 { }
6773
6774 template<typename _Func>
6775 piecewise_linear_distribution(size_t __nw,
6776 _RealType __xmin, _RealType __xmax,
6777 _Func __fw)
6778 : _M_param(__nw, __xmin, __xmax, __fw)
6779 { }
6780
6781 explicit
6782 piecewise_linear_distribution(const param_type& __p)
6783 : _M_param(__p)
6784 { }
6785
6786 /**
6787 * Resets the distribution state.
6788 */
6789 void
6791 { }
6792
6793 /**
6794 * @brief Return the intervals of the distribution.
6795 */
6798 {
6799 if (_M_param._M_int.empty())
6800 {
6801 std::vector<_RealType> __tmp(2);
6802 __tmp[1] = _RealType(1);
6803 return __tmp;
6804 }
6805 else
6806 return _M_param._M_int;
6807 }
6808
6809 /**
6810 * @brief Return a vector of the probability densities of the
6811 * distribution.
6812 */
6815 {
6816 return _M_param._M_den.empty()
6817 ? std::vector<double>(2, 1.0) : _M_param._M_den;
6818 }
6819
6820 /**
6821 * @brief Returns the parameter set of the distribution.
6822 */
6823 param_type
6824 param() const
6825 { return _M_param; }
6826
6827 /**
6828 * @brief Sets the parameter set of the distribution.
6829 * @param __param The new parameter set of the distribution.
6830 */
6831 void
6832 param(const param_type& __param)
6833 { _M_param = __param; }
6834
6835 /**
6836 * @brief Returns the greatest lower bound value of the distribution.
6837 */
6838 result_type
6839 min() const
6840 {
6841 return _M_param._M_int.empty()
6842 ? result_type(0) : _M_param._M_int.front();
6843 }
6844
6845 /**
6846 * @brief Returns the least upper bound value of the distribution.
6847 */
6848 result_type
6849 max() const
6850 {
6851 return _M_param._M_int.empty()
6852 ? result_type(1) : _M_param._M_int.back();
6853 }
6854
6855 /**
6856 * @brief Generating functions.
6857 */
6858 template<typename _UniformRandomNumberGenerator>
6859 result_type
6860 operator()(_UniformRandomNumberGenerator& __urng)
6861 { return this->operator()(__urng, _M_param); }
6862
6863 template<typename _UniformRandomNumberGenerator>
6864 result_type
6865 operator()(_UniformRandomNumberGenerator& __urng,
6866 const param_type& __p);
6867
6868 template<typename _ForwardIterator,
6869 typename _UniformRandomNumberGenerator>
6870 void
6871 __generate(_ForwardIterator __f, _ForwardIterator __t,
6872 _UniformRandomNumberGenerator& __urng)
6873 { this->__generate(__f, __t, __urng, _M_param); }
6874
6875 template<typename _ForwardIterator,
6876 typename _UniformRandomNumberGenerator>
6877 void
6878 __generate(_ForwardIterator __f, _ForwardIterator __t,
6879 _UniformRandomNumberGenerator& __urng,
6880 const param_type& __p)
6881 { this->__generate_impl(__f, __t, __urng, __p); }
6882
6883 template<typename _UniformRandomNumberGenerator>
6884 void
6885 __generate(result_type* __f, result_type* __t,
6886 _UniformRandomNumberGenerator& __urng,
6887 const param_type& __p)
6888 { this->__generate_impl(__f, __t, __urng, __p); }
6889
6890 /**
6891 * @brief Return true if two piecewise linear distributions have the
6892 * same parameters.
6893 */
6894 friend bool
6895 operator==(const piecewise_linear_distribution& __d1,
6896 const piecewise_linear_distribution& __d2)
6897 { return __d1._M_param == __d2._M_param; }
6898
6899 /**
6900 * @brief Inserts a %piecewise_linear_distribution random number
6901 * distribution @p __x into the output stream @p __os.
6902 *
6903 * @param __os An output stream.
6904 * @param __x A %piecewise_linear_distribution random number
6905 * distribution.
6906 *
6907 * @returns The output stream with the state of @p __x inserted or in
6908 * an error state.
6909 */
6910 template<typename _RealType1, typename _CharT, typename _Traits>
6914
6915 /**
6916 * @brief Extracts a %piecewise_linear_distribution random number
6917 * distribution @p __x from the input stream @p __is.
6918 *
6919 * @param __is An input stream.
6920 * @param __x A %piecewise_linear_distribution random number
6921 * generator engine.
6922 *
6923 * @returns The input stream with @p __x extracted or in an error
6924 * state.
6925 */
6926 template<typename _RealType1, typename _CharT, typename _Traits>
6930
6931 private:
6932 template<typename _ForwardIterator,
6933 typename _UniformRandomNumberGenerator>
6934 void
6935 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
6936 _UniformRandomNumberGenerator& __urng,
6937 const param_type& __p);
6938
6939 param_type _M_param;
6940 };
6941
6942#if __cpp_impl_three_way_comparison < 201907L
6943 /**
6944 * @brief Return true if two piecewise linear distributions have
6945 * different parameters.
6946 */
6947 template<typename _RealType>
6948 inline bool
6949 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
6951 { return !(__d1 == __d2); }
6952#endif
6953
6954 /// @} group random_distributions_sampling
6955
6956 /// @} *group random_distributions
6957
6958 /**
6959 * @addtogroup random_utilities Random Number Utilities
6960 * @ingroup random
6961 * @{
6962 */
6963
6964 /**
6965 * @brief The seed_seq class generates sequences of seeds for random
6966 * number generators.
6967 *
6968 * @headerfile random
6969 * @since C++11
6970 */
6972 {
6973 public:
6974 /** The type of the seed vales. */
6975 typedef uint_least32_t result_type;
6976
6977 /** Default constructor. */
6978 seed_seq() noexcept
6979 : _M_v()
6980 { }
6981
6982 template<typename _IntType, typename = _Require<is_integral<_IntType>>>
6984
6985 template<typename _InputIterator>
6986 seed_seq(_InputIterator __begin, _InputIterator __end);
6987
6988 // generating functions
6989 template<typename _RandomAccessIterator>
6990 void
6991 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
6992
6993 // property functions
6994 size_t size() const noexcept
6995 { return _M_v.size(); }
6996
6997 template<typename _OutputIterator>
6998 void
6999 param(_OutputIterator __dest) const
7000 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
7001
7002 // no copy functions
7003 seed_seq(const seed_seq&) = delete;
7004 seed_seq& operator=(const seed_seq&) = delete;
7005
7006 private:
7007 std::vector<result_type> _M_v;
7008 };
7009
7010 /// @} group random_utilities
7011
7012 /// @} group random
7013
7014_GLIBCXX_END_NAMESPACE_VERSION
7015} // namespace std
7016
7017#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:1162
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:1135
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:1271
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2681
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
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
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:1624
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1644
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1740
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1614
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1604
Implementation details not part of the namespace std interface.
initializer_list
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:1029
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 ...
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:3527
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:3578
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3512
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:3519
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:3654
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3746
friend bool operator==(const cauchy_distribution &__d1, const cauchy_distribution &__d2)
Return true if two Cauchy distributions have the same parameters.
Definition random.h:3796
void reset()
Resets the distribution state.
Definition random.h:3713
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3731
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3761
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3753
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3739
A fisher_f_distribution random number distribution.
Definition random.h:3869
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:3958
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:3972
void reset()
Resets the distribution state.
Definition random.h:3929
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:3950
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:4028
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:3965
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:3980
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:4108
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4187
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4201
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4194
void reset()
Resets the distribution state.
Definition random.h:4162
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:4258
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4209
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:4179
A Bernoulli random number distribution.
Definition random.h:4341
void reset()
Resets the distribution state.
Definition random.h:4406
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4441
friend bool operator==(const bernoulli_distribution &__d1, const bernoulli_distribution &__d2)
Return true if two Bernoulli distributions have the same parameters.
Definition random.h:4491
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4419
bernoulli_distribution()
Constructs a Bernoulli distribution with likelihood 0.5.
Definition random.h:4382
bernoulli_distribution(double __p)
Constructs a Bernoulli distribution with likelihood p.
Definition random.h:4391
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4434
double p() const
Returns the p parameter of the distribution.
Definition random.h:4412
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4427
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4449
A discrete binomial random number distribution.
Definition random.h:4565
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4678
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4685
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4671
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4693
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:4729
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4663
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:4649
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:4642
double p() const
Returns the distribution p parameter.
Definition random.h:4656
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
A discrete geometric random number distribution.
Definition random.h:4811
double p() const
Returns the distribution parameter p.
Definition random.h:4885
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:4922
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:4914
friend bool operator==(const geometric_distribution &__d1, const geometric_distribution &__d2)
Return true if two geometric distributions have the same parameters.
Definition random.h:4957
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:4892
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:4900
void reset()
Resets the distribution state.
Definition random.h:4879
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:4907
A negative_binomial_distribution random number distribution.
Definition random.h:5028
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:5118
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5125
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5132
double p() const
Return the parameter of the distribution.
Definition random.h:5103
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:5181
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5110
_IntType k() const
Return the parameter of the distribution.
Definition random.h:5096
void reset()
Resets the distribution state.
Definition random.h:5089
A discrete Poisson random number distribution.
Definition random.h:5265
result_type operator()(_UniformRandomNumberGenerator &__urng, const param_type &__p)
void reset()
Resets the distribution state.
Definition random.h:5334
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5378
double mean() const
Returns the distribution parameter mean.
Definition random.h:5341
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:5414
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5370
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5356
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:5348
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:5363
An exponential continuous distribution for random numbers.
Definition random.h:5497
_RealType lambda() const
Returns the inverse scale parameter of the distribution.
Definition random.h:5570
exponential_distribution()
Constructs an exponential distribution with inverse scale parameter 1.0.
Definition random.h:5542
exponential_distribution(_RealType __lambda)
Constructs an exponential distribution with inverse scale parameter .
Definition random.h:5549
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5607
void reset()
Resets the distribution state.
Definition random.h:5564
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5592
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5577
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5599
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5585
friend bool operator==(const exponential_distribution &__d1, const exponential_distribution &__d2)
Return true if two exponential distributions have the same parameters.
Definition random.h:5647
A weibull_distribution random number distribution.
Definition random.h:5719
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:5799
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:5814
void reset()
Resets the distribution state.
Definition random.h:5778
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:5829
friend bool operator==(const weibull_distribution &__d1, const weibull_distribution &__d2)
Return true if two Weibull distributions have the same parameters.
Definition random.h:5864
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:5807
_RealType b() const
Return the parameter of the distribution.
Definition random.h:5792
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:5821
_RealType a() const
Return the parameter of the distribution.
Definition random.h:5785
A extreme_value_distribution random number distribution.
Definition random.h:5936
void reset()
Resets the distribution state.
Definition random.h:5995
_RealType b() const
Return the parameter of the distribution.
Definition random.h:6009
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6046
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6024
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6031
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6038
_RealType a() const
Return the parameter of the distribution.
Definition random.h:6002
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:6081
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6016
A discrete_distribution random number distribution.
Definition random.h:6158
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:6277
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:6284
void reset()
Resets the distribution state.
Definition random.h:6245
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6262
friend bool operator==(const discrete_distribution &__d1, const discrete_distribution &__d2)
Return true if two discrete distributions have the same parameters.
Definition random.h:6330
std::vector< double > probabilities() const
Returns the probabilities of the distribution.
Definition random.h:6252
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6295
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6270
A piecewise_constant_distribution random number distribution.
Definition random.h:6406
std::vector< double > densities() const
Returns a vector of the probability densities.
Definition random.h:6532
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6550
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6557
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6567
void reset()
Resets the distribution state.
Definition random.h:6509
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:6542
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:6613
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6578
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:6516
A piecewise_linear_distribution random number distribution.
Definition random.h:6686
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition random.h:6860
result_type max() const
Returns the least upper bound value of the distribution.
Definition random.h:6849
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:6797
param_type param() const
Returns the parameter set of the distribution.
Definition random.h:6824
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:6895
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition random.h:6832
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition random.h:6839
std::vector< double > densities() const
Return a vector of the probability densities of the distribution.
Definition random.h:6814
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:6978
uint_least32_t result_type
Definition random.h:6975
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