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