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