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