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