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