1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2015 Free Software Foundation, Inc.
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)
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.
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.
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/>.
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
35 #include <bits/uniform_int_dist.h>
37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 // [26.4] Random number generation
44 * @defgroup random Random Number Generation
47 * A facility for generating random numbers on selected distributions.
52 * @brief A function template for converting the output of a (integral)
53 * uniform random number generator to a floatng point result in the range
56 template<typename _RealType, size_t __bits,
57 typename _UniformRandomNumberGenerator>
59 generate_canonical(_UniformRandomNumberGenerator& __g);
61 _GLIBCXX_END_NAMESPACE_VERSION
64 * Implementation-space details.
68 _GLIBCXX_BEGIN_NAMESPACE_VERSION
70 template<typename _UIntType, size_t __w,
71 bool = __w < static_cast<size_t>
72 (std::numeric_limits<_UIntType>::digits)>
74 { static const _UIntType __value = 0; };
76 template<typename _UIntType, size_t __w>
77 struct _Shift<_UIntType, __w, true>
78 { static const _UIntType __value = _UIntType(1) << __w; };
81 int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
82 + (__s <= __CHAR_BIT__ * sizeof (long))
83 + (__s <= __CHAR_BIT__ * sizeof (long long))
84 /* assume long long no bigger than __int128 */
86 struct _Select_uint_least_t
88 static_assert(__which < 0, /* needs to be dependent */
89 "sorry, would be too much trouble for a slow result");
93 struct _Select_uint_least_t<__s, 4>
94 { typedef unsigned int type; };
97 struct _Select_uint_least_t<__s, 3>
98 { typedef unsigned long type; };
101 struct _Select_uint_least_t<__s, 2>
102 { typedef unsigned long long type; };
104 #ifdef _GLIBCXX_USE_INT128
106 struct _Select_uint_least_t<__s, 1>
107 { typedef unsigned __int128 type; };
110 // Assume a != 0, a < m, c < m, x < m.
111 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
112 bool __big_enough = (!(__m & (__m - 1))
113 || (_Tp(-1) - __c) / __a >= __m - 1),
114 bool __schrage_ok = __m % __a < __m / __a>
117 typedef typename _Select_uint_least_t<std::__lg(__a)
118 + std::__lg(__m) + 2>::type _Tp2;
121 { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); }
125 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
126 struct _Mod<_Tp, __m, __a, __c, false, true>
133 // - for m == 2^n or m == 0, unsigned integer overflow is safe.
134 // - a * (m - 1) + c fits in _Tp, there is no overflow.
135 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
136 struct _Mod<_Tp, __m, __a, __c, true, __s>
141 _Tp __res = __a * __x + __c;
148 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
151 { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
154 * An adaptor class for converting the output of any Generator into
155 * the input for a specific Distribution.
157 template<typename _Engine, typename _DInputType>
160 static_assert(std::is_floating_point<_DInputType>::value,
161 "template argument not a floating point type");
164 _Adaptor(_Engine& __g)
169 { return _DInputType(0); }
173 { return _DInputType(1); }
176 * Converts a value generated by the adapted random number generator
177 * into a value in the input domain for the dependent random number
183 return std::generate_canonical<_DInputType,
184 std::numeric_limits<_DInputType>::digits,
192 _GLIBCXX_END_NAMESPACE_VERSION
193 } // namespace __detail
195 _GLIBCXX_BEGIN_NAMESPACE_VERSION
198 * @addtogroup random_generators Random Number Generators
201 * These classes define objects which provide random or pseudorandom
202 * numbers, either from a discrete or a continuous interval. The
203 * random number generator supplied as a part of this library are
204 * all uniform random number generators which provide a sequence of
205 * random number uniformly distributed over their range.
207 * A number generator is a function object with an operator() that
208 * takes zero arguments and returns a number.
210 * A compliant random number generator must satisfy the following
211 * requirements. <table border=1 cellpadding=10 cellspacing=0>
212 * <caption align=top>Random Number Generator Requirements</caption>
213 * <tr><td>To be documented.</td></tr> </table>
219 * @brief A model of a linear congruential random number generator.
221 * A random number generator that produces pseudorandom numbers via
224 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
227 * The template parameter @p _UIntType must be an unsigned integral type
228 * large enough to store values up to (__m-1). If the template parameter
229 * @p __m is 0, the modulus @p __m used is
230 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
231 * parameters @p __a and @p __c must be less than @p __m.
233 * The size of the state is @f$1@f$.
235 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
236 class linear_congruential_engine
238 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
239 "substituting _UIntType not an unsigned integral type");
240 static_assert(__m == 0u || (__a < __m && __c < __m),
241 "template argument substituting __m out of bounds");
244 /** The type of the generated random value. */
245 typedef _UIntType result_type;
247 /** The multiplier. */
248 static constexpr result_type multiplier = __a;
250 static constexpr result_type increment = __c;
252 static constexpr result_type modulus = __m;
253 static constexpr result_type default_seed = 1u;
256 * @brief Constructs a %linear_congruential_engine random number
257 * generator engine with seed @p __s. The default seed value
260 * @param __s The initial seed value.
263 linear_congruential_engine(result_type __s = default_seed)
267 * @brief Constructs a %linear_congruential_engine random number
268 * generator engine seeded from the seed sequence @p __q.
270 * @param __q the seed sequence.
272 template<typename _Sseq, typename = typename
273 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
276 linear_congruential_engine(_Sseq& __q)
280 * @brief Reseeds the %linear_congruential_engine random number generator
281 * engine sequence to the seed @p __s.
283 * @param __s The new seed.
286 seed(result_type __s = default_seed);
289 * @brief Reseeds the %linear_congruential_engine random number generator
291 * sequence using values from the seed sequence @p __q.
293 * @param __q the seed sequence.
295 template<typename _Sseq>
296 typename std::enable_if<std::is_class<_Sseq>::value>::type
300 * @brief Gets the smallest possible value in the output range.
302 * The minimum depends on the @p __c parameter: if it is zero, the
303 * minimum generated must be > 0, otherwise 0 is allowed.
305 static constexpr result_type
307 { return __c == 0u ? 1u : 0u; }
310 * @brief Gets the largest possible value in the output range.
312 static constexpr result_type
317 * @brief Discard a sequence of random numbers.
320 discard(unsigned long long __z)
322 for (; __z != 0ULL; --__z)
327 * @brief Gets the next random number in the sequence.
332 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
337 * @brief Compares two linear congruential random number generator
338 * objects of the same type for equality.
340 * @param __lhs A linear congruential random number generator object.
341 * @param __rhs Another linear congruential random number generator
344 * @returns true if the infinite sequences of generated values
345 * would be equal, false otherwise.
348 operator==(const linear_congruential_engine& __lhs,
349 const linear_congruential_engine& __rhs)
350 { return __lhs._M_x == __rhs._M_x; }
353 * @brief Writes the textual representation of the state x(i) of x to
356 * @param __os The output stream.
357 * @param __lcr A % linear_congruential_engine random number generator.
360 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
361 _UIntType1 __m1, typename _CharT, typename _Traits>
362 friend std::basic_ostream<_CharT, _Traits>&
363 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
364 const std::linear_congruential_engine<_UIntType1,
365 __a1, __c1, __m1>& __lcr);
368 * @brief Sets the state of the engine by reading its textual
369 * representation from @p __is.
371 * The textual representation must have been previously written using
372 * an output stream whose imbued locale and whose type's template
373 * specialization arguments _CharT and _Traits were the same as those
376 * @param __is The input stream.
377 * @param __lcr A % linear_congruential_engine random number generator.
380 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
381 _UIntType1 __m1, typename _CharT, typename _Traits>
382 friend std::basic_istream<_CharT, _Traits>&
383 operator>>(std::basic_istream<_CharT, _Traits>& __is,
384 std::linear_congruential_engine<_UIntType1, __a1,
392 * @brief Compares two linear congruential random number generator
393 * objects of the same type for inequality.
395 * @param __lhs A linear congruential random number generator object.
396 * @param __rhs Another linear congruential random number generator
399 * @returns true if the infinite sequences of generated values
400 * would be different, false otherwise.
402 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
404 operator!=(const std::linear_congruential_engine<_UIntType, __a,
406 const std::linear_congruential_engine<_UIntType, __a,
408 { return !(__lhs == __rhs); }
412 * A generalized feedback shift register discrete random number generator.
414 * This algorithm avoids multiplication and division and is designed to be
415 * friendly to a pipelined architecture. If the parameters are chosen
416 * correctly, this generator will produce numbers with a very long period and
417 * fairly good apparent entropy, although still not cryptographically strong.
419 * The best way to use this generator is with the predefined mt19937 class.
421 * This algorithm was originally invented by Makoto Matsumoto and
424 * @tparam __w Word size, the number of bits in each element of
426 * @tparam __n The degree of recursion.
427 * @tparam __m The period parameter.
428 * @tparam __r The separation point bit index.
429 * @tparam __a The last row of the twist matrix.
430 * @tparam __u The first right-shift tempering matrix parameter.
431 * @tparam __d The first right-shift tempering matrix mask.
432 * @tparam __s The first left-shift tempering matrix parameter.
433 * @tparam __b The first left-shift tempering matrix mask.
434 * @tparam __t The second left-shift tempering matrix parameter.
435 * @tparam __c The second left-shift tempering matrix mask.
436 * @tparam __l The second right-shift tempering matrix parameter.
437 * @tparam __f Initialization multiplier.
439 template<typename _UIntType, size_t __w,
440 size_t __n, size_t __m, size_t __r,
441 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
442 _UIntType __b, size_t __t,
443 _UIntType __c, size_t __l, _UIntType __f>
444 class mersenne_twister_engine
446 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
447 "substituting _UIntType not an unsigned integral type");
448 static_assert(1u <= __m && __m <= __n,
449 "template argument substituting __m out of bounds");
450 static_assert(__r <= __w, "template argument substituting "
452 static_assert(__u <= __w, "template argument substituting "
454 static_assert(__s <= __w, "template argument substituting "
456 static_assert(__t <= __w, "template argument substituting "
458 static_assert(__l <= __w, "template argument substituting "
460 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
461 "template argument substituting __w out of bound");
462 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
463 "template argument substituting __a out of bound");
464 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
465 "template argument substituting __b out of bound");
466 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
467 "template argument substituting __c out of bound");
468 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
469 "template argument substituting __d out of bound");
470 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
471 "template argument substituting __f out of bound");
474 /** The type of the generated random value. */
475 typedef _UIntType result_type;
478 static constexpr size_t word_size = __w;
479 static constexpr size_t state_size = __n;
480 static constexpr size_t shift_size = __m;
481 static constexpr size_t mask_bits = __r;
482 static constexpr result_type xor_mask = __a;
483 static constexpr size_t tempering_u = __u;
484 static constexpr result_type tempering_d = __d;
485 static constexpr size_t tempering_s = __s;
486 static constexpr result_type tempering_b = __b;
487 static constexpr size_t tempering_t = __t;
488 static constexpr result_type tempering_c = __c;
489 static constexpr size_t tempering_l = __l;
490 static constexpr result_type initialization_multiplier = __f;
491 static constexpr result_type default_seed = 5489u;
493 // constructors and member function
495 mersenne_twister_engine(result_type __sd = default_seed)
499 * @brief Constructs a %mersenne_twister_engine random number generator
500 * engine seeded from the seed sequence @p __q.
502 * @param __q the seed sequence.
504 template<typename _Sseq, typename = typename
505 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
508 mersenne_twister_engine(_Sseq& __q)
512 seed(result_type __sd = default_seed);
514 template<typename _Sseq>
515 typename std::enable_if<std::is_class<_Sseq>::value>::type
519 * @brief Gets the smallest possible value in the output range.
521 static constexpr result_type
526 * @brief Gets the largest possible value in the output range.
528 static constexpr result_type
530 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
533 * @brief Discard a sequence of random numbers.
536 discard(unsigned long long __z);
542 * @brief Compares two % mersenne_twister_engine random number generator
543 * objects of the same type for equality.
545 * @param __lhs A % mersenne_twister_engine random number generator
547 * @param __rhs Another % mersenne_twister_engine random number
550 * @returns true if the infinite sequences of generated values
551 * would be equal, false otherwise.
554 operator==(const mersenne_twister_engine& __lhs,
555 const mersenne_twister_engine& __rhs)
556 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
557 && __lhs._M_p == __rhs._M_p); }
560 * @brief Inserts the current state of a % mersenne_twister_engine
561 * random number generator engine @p __x into the output stream
564 * @param __os An output stream.
565 * @param __x A % mersenne_twister_engine random number generator
568 * @returns The output stream with the state of @p __x inserted or in
571 template<typename _UIntType1,
572 size_t __w1, size_t __n1,
573 size_t __m1, size_t __r1,
574 _UIntType1 __a1, size_t __u1,
575 _UIntType1 __d1, size_t __s1,
576 _UIntType1 __b1, size_t __t1,
577 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
578 typename _CharT, typename _Traits>
579 friend std::basic_ostream<_CharT, _Traits>&
580 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
581 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
582 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
586 * @brief Extracts the current state of a % mersenne_twister_engine
587 * random number generator engine @p __x from the input stream
590 * @param __is An input stream.
591 * @param __x A % mersenne_twister_engine random number generator
594 * @returns The input stream with the state of @p __x extracted or in
597 template<typename _UIntType1,
598 size_t __w1, size_t __n1,
599 size_t __m1, size_t __r1,
600 _UIntType1 __a1, size_t __u1,
601 _UIntType1 __d1, size_t __s1,
602 _UIntType1 __b1, size_t __t1,
603 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
604 typename _CharT, typename _Traits>
605 friend std::basic_istream<_CharT, _Traits>&
606 operator>>(std::basic_istream<_CharT, _Traits>& __is,
607 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
608 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
614 _UIntType _M_x[state_size];
619 * @brief Compares two % mersenne_twister_engine random number generator
620 * objects of the same type for inequality.
622 * @param __lhs A % mersenne_twister_engine random number generator
624 * @param __rhs Another % mersenne_twister_engine random number
627 * @returns true if the infinite sequences of generated values
628 * would be different, false otherwise.
630 template<typename _UIntType, size_t __w,
631 size_t __n, size_t __m, size_t __r,
632 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
633 _UIntType __b, size_t __t,
634 _UIntType __c, size_t __l, _UIntType __f>
636 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
637 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
638 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
639 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
640 { return !(__lhs == __rhs); }
644 * @brief The Marsaglia-Zaman generator.
646 * This is a model of a Generalized Fibonacci discrete random number
647 * generator, sometimes referred to as the SWC generator.
649 * A discrete random number generator that produces pseudorandom
652 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
655 * The size of the state is @f$r@f$
656 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
658 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
659 class subtract_with_carry_engine
661 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
662 "substituting _UIntType not an unsigned integral type");
663 static_assert(0u < __s && __s < __r,
664 "template argument substituting __s out of bounds");
665 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
666 "template argument substituting __w out of bounds");
669 /** The type of the generated random value. */
670 typedef _UIntType result_type;
673 static constexpr size_t word_size = __w;
674 static constexpr size_t short_lag = __s;
675 static constexpr size_t long_lag = __r;
676 static constexpr result_type default_seed = 19780503u;
679 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
680 * random number generator.
683 subtract_with_carry_engine(result_type __sd = default_seed)
687 * @brief Constructs a %subtract_with_carry_engine random number engine
688 * seeded from the seed sequence @p __q.
690 * @param __q the seed sequence.
692 template<typename _Sseq, typename = typename
693 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
696 subtract_with_carry_engine(_Sseq& __q)
700 * @brief Seeds the initial state @f$x_0@f$ of the random number
703 * N1688[4.19] modifies this as follows. If @p __value == 0,
704 * sets value to 19780503. In any case, with a linear
705 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
706 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
707 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
708 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
709 * set carry to 1, otherwise sets carry to 0.
712 seed(result_type __sd = default_seed);
715 * @brief Seeds the initial state @f$x_0@f$ of the
716 * % subtract_with_carry_engine random number generator.
718 template<typename _Sseq>
719 typename std::enable_if<std::is_class<_Sseq>::value>::type
723 * @brief Gets the inclusive minimum value of the range of random
724 * integers returned by this generator.
726 static constexpr result_type
731 * @brief Gets the inclusive maximum value of the range of random
732 * integers returned by this generator.
734 static constexpr result_type
736 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
739 * @brief Discard a sequence of random numbers.
742 discard(unsigned long long __z)
744 for (; __z != 0ULL; --__z)
749 * @brief Gets the next random number in the sequence.
755 * @brief Compares two % subtract_with_carry_engine random number
756 * generator objects of the same type for equality.
758 * @param __lhs A % subtract_with_carry_engine random number generator
760 * @param __rhs Another % subtract_with_carry_engine random number
763 * @returns true if the infinite sequences of generated values
764 * would be equal, false otherwise.
767 operator==(const subtract_with_carry_engine& __lhs,
768 const subtract_with_carry_engine& __rhs)
769 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
770 && __lhs._M_carry == __rhs._M_carry
771 && __lhs._M_p == __rhs._M_p); }
774 * @brief Inserts the current state of a % subtract_with_carry_engine
775 * random number generator engine @p __x into the output stream
778 * @param __os An output stream.
779 * @param __x A % subtract_with_carry_engine random number generator
782 * @returns The output stream with the state of @p __x inserted or in
785 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
786 typename _CharT, typename _Traits>
787 friend std::basic_ostream<_CharT, _Traits>&
788 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
789 const std::subtract_with_carry_engine<_UIntType1, __w1,
793 * @brief Extracts the current state of a % subtract_with_carry_engine
794 * random number generator engine @p __x from the input stream
797 * @param __is An input stream.
798 * @param __x A % subtract_with_carry_engine random number generator
801 * @returns The input stream with the state of @p __x extracted or in
804 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
805 typename _CharT, typename _Traits>
806 friend std::basic_istream<_CharT, _Traits>&
807 operator>>(std::basic_istream<_CharT, _Traits>& __is,
808 std::subtract_with_carry_engine<_UIntType1, __w1,
812 /// The state of the generator. This is a ring buffer.
813 _UIntType _M_x[long_lag];
814 _UIntType _M_carry; ///< The carry
815 size_t _M_p; ///< Current index of x(i - r).
819 * @brief Compares two % subtract_with_carry_engine random number
820 * generator objects of the same type for inequality.
822 * @param __lhs A % subtract_with_carry_engine random number generator
824 * @param __rhs Another % subtract_with_carry_engine random number
827 * @returns true if the infinite sequences of generated values
828 * would be different, false otherwise.
830 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
832 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
834 const std::subtract_with_carry_engine<_UIntType, __w,
836 { return !(__lhs == __rhs); }
840 * Produces random numbers from some base engine by discarding blocks of
843 * 0 <= @p __r <= @p __p
845 template<typename _RandomNumberEngine, size_t __p, size_t __r>
846 class discard_block_engine
848 static_assert(1 <= __r && __r <= __p,
849 "template argument substituting __r out of bounds");
852 /** The type of the generated random value. */
853 typedef typename _RandomNumberEngine::result_type result_type;
856 static constexpr size_t block_size = __p;
857 static constexpr size_t used_block = __r;
860 * @brief Constructs a default %discard_block_engine engine.
862 * The underlying engine is default constructed as well.
864 discard_block_engine()
865 : _M_b(), _M_n(0) { }
868 * @brief Copy constructs a %discard_block_engine engine.
870 * Copies an existing base class random number generator.
871 * @param __rng An existing (base class) engine object.
874 discard_block_engine(const _RandomNumberEngine& __rng)
875 : _M_b(__rng), _M_n(0) { }
878 * @brief Move constructs a %discard_block_engine engine.
880 * Copies an existing base class random number generator.
881 * @param __rng An existing (base class) engine object.
884 discard_block_engine(_RandomNumberEngine&& __rng)
885 : _M_b(std::move(__rng)), _M_n(0) { }
888 * @brief Seed constructs a %discard_block_engine engine.
890 * Constructs the underlying generator engine seeded with @p __s.
891 * @param __s A seed value for the base class engine.
894 discard_block_engine(result_type __s)
895 : _M_b(__s), _M_n(0) { }
898 * @brief Generator construct a %discard_block_engine engine.
900 * @param __q A seed sequence.
902 template<typename _Sseq, typename = typename
903 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
904 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
907 discard_block_engine(_Sseq& __q)
912 * @brief Reseeds the %discard_block_engine object with the default
913 * seed for the underlying base class generator engine.
923 * @brief Reseeds the %discard_block_engine object with the default
924 * seed for the underlying base class generator engine.
927 seed(result_type __s)
934 * @brief Reseeds the %discard_block_engine object with the given seed
936 * @param __q A seed generator function.
938 template<typename _Sseq>
947 * @brief Gets a const reference to the underlying generator engine
950 const _RandomNumberEngine&
951 base() const noexcept
955 * @brief Gets the minimum value in the generated random number range.
957 static constexpr result_type
959 { return _RandomNumberEngine::min(); }
962 * @brief Gets the maximum value in the generated random number range.
964 static constexpr result_type
966 { return _RandomNumberEngine::max(); }
969 * @brief Discard a sequence of random numbers.
972 discard(unsigned long long __z)
974 for (; __z != 0ULL; --__z)
979 * @brief Gets the next value in the generated random number sequence.
985 * @brief Compares two %discard_block_engine random number generator
986 * objects of the same type for equality.
988 * @param __lhs A %discard_block_engine random number generator object.
989 * @param __rhs Another %discard_block_engine random number generator
992 * @returns true if the infinite sequences of generated values
993 * would be equal, false otherwise.
996 operator==(const discard_block_engine& __lhs,
997 const discard_block_engine& __rhs)
998 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
1001 * @brief Inserts the current state of a %discard_block_engine random
1002 * number generator engine @p __x into the output stream
1005 * @param __os An output stream.
1006 * @param __x A %discard_block_engine random number generator engine.
1008 * @returns The output stream with the state of @p __x inserted or in
1011 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1012 typename _CharT, typename _Traits>
1013 friend std::basic_ostream<_CharT, _Traits>&
1014 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1015 const std::discard_block_engine<_RandomNumberEngine1,
1019 * @brief Extracts the current state of a % subtract_with_carry_engine
1020 * random number generator engine @p __x from the input stream
1023 * @param __is An input stream.
1024 * @param __x A %discard_block_engine random number generator engine.
1026 * @returns The input stream with the state of @p __x extracted or in
1029 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1030 typename _CharT, typename _Traits>
1031 friend std::basic_istream<_CharT, _Traits>&
1032 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1033 std::discard_block_engine<_RandomNumberEngine1,
1037 _RandomNumberEngine _M_b;
1042 * @brief Compares two %discard_block_engine random number generator
1043 * objects of the same type for inequality.
1045 * @param __lhs A %discard_block_engine random number generator object.
1046 * @param __rhs Another %discard_block_engine random number generator
1049 * @returns true if the infinite sequences of generated values
1050 * would be different, false otherwise.
1052 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1054 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1056 const std::discard_block_engine<_RandomNumberEngine, __p,
1058 { return !(__lhs == __rhs); }
1062 * Produces random numbers by combining random numbers from some base
1063 * engine to produce random numbers with a specifies number of bits @p __w.
1065 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1066 class independent_bits_engine
1068 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1069 "substituting _UIntType not an unsigned integral type");
1070 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1071 "template argument substituting __w out of bounds");
1074 /** The type of the generated random value. */
1075 typedef _UIntType result_type;
1078 * @brief Constructs a default %independent_bits_engine engine.
1080 * The underlying engine is default constructed as well.
1082 independent_bits_engine()
1086 * @brief Copy constructs a %independent_bits_engine engine.
1088 * Copies an existing base class random number generator.
1089 * @param __rng An existing (base class) engine object.
1092 independent_bits_engine(const _RandomNumberEngine& __rng)
1096 * @brief Move constructs a %independent_bits_engine engine.
1098 * Copies an existing base class random number generator.
1099 * @param __rng An existing (base class) engine object.
1102 independent_bits_engine(_RandomNumberEngine&& __rng)
1103 : _M_b(std::move(__rng)) { }
1106 * @brief Seed constructs a %independent_bits_engine engine.
1108 * Constructs the underlying generator engine seeded with @p __s.
1109 * @param __s A seed value for the base class engine.
1112 independent_bits_engine(result_type __s)
1116 * @brief Generator construct a %independent_bits_engine engine.
1118 * @param __q A seed sequence.
1120 template<typename _Sseq, typename = typename
1121 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1122 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1125 independent_bits_engine(_Sseq& __q)
1130 * @brief Reseeds the %independent_bits_engine object with the default
1131 * seed for the underlying base class generator engine.
1138 * @brief Reseeds the %independent_bits_engine object with the default
1139 * seed for the underlying base class generator engine.
1142 seed(result_type __s)
1146 * @brief Reseeds the %independent_bits_engine object with the given
1148 * @param __q A seed generator function.
1150 template<typename _Sseq>
1156 * @brief Gets a const reference to the underlying generator engine
1159 const _RandomNumberEngine&
1160 base() const noexcept
1164 * @brief Gets the minimum value in the generated random number range.
1166 static constexpr result_type
1171 * @brief Gets the maximum value in the generated random number range.
1173 static constexpr result_type
1175 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1178 * @brief Discard a sequence of random numbers.
1181 discard(unsigned long long __z)
1183 for (; __z != 0ULL; --__z)
1188 * @brief Gets the next value in the generated random number sequence.
1194 * @brief Compares two %independent_bits_engine random number generator
1195 * objects of the same type for equality.
1197 * @param __lhs A %independent_bits_engine random number generator
1199 * @param __rhs Another %independent_bits_engine random number generator
1202 * @returns true if the infinite sequences of generated values
1203 * would be equal, false otherwise.
1206 operator==(const independent_bits_engine& __lhs,
1207 const independent_bits_engine& __rhs)
1208 { return __lhs._M_b == __rhs._M_b; }
1211 * @brief Extracts the current state of a % subtract_with_carry_engine
1212 * random number generator engine @p __x from the input stream
1215 * @param __is An input stream.
1216 * @param __x A %independent_bits_engine random number generator
1219 * @returns The input stream with the state of @p __x extracted or in
1222 template<typename _CharT, typename _Traits>
1223 friend std::basic_istream<_CharT, _Traits>&
1224 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1225 std::independent_bits_engine<_RandomNumberEngine,
1226 __w, _UIntType>& __x)
1233 _RandomNumberEngine _M_b;
1237 * @brief Compares two %independent_bits_engine random number generator
1238 * objects of the same type for inequality.
1240 * @param __lhs A %independent_bits_engine random number generator
1242 * @param __rhs Another %independent_bits_engine random number generator
1245 * @returns true if the infinite sequences of generated values
1246 * would be different, false otherwise.
1248 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1250 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1252 const std::independent_bits_engine<_RandomNumberEngine, __w,
1254 { return !(__lhs == __rhs); }
1257 * @brief Inserts the current state of a %independent_bits_engine random
1258 * number generator engine @p __x into the output stream @p __os.
1260 * @param __os An output stream.
1261 * @param __x A %independent_bits_engine random number generator engine.
1263 * @returns The output stream with the state of @p __x inserted or in
1266 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1267 typename _CharT, typename _Traits>
1268 std::basic_ostream<_CharT, _Traits>&
1269 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1270 const std::independent_bits_engine<_RandomNumberEngine,
1271 __w, _UIntType>& __x)
1279 * @brief Produces random numbers by combining random numbers from some
1280 * base engine to produce random numbers with a specifies number of bits
1283 template<typename _RandomNumberEngine, size_t __k>
1284 class shuffle_order_engine
1286 static_assert(1u <= __k, "template argument substituting "
1287 "__k out of bound");
1290 /** The type of the generated random value. */
1291 typedef typename _RandomNumberEngine::result_type result_type;
1293 static constexpr size_t table_size = __k;
1296 * @brief Constructs a default %shuffle_order_engine engine.
1298 * The underlying engine is default constructed as well.
1300 shuffle_order_engine()
1302 { _M_initialize(); }
1305 * @brief Copy constructs a %shuffle_order_engine engine.
1307 * Copies an existing base class random number generator.
1308 * @param __rng An existing (base class) engine object.
1311 shuffle_order_engine(const _RandomNumberEngine& __rng)
1313 { _M_initialize(); }
1316 * @brief Move constructs a %shuffle_order_engine engine.
1318 * Copies an existing base class random number generator.
1319 * @param __rng An existing (base class) engine object.
1322 shuffle_order_engine(_RandomNumberEngine&& __rng)
1323 : _M_b(std::move(__rng))
1324 { _M_initialize(); }
1327 * @brief Seed constructs a %shuffle_order_engine engine.
1329 * Constructs the underlying generator engine seeded with @p __s.
1330 * @param __s A seed value for the base class engine.
1333 shuffle_order_engine(result_type __s)
1335 { _M_initialize(); }
1338 * @brief Generator construct a %shuffle_order_engine engine.
1340 * @param __q A seed sequence.
1342 template<typename _Sseq, typename = typename
1343 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1344 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1347 shuffle_order_engine(_Sseq& __q)
1349 { _M_initialize(); }
1352 * @brief Reseeds the %shuffle_order_engine object with the default seed
1353 for the underlying base class generator engine.
1363 * @brief Reseeds the %shuffle_order_engine object with the default seed
1364 * for the underlying base class generator engine.
1367 seed(result_type __s)
1374 * @brief Reseeds the %shuffle_order_engine object with the given seed
1376 * @param __q A seed generator function.
1378 template<typename _Sseq>
1387 * Gets a const reference to the underlying generator engine object.
1389 const _RandomNumberEngine&
1390 base() const noexcept
1394 * Gets the minimum value in the generated random number range.
1396 static constexpr result_type
1398 { return _RandomNumberEngine::min(); }
1401 * Gets the maximum value in the generated random number range.
1403 static constexpr result_type
1405 { return _RandomNumberEngine::max(); }
1408 * Discard a sequence of random numbers.
1411 discard(unsigned long long __z)
1413 for (; __z != 0ULL; --__z)
1418 * Gets the next value in the generated random number sequence.
1424 * Compares two %shuffle_order_engine random number generator objects
1425 * of the same type for equality.
1427 * @param __lhs A %shuffle_order_engine random number generator object.
1428 * @param __rhs Another %shuffle_order_engine random number generator
1431 * @returns true if the infinite sequences of generated values
1432 * would be equal, false otherwise.
1435 operator==(const shuffle_order_engine& __lhs,
1436 const shuffle_order_engine& __rhs)
1437 { return (__lhs._M_b == __rhs._M_b
1438 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1439 && __lhs._M_y == __rhs._M_y); }
1442 * @brief Inserts the current state of a %shuffle_order_engine random
1443 * number generator engine @p __x into the output stream
1446 * @param __os An output stream.
1447 * @param __x A %shuffle_order_engine random number generator engine.
1449 * @returns The output stream with the state of @p __x inserted or in
1452 template<typename _RandomNumberEngine1, size_t __k1,
1453 typename _CharT, typename _Traits>
1454 friend std::basic_ostream<_CharT, _Traits>&
1455 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1456 const std::shuffle_order_engine<_RandomNumberEngine1,
1460 * @brief Extracts the current state of a % subtract_with_carry_engine
1461 * random number generator engine @p __x from the input stream
1464 * @param __is An input stream.
1465 * @param __x A %shuffle_order_engine random number generator engine.
1467 * @returns The input stream with the state of @p __x extracted or in
1470 template<typename _RandomNumberEngine1, size_t __k1,
1471 typename _CharT, typename _Traits>
1472 friend std::basic_istream<_CharT, _Traits>&
1473 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1474 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
1477 void _M_initialize()
1479 for (size_t __i = 0; __i < __k; ++__i)
1484 _RandomNumberEngine _M_b;
1485 result_type _M_v[__k];
1490 * Compares two %shuffle_order_engine random number generator objects
1491 * of the same type for inequality.
1493 * @param __lhs A %shuffle_order_engine random number generator object.
1494 * @param __rhs Another %shuffle_order_engine random number generator
1497 * @returns true if the infinite sequences of generated values
1498 * would be different, false otherwise.
1500 template<typename _RandomNumberEngine, size_t __k>
1502 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1504 const std::shuffle_order_engine<_RandomNumberEngine,
1506 { return !(__lhs == __rhs); }
1510 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1512 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1516 * An alternative LCR (Lehmer Generator function).
1518 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1522 * The classic Mersenne Twister.
1525 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1526 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1527 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1529 typedef mersenne_twister_engine<
1535 0xefc60000UL, 18, 1812433253UL> mt19937;
1538 * An alternative Mersenne Twister.
1540 typedef mersenne_twister_engine<
1543 0xb5026f5aa96619e9ULL, 29,
1544 0x5555555555555555ULL, 17,
1545 0x71d67fffeda60000ULL, 37,
1546 0xfff7eee000000000ULL, 43,
1547 6364136223846793005ULL> mt19937_64;
1549 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1552 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1555 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1557 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1559 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1561 typedef minstd_rand0 default_random_engine;
1564 * A standard interface to a platform-specific non-deterministic
1565 * random number generator (if any are available).
1570 /** The type of the generated random value. */
1571 typedef unsigned int result_type;
1573 // constructors, destructors and member functions
1575 #ifdef _GLIBCXX_USE_RANDOM_TR1
1578 random_device(const std::string& __token = "default")
1589 random_device(const std::string& __token = "mt19937")
1590 { _M_init_pretr1(__token); }
1596 static constexpr result_type
1598 { return std::numeric_limits<result_type>::min(); }
1600 static constexpr result_type
1602 { return std::numeric_limits<result_type>::max(); }
1605 entropy() const noexcept
1611 #ifdef _GLIBCXX_USE_RANDOM_TR1
1612 return this->_M_getval();
1614 return this->_M_getval_pretr1();
1618 // No copy functions.
1619 random_device(const random_device&) = delete;
1620 void operator=(const random_device&) = delete;
1624 void _M_init(const std::string& __token);
1625 void _M_init_pretr1(const std::string& __token);
1628 result_type _M_getval();
1629 result_type _M_getval_pretr1();
1638 /* @} */ // group random_generators
1641 * @addtogroup random_distributions Random Number Distributions
1647 * @addtogroup random_distributions_uniform Uniform Distributions
1648 * @ingroup random_distributions
1652 // std::uniform_int_distribution is defined in <bits/uniform_int_dist.h>
1655 * @brief Return true if two uniform integer distributions have
1656 * different parameters.
1658 template<typename _IntType>
1660 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1661 const std::uniform_int_distribution<_IntType>& __d2)
1662 { return !(__d1 == __d2); }
1665 * @brief Inserts a %uniform_int_distribution random number
1666 * distribution @p __x into the output stream @p os.
1668 * @param __os An output stream.
1669 * @param __x A %uniform_int_distribution random number distribution.
1671 * @returns The output stream with the state of @p __x inserted or in
1674 template<typename _IntType, typename _CharT, typename _Traits>
1675 std::basic_ostream<_CharT, _Traits>&
1676 operator<<(std::basic_ostream<_CharT, _Traits>&,
1677 const std::uniform_int_distribution<_IntType>&);
1680 * @brief Extracts a %uniform_int_distribution random number distribution
1681 * @p __x from the input stream @p __is.
1683 * @param __is An input stream.
1684 * @param __x A %uniform_int_distribution random number generator engine.
1686 * @returns The input stream with @p __x extracted or in an error state.
1688 template<typename _IntType, typename _CharT, typename _Traits>
1689 std::basic_istream<_CharT, _Traits>&
1690 operator>>(std::basic_istream<_CharT, _Traits>&,
1691 std::uniform_int_distribution<_IntType>&);
1695 * @brief Uniform continuous distribution for random numbers.
1697 * A continuous random distribution on the range [min, max) with equal
1698 * probability throughout the range. The URNG should be real-valued and
1699 * deliver number in the range [0, 1).
1701 template<typename _RealType = double>
1702 class uniform_real_distribution
1704 static_assert(std::is_floating_point<_RealType>::value,
1705 "template argument not a floating point type");
1708 /** The type of the range of the distribution. */
1709 typedef _RealType result_type;
1710 /** Parameter type. */
1713 typedef uniform_real_distribution<_RealType> distribution_type;
1716 param_type(_RealType __a = _RealType(0),
1717 _RealType __b = _RealType(1))
1718 : _M_a(__a), _M_b(__b)
1720 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1732 operator==(const param_type& __p1, const param_type& __p2)
1733 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1742 * @brief Constructs a uniform_real_distribution object.
1744 * @param __a [IN] The lower bound of the distribution.
1745 * @param __b [IN] The upper bound of the distribution.
1748 uniform_real_distribution(_RealType __a = _RealType(0),
1749 _RealType __b = _RealType(1))
1750 : _M_param(__a, __b)
1754 uniform_real_distribution(const param_type& __p)
1759 * @brief Resets the distribution state.
1761 * Does nothing for the uniform real distribution.
1768 { return _M_param.a(); }
1772 { return _M_param.b(); }
1775 * @brief Returns the parameter set of the distribution.
1779 { return _M_param; }
1782 * @brief Sets the parameter set of the distribution.
1783 * @param __param The new parameter set of the distribution.
1786 param(const param_type& __param)
1787 { _M_param = __param; }
1790 * @brief Returns the inclusive lower bound of the distribution range.
1794 { return this->a(); }
1797 * @brief Returns the inclusive upper bound of the distribution range.
1801 { return this->b(); }
1804 * @brief Generating functions.
1806 template<typename _UniformRandomNumberGenerator>
1808 operator()(_UniformRandomNumberGenerator& __urng)
1809 { return this->operator()(__urng, _M_param); }
1811 template<typename _UniformRandomNumberGenerator>
1813 operator()(_UniformRandomNumberGenerator& __urng,
1814 const param_type& __p)
1816 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1818 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1821 template<typename _ForwardIterator,
1822 typename _UniformRandomNumberGenerator>
1824 __generate(_ForwardIterator __f, _ForwardIterator __t,
1825 _UniformRandomNumberGenerator& __urng)
1826 { this->__generate(__f, __t, __urng, _M_param); }
1828 template<typename _ForwardIterator,
1829 typename _UniformRandomNumberGenerator>
1831 __generate(_ForwardIterator __f, _ForwardIterator __t,
1832 _UniformRandomNumberGenerator& __urng,
1833 const param_type& __p)
1834 { this->__generate_impl(__f, __t, __urng, __p); }
1836 template<typename _UniformRandomNumberGenerator>
1838 __generate(result_type* __f, result_type* __t,
1839 _UniformRandomNumberGenerator& __urng,
1840 const param_type& __p)
1841 { this->__generate_impl(__f, __t, __urng, __p); }
1844 * @brief Return true if two uniform real distributions have
1845 * the same parameters.
1848 operator==(const uniform_real_distribution& __d1,
1849 const uniform_real_distribution& __d2)
1850 { return __d1._M_param == __d2._M_param; }
1853 template<typename _ForwardIterator,
1854 typename _UniformRandomNumberGenerator>
1856 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1857 _UniformRandomNumberGenerator& __urng,
1858 const param_type& __p);
1860 param_type _M_param;
1864 * @brief Return true if two uniform real distributions have
1865 * different parameters.
1867 template<typename _IntType>
1869 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1870 const std::uniform_real_distribution<_IntType>& __d2)
1871 { return !(__d1 == __d2); }
1874 * @brief Inserts a %uniform_real_distribution random number
1875 * distribution @p __x into the output stream @p __os.
1877 * @param __os An output stream.
1878 * @param __x A %uniform_real_distribution random number distribution.
1880 * @returns The output stream with the state of @p __x inserted or in
1883 template<typename _RealType, typename _CharT, typename _Traits>
1884 std::basic_ostream<_CharT, _Traits>&
1885 operator<<(std::basic_ostream<_CharT, _Traits>&,
1886 const std::uniform_real_distribution<_RealType>&);
1889 * @brief Extracts a %uniform_real_distribution random number distribution
1890 * @p __x from the input stream @p __is.
1892 * @param __is An input stream.
1893 * @param __x A %uniform_real_distribution random number generator engine.
1895 * @returns The input stream with @p __x extracted or in an error state.
1897 template<typename _RealType, typename _CharT, typename _Traits>
1898 std::basic_istream<_CharT, _Traits>&
1899 operator>>(std::basic_istream<_CharT, _Traits>&,
1900 std::uniform_real_distribution<_RealType>&);
1902 /* @} */ // group random_distributions_uniform
1905 * @addtogroup random_distributions_normal Normal Distributions
1906 * @ingroup random_distributions
1911 * @brief A normal continuous distribution for random numbers.
1913 * The formula for the normal probability density function is
1915 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1916 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1919 template<typename _RealType = double>
1920 class normal_distribution
1922 static_assert(std::is_floating_point<_RealType>::value,
1923 "template argument not a floating point type");
1926 /** The type of the range of the distribution. */
1927 typedef _RealType result_type;
1928 /** Parameter type. */
1931 typedef normal_distribution<_RealType> distribution_type;
1934 param_type(_RealType __mean = _RealType(0),
1935 _RealType __stddev = _RealType(1))
1936 : _M_mean(__mean), _M_stddev(__stddev)
1938 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1947 { return _M_stddev; }
1950 operator==(const param_type& __p1, const param_type& __p2)
1951 { return (__p1._M_mean == __p2._M_mean
1952 && __p1._M_stddev == __p2._M_stddev); }
1956 _RealType _M_stddev;
1961 * Constructs a normal distribution with parameters @f$mean@f$ and
1962 * standard deviation.
1965 normal_distribution(result_type __mean = result_type(0),
1966 result_type __stddev = result_type(1))
1967 : _M_param(__mean, __stddev), _M_saved_available(false)
1971 normal_distribution(const param_type& __p)
1972 : _M_param(__p), _M_saved_available(false)
1976 * @brief Resets the distribution state.
1980 { _M_saved_available = false; }
1983 * @brief Returns the mean of the distribution.
1987 { return _M_param.mean(); }
1990 * @brief Returns the standard deviation of the distribution.
1994 { return _M_param.stddev(); }
1997 * @brief Returns the parameter set of the distribution.
2001 { return _M_param; }
2004 * @brief Sets the parameter set of the distribution.
2005 * @param __param The new parameter set of the distribution.
2008 param(const param_type& __param)
2009 { _M_param = __param; }
2012 * @brief Returns the greatest lower bound value of the distribution.
2016 { return std::numeric_limits<result_type>::lowest(); }
2019 * @brief Returns the least upper bound value of the distribution.
2023 { return std::numeric_limits<result_type>::max(); }
2026 * @brief Generating functions.
2028 template<typename _UniformRandomNumberGenerator>
2030 operator()(_UniformRandomNumberGenerator& __urng)
2031 { return this->operator()(__urng, _M_param); }
2033 template<typename _UniformRandomNumberGenerator>
2035 operator()(_UniformRandomNumberGenerator& __urng,
2036 const param_type& __p);
2038 template<typename _ForwardIterator,
2039 typename _UniformRandomNumberGenerator>
2041 __generate(_ForwardIterator __f, _ForwardIterator __t,
2042 _UniformRandomNumberGenerator& __urng)
2043 { this->__generate(__f, __t, __urng, _M_param); }
2045 template<typename _ForwardIterator,
2046 typename _UniformRandomNumberGenerator>
2048 __generate(_ForwardIterator __f, _ForwardIterator __t,
2049 _UniformRandomNumberGenerator& __urng,
2050 const param_type& __p)
2051 { this->__generate_impl(__f, __t, __urng, __p); }
2053 template<typename _UniformRandomNumberGenerator>
2055 __generate(result_type* __f, result_type* __t,
2056 _UniformRandomNumberGenerator& __urng,
2057 const param_type& __p)
2058 { this->__generate_impl(__f, __t, __urng, __p); }
2061 * @brief Return true if two normal distributions have
2062 * the same parameters and the sequences that would
2063 * be generated are equal.
2065 template<typename _RealType1>
2067 operator==(const std::normal_distribution<_RealType1>& __d1,
2068 const std::normal_distribution<_RealType1>& __d2);
2071 * @brief Inserts a %normal_distribution random number distribution
2072 * @p __x into the output stream @p __os.
2074 * @param __os An output stream.
2075 * @param __x A %normal_distribution random number distribution.
2077 * @returns The output stream with the state of @p __x inserted or in
2080 template<typename _RealType1, typename _CharT, typename _Traits>
2081 friend std::basic_ostream<_CharT, _Traits>&
2082 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2083 const std::normal_distribution<_RealType1>& __x);
2086 * @brief Extracts a %normal_distribution random number distribution
2087 * @p __x from the input stream @p __is.
2089 * @param __is An input stream.
2090 * @param __x A %normal_distribution random number generator engine.
2092 * @returns The input stream with @p __x extracted or in an error
2095 template<typename _RealType1, typename _CharT, typename _Traits>
2096 friend std::basic_istream<_CharT, _Traits>&
2097 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2098 std::normal_distribution<_RealType1>& __x);
2101 template<typename _ForwardIterator,
2102 typename _UniformRandomNumberGenerator>
2104 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2105 _UniformRandomNumberGenerator& __urng,
2106 const param_type& __p);
2108 param_type _M_param;
2109 result_type _M_saved;
2110 bool _M_saved_available;
2114 * @brief Return true if two normal distributions are different.
2116 template<typename _RealType>
2118 operator!=(const std::normal_distribution<_RealType>& __d1,
2119 const std::normal_distribution<_RealType>& __d2)
2120 { return !(__d1 == __d2); }
2124 * @brief A lognormal_distribution random number distribution.
2126 * The formula for the normal probability mass function is
2128 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2129 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2132 template<typename _RealType = double>
2133 class lognormal_distribution
2135 static_assert(std::is_floating_point<_RealType>::value,
2136 "template argument not a floating point type");
2139 /** The type of the range of the distribution. */
2140 typedef _RealType result_type;
2141 /** Parameter type. */
2144 typedef lognormal_distribution<_RealType> distribution_type;
2147 param_type(_RealType __m = _RealType(0),
2148 _RealType __s = _RealType(1))
2149 : _M_m(__m), _M_s(__s)
2161 operator==(const param_type& __p1, const param_type& __p2)
2162 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2170 lognormal_distribution(_RealType __m = _RealType(0),
2171 _RealType __s = _RealType(1))
2172 : _M_param(__m, __s), _M_nd()
2176 lognormal_distribution(const param_type& __p)
2177 : _M_param(__p), _M_nd()
2181 * Resets the distribution state.
2192 { return _M_param.m(); }
2196 { return _M_param.s(); }
2199 * @brief Returns the parameter set of the distribution.
2203 { return _M_param; }
2206 * @brief Sets the parameter set of the distribution.
2207 * @param __param The new parameter set of the distribution.
2210 param(const param_type& __param)
2211 { _M_param = __param; }
2214 * @brief Returns the greatest lower bound value of the distribution.
2218 { return result_type(0); }
2221 * @brief Returns the least upper bound value of the distribution.
2225 { return std::numeric_limits<result_type>::max(); }
2228 * @brief Generating functions.
2230 template<typename _UniformRandomNumberGenerator>
2232 operator()(_UniformRandomNumberGenerator& __urng)
2233 { return this->operator()(__urng, _M_param); }
2235 template<typename _UniformRandomNumberGenerator>
2237 operator()(_UniformRandomNumberGenerator& __urng,
2238 const param_type& __p)
2239 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2241 template<typename _ForwardIterator,
2242 typename _UniformRandomNumberGenerator>
2244 __generate(_ForwardIterator __f, _ForwardIterator __t,
2245 _UniformRandomNumberGenerator& __urng)
2246 { this->__generate(__f, __t, __urng, _M_param); }
2248 template<typename _ForwardIterator,
2249 typename _UniformRandomNumberGenerator>
2251 __generate(_ForwardIterator __f, _ForwardIterator __t,
2252 _UniformRandomNumberGenerator& __urng,
2253 const param_type& __p)
2254 { this->__generate_impl(__f, __t, __urng, __p); }
2256 template<typename _UniformRandomNumberGenerator>
2258 __generate(result_type* __f, result_type* __t,
2259 _UniformRandomNumberGenerator& __urng,
2260 const param_type& __p)
2261 { this->__generate_impl(__f, __t, __urng, __p); }
2264 * @brief Return true if two lognormal distributions have
2265 * the same parameters and the sequences that would
2266 * be generated are equal.
2269 operator==(const lognormal_distribution& __d1,
2270 const lognormal_distribution& __d2)
2271 { return (__d1._M_param == __d2._M_param
2272 && __d1._M_nd == __d2._M_nd); }
2275 * @brief Inserts a %lognormal_distribution random number distribution
2276 * @p __x into the output stream @p __os.
2278 * @param __os An output stream.
2279 * @param __x A %lognormal_distribution random number distribution.
2281 * @returns The output stream with the state of @p __x inserted or in
2284 template<typename _RealType1, typename _CharT, typename _Traits>
2285 friend std::basic_ostream<_CharT, _Traits>&
2286 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2287 const std::lognormal_distribution<_RealType1>& __x);
2290 * @brief Extracts a %lognormal_distribution random number distribution
2291 * @p __x from the input stream @p __is.
2293 * @param __is An input stream.
2294 * @param __x A %lognormal_distribution random number
2297 * @returns The input stream with @p __x extracted or in an error state.
2299 template<typename _RealType1, typename _CharT, typename _Traits>
2300 friend std::basic_istream<_CharT, _Traits>&
2301 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2302 std::lognormal_distribution<_RealType1>& __x);
2305 template<typename _ForwardIterator,
2306 typename _UniformRandomNumberGenerator>
2308 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2309 _UniformRandomNumberGenerator& __urng,
2310 const param_type& __p);
2312 param_type _M_param;
2314 std::normal_distribution<result_type> _M_nd;
2318 * @brief Return true if two lognormal distributions are different.
2320 template<typename _RealType>
2322 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2323 const std::lognormal_distribution<_RealType>& __d2)
2324 { return !(__d1 == __d2); }
2328 * @brief A gamma continuous distribution for random numbers.
2330 * The formula for the gamma probability density function is:
2332 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2333 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2336 template<typename _RealType = double>
2337 class gamma_distribution
2339 static_assert(std::is_floating_point<_RealType>::value,
2340 "template argument not a floating point type");
2343 /** The type of the range of the distribution. */
2344 typedef _RealType result_type;
2345 /** Parameter type. */
2348 typedef gamma_distribution<_RealType> distribution_type;
2349 friend class gamma_distribution<_RealType>;
2352 param_type(_RealType __alpha_val = _RealType(1),
2353 _RealType __beta_val = _RealType(1))
2354 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2356 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2362 { return _M_alpha; }
2369 operator==(const param_type& __p1, const param_type& __p2)
2370 { return (__p1._M_alpha == __p2._M_alpha
2371 && __p1._M_beta == __p2._M_beta); }
2380 _RealType _M_malpha, _M_a2;
2385 * @brief Constructs a gamma distribution with parameters
2386 * @f$\alpha@f$ and @f$\beta@f$.
2389 gamma_distribution(_RealType __alpha_val = _RealType(1),
2390 _RealType __beta_val = _RealType(1))
2391 : _M_param(__alpha_val, __beta_val), _M_nd()
2395 gamma_distribution(const param_type& __p)
2396 : _M_param(__p), _M_nd()
2400 * @brief Resets the distribution state.
2407 * @brief Returns the @f$\alpha@f$ of the distribution.
2411 { return _M_param.alpha(); }
2414 * @brief Returns the @f$\beta@f$ of the distribution.
2418 { return _M_param.beta(); }
2421 * @brief Returns the parameter set of the distribution.
2425 { return _M_param; }
2428 * @brief Sets the parameter set of the distribution.
2429 * @param __param The new parameter set of the distribution.
2432 param(const param_type& __param)
2433 { _M_param = __param; }
2436 * @brief Returns the greatest lower bound value of the distribution.
2440 { return result_type(0); }
2443 * @brief Returns the least upper bound value of the distribution.
2447 { return std::numeric_limits<result_type>::max(); }
2450 * @brief Generating functions.
2452 template<typename _UniformRandomNumberGenerator>
2454 operator()(_UniformRandomNumberGenerator& __urng)
2455 { return this->operator()(__urng, _M_param); }
2457 template<typename _UniformRandomNumberGenerator>
2459 operator()(_UniformRandomNumberGenerator& __urng,
2460 const param_type& __p);
2462 template<typename _ForwardIterator,
2463 typename _UniformRandomNumberGenerator>
2465 __generate(_ForwardIterator __f, _ForwardIterator __t,
2466 _UniformRandomNumberGenerator& __urng)
2467 { this->__generate(__f, __t, __urng, _M_param); }
2469 template<typename _ForwardIterator,
2470 typename _UniformRandomNumberGenerator>
2472 __generate(_ForwardIterator __f, _ForwardIterator __t,
2473 _UniformRandomNumberGenerator& __urng,
2474 const param_type& __p)
2475 { this->__generate_impl(__f, __t, __urng, __p); }
2477 template<typename _UniformRandomNumberGenerator>
2479 __generate(result_type* __f, result_type* __t,
2480 _UniformRandomNumberGenerator& __urng,
2481 const param_type& __p)
2482 { this->__generate_impl(__f, __t, __urng, __p); }
2485 * @brief Return true if two gamma distributions have the same
2486 * parameters and the sequences that would be generated
2490 operator==(const gamma_distribution& __d1,
2491 const gamma_distribution& __d2)
2492 { return (__d1._M_param == __d2._M_param
2493 && __d1._M_nd == __d2._M_nd); }
2496 * @brief Inserts a %gamma_distribution random number distribution
2497 * @p __x into the output stream @p __os.
2499 * @param __os An output stream.
2500 * @param __x A %gamma_distribution random number distribution.
2502 * @returns The output stream with the state of @p __x inserted or in
2505 template<typename _RealType1, typename _CharT, typename _Traits>
2506 friend std::basic_ostream<_CharT, _Traits>&
2507 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2508 const std::gamma_distribution<_RealType1>& __x);
2511 * @brief Extracts a %gamma_distribution random number distribution
2512 * @p __x from the input stream @p __is.
2514 * @param __is An input stream.
2515 * @param __x A %gamma_distribution random number generator engine.
2517 * @returns The input stream with @p __x extracted or in an error state.
2519 template<typename _RealType1, typename _CharT, typename _Traits>
2520 friend std::basic_istream<_CharT, _Traits>&
2521 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2522 std::gamma_distribution<_RealType1>& __x);
2525 template<typename _ForwardIterator,
2526 typename _UniformRandomNumberGenerator>
2528 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2529 _UniformRandomNumberGenerator& __urng,
2530 const param_type& __p);
2532 param_type _M_param;
2534 std::normal_distribution<result_type> _M_nd;
2538 * @brief Return true if two gamma distributions are different.
2540 template<typename _RealType>
2542 operator!=(const std::gamma_distribution<_RealType>& __d1,
2543 const std::gamma_distribution<_RealType>& __d2)
2544 { return !(__d1 == __d2); }
2548 * @brief A chi_squared_distribution random number distribution.
2550 * The formula for the normal probability mass function is
2551 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2553 template<typename _RealType = double>
2554 class chi_squared_distribution
2556 static_assert(std::is_floating_point<_RealType>::value,
2557 "template argument not a floating point type");
2560 /** The type of the range of the distribution. */
2561 typedef _RealType result_type;
2562 /** Parameter type. */
2565 typedef chi_squared_distribution<_RealType> distribution_type;
2568 param_type(_RealType __n = _RealType(1))
2577 operator==(const param_type& __p1, const param_type& __p2)
2578 { return __p1._M_n == __p2._M_n; }
2585 chi_squared_distribution(_RealType __n = _RealType(1))
2586 : _M_param(__n), _M_gd(__n / 2)
2590 chi_squared_distribution(const param_type& __p)
2591 : _M_param(__p), _M_gd(__p.n() / 2)
2595 * @brief Resets the distribution state.
2606 { return _M_param.n(); }
2609 * @brief Returns the parameter set of the distribution.
2613 { return _M_param; }
2616 * @brief Sets the parameter set of the distribution.
2617 * @param __param The new parameter set of the distribution.
2620 param(const param_type& __param)
2621 { _M_param = __param; }
2624 * @brief Returns the greatest lower bound value of the distribution.
2628 { return result_type(0); }
2631 * @brief Returns the least upper bound value of the distribution.
2635 { return std::numeric_limits<result_type>::max(); }
2638 * @brief Generating functions.
2640 template<typename _UniformRandomNumberGenerator>
2642 operator()(_UniformRandomNumberGenerator& __urng)
2643 { return 2 * _M_gd(__urng); }
2645 template<typename _UniformRandomNumberGenerator>
2647 operator()(_UniformRandomNumberGenerator& __urng,
2648 const param_type& __p)
2650 typedef typename std::gamma_distribution<result_type>::param_type
2652 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2655 template<typename _ForwardIterator,
2656 typename _UniformRandomNumberGenerator>
2658 __generate(_ForwardIterator __f, _ForwardIterator __t,
2659 _UniformRandomNumberGenerator& __urng)
2660 { this->__generate_impl(__f, __t, __urng); }
2662 template<typename _ForwardIterator,
2663 typename _UniformRandomNumberGenerator>
2665 __generate(_ForwardIterator __f, _ForwardIterator __t,
2666 _UniformRandomNumberGenerator& __urng,
2667 const param_type& __p)
2668 { typename std::gamma_distribution<result_type>::param_type
2670 this->__generate_impl(__f, __t, __urng, __p2); }
2672 template<typename _UniformRandomNumberGenerator>
2674 __generate(result_type* __f, result_type* __t,
2675 _UniformRandomNumberGenerator& __urng)
2676 { this->__generate_impl(__f, __t, __urng); }
2678 template<typename _UniformRandomNumberGenerator>
2680 __generate(result_type* __f, result_type* __t,
2681 _UniformRandomNumberGenerator& __urng,
2682 const param_type& __p)
2683 { typename std::gamma_distribution<result_type>::param_type
2685 this->__generate_impl(__f, __t, __urng, __p2); }
2688 * @brief Return true if two Chi-squared distributions have
2689 * the same parameters and the sequences that would be
2690 * generated are equal.
2693 operator==(const chi_squared_distribution& __d1,
2694 const chi_squared_distribution& __d2)
2695 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
2698 * @brief Inserts a %chi_squared_distribution random number distribution
2699 * @p __x into the output stream @p __os.
2701 * @param __os An output stream.
2702 * @param __x A %chi_squared_distribution random number distribution.
2704 * @returns The output stream with the state of @p __x inserted or in
2707 template<typename _RealType1, typename _CharT, typename _Traits>
2708 friend std::basic_ostream<_CharT, _Traits>&
2709 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2710 const std::chi_squared_distribution<_RealType1>& __x);
2713 * @brief Extracts a %chi_squared_distribution random number distribution
2714 * @p __x from the input stream @p __is.
2716 * @param __is An input stream.
2717 * @param __x A %chi_squared_distribution random number
2720 * @returns The input stream with @p __x extracted or in an error state.
2722 template<typename _RealType1, typename _CharT, typename _Traits>
2723 friend std::basic_istream<_CharT, _Traits>&
2724 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2725 std::chi_squared_distribution<_RealType1>& __x);
2728 template<typename _ForwardIterator,
2729 typename _UniformRandomNumberGenerator>
2731 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2732 _UniformRandomNumberGenerator& __urng);
2734 template<typename _ForwardIterator,
2735 typename _UniformRandomNumberGenerator>
2737 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2738 _UniformRandomNumberGenerator& __urng,
2740 std::gamma_distribution<result_type>::param_type& __p);
2742 param_type _M_param;
2744 std::gamma_distribution<result_type> _M_gd;
2748 * @brief Return true if two Chi-squared distributions are different.
2750 template<typename _RealType>
2752 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2753 const std::chi_squared_distribution<_RealType>& __d2)
2754 { return !(__d1 == __d2); }
2758 * @brief A cauchy_distribution random number distribution.
2760 * The formula for the normal probability mass function is
2761 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2763 template<typename _RealType = double>
2764 class cauchy_distribution
2766 static_assert(std::is_floating_point<_RealType>::value,
2767 "template argument not a floating point type");
2770 /** The type of the range of the distribution. */
2771 typedef _RealType result_type;
2772 /** Parameter type. */
2775 typedef cauchy_distribution<_RealType> distribution_type;
2778 param_type(_RealType __a = _RealType(0),
2779 _RealType __b = _RealType(1))
2780 : _M_a(__a), _M_b(__b)
2792 operator==(const param_type& __p1, const param_type& __p2)
2793 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2801 cauchy_distribution(_RealType __a = _RealType(0),
2802 _RealType __b = _RealType(1))
2803 : _M_param(__a, __b)
2807 cauchy_distribution(const param_type& __p)
2812 * @brief Resets the distribution state.
2823 { return _M_param.a(); }
2827 { return _M_param.b(); }
2830 * @brief Returns the parameter set of the distribution.
2834 { return _M_param; }
2837 * @brief Sets the parameter set of the distribution.
2838 * @param __param The new parameter set of the distribution.
2841 param(const param_type& __param)
2842 { _M_param = __param; }
2845 * @brief Returns the greatest lower bound value of the distribution.
2849 { return std::numeric_limits<result_type>::lowest(); }
2852 * @brief Returns the least upper bound value of the distribution.
2856 { return std::numeric_limits<result_type>::max(); }
2859 * @brief Generating functions.
2861 template<typename _UniformRandomNumberGenerator>
2863 operator()(_UniformRandomNumberGenerator& __urng)
2864 { return this->operator()(__urng, _M_param); }
2866 template<typename _UniformRandomNumberGenerator>
2868 operator()(_UniformRandomNumberGenerator& __urng,
2869 const param_type& __p);
2871 template<typename _ForwardIterator,
2872 typename _UniformRandomNumberGenerator>
2874 __generate(_ForwardIterator __f, _ForwardIterator __t,
2875 _UniformRandomNumberGenerator& __urng)
2876 { this->__generate(__f, __t, __urng, _M_param); }
2878 template<typename _ForwardIterator,
2879 typename _UniformRandomNumberGenerator>
2881 __generate(_ForwardIterator __f, _ForwardIterator __t,
2882 _UniformRandomNumberGenerator& __urng,
2883 const param_type& __p)
2884 { this->__generate_impl(__f, __t, __urng, __p); }
2886 template<typename _UniformRandomNumberGenerator>
2888 __generate(result_type* __f, result_type* __t,
2889 _UniformRandomNumberGenerator& __urng,
2890 const param_type& __p)
2891 { this->__generate_impl(__f, __t, __urng, __p); }
2894 * @brief Return true if two Cauchy distributions have
2895 * the same parameters.
2898 operator==(const cauchy_distribution& __d1,
2899 const cauchy_distribution& __d2)
2900 { return __d1._M_param == __d2._M_param; }
2903 template<typename _ForwardIterator,
2904 typename _UniformRandomNumberGenerator>
2906 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2907 _UniformRandomNumberGenerator& __urng,
2908 const param_type& __p);
2910 param_type _M_param;
2914 * @brief Return true if two Cauchy distributions have
2915 * different parameters.
2917 template<typename _RealType>
2919 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2920 const std::cauchy_distribution<_RealType>& __d2)
2921 { return !(__d1 == __d2); }
2924 * @brief Inserts a %cauchy_distribution random number distribution
2925 * @p __x into the output stream @p __os.
2927 * @param __os An output stream.
2928 * @param __x A %cauchy_distribution random number distribution.
2930 * @returns The output stream with the state of @p __x inserted or in
2933 template<typename _RealType, typename _CharT, typename _Traits>
2934 std::basic_ostream<_CharT, _Traits>&
2935 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2936 const std::cauchy_distribution<_RealType>& __x);
2939 * @brief Extracts a %cauchy_distribution random number distribution
2940 * @p __x from the input stream @p __is.
2942 * @param __is An input stream.
2943 * @param __x A %cauchy_distribution random number
2946 * @returns The input stream with @p __x extracted or in an error state.
2948 template<typename _RealType, typename _CharT, typename _Traits>
2949 std::basic_istream<_CharT, _Traits>&
2950 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2951 std::cauchy_distribution<_RealType>& __x);
2955 * @brief A fisher_f_distribution random number distribution.
2957 * The formula for the normal probability mass function is
2959 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2960 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2961 * (1 + \frac{mx}{n})^{-(m+n)/2}
2964 template<typename _RealType = double>
2965 class fisher_f_distribution
2967 static_assert(std::is_floating_point<_RealType>::value,
2968 "template argument not a floating point type");
2971 /** The type of the range of the distribution. */
2972 typedef _RealType result_type;
2973 /** Parameter type. */
2976 typedef fisher_f_distribution<_RealType> distribution_type;
2979 param_type(_RealType __m = _RealType(1),
2980 _RealType __n = _RealType(1))
2981 : _M_m(__m), _M_n(__n)
2993 operator==(const param_type& __p1, const param_type& __p2)
2994 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
3002 fisher_f_distribution(_RealType __m = _RealType(1),
3003 _RealType __n = _RealType(1))
3004 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
3008 fisher_f_distribution(const param_type& __p)
3009 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
3013 * @brief Resets the distribution state.
3027 { return _M_param.m(); }
3031 { return _M_param.n(); }
3034 * @brief Returns the parameter set of the distribution.
3038 { return _M_param; }
3041 * @brief Sets the parameter set of the distribution.
3042 * @param __param The new parameter set of the distribution.
3045 param(const param_type& __param)
3046 { _M_param = __param; }
3049 * @brief Returns the greatest lower bound value of the distribution.
3053 { return result_type(0); }
3056 * @brief Returns the least upper bound value of the distribution.
3060 { return std::numeric_limits<result_type>::max(); }
3063 * @brief Generating functions.
3065 template<typename _UniformRandomNumberGenerator>
3067 operator()(_UniformRandomNumberGenerator& __urng)
3068 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
3070 template<typename _UniformRandomNumberGenerator>
3072 operator()(_UniformRandomNumberGenerator& __urng,
3073 const param_type& __p)
3075 typedef typename std::gamma_distribution<result_type>::param_type
3077 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
3078 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
3081 template<typename _ForwardIterator,
3082 typename _UniformRandomNumberGenerator>
3084 __generate(_ForwardIterator __f, _ForwardIterator __t,
3085 _UniformRandomNumberGenerator& __urng)
3086 { this->__generate_impl(__f, __t, __urng); }
3088 template<typename _ForwardIterator,
3089 typename _UniformRandomNumberGenerator>
3091 __generate(_ForwardIterator __f, _ForwardIterator __t,
3092 _UniformRandomNumberGenerator& __urng,
3093 const param_type& __p)
3094 { this->__generate_impl(__f, __t, __urng, __p); }
3096 template<typename _UniformRandomNumberGenerator>
3098 __generate(result_type* __f, result_type* __t,
3099 _UniformRandomNumberGenerator& __urng)
3100 { this->__generate_impl(__f, __t, __urng); }
3102 template<typename _UniformRandomNumberGenerator>
3104 __generate(result_type* __f, result_type* __t,
3105 _UniformRandomNumberGenerator& __urng,
3106 const param_type& __p)
3107 { this->__generate_impl(__f, __t, __urng, __p); }
3110 * @brief Return true if two Fisher f distributions have
3111 * the same parameters and the sequences that would
3112 * be generated are equal.
3115 operator==(const fisher_f_distribution& __d1,
3116 const fisher_f_distribution& __d2)
3117 { return (__d1._M_param == __d2._M_param
3118 && __d1._M_gd_x == __d2._M_gd_x
3119 && __d1._M_gd_y == __d2._M_gd_y); }
3122 * @brief Inserts a %fisher_f_distribution random number distribution
3123 * @p __x into the output stream @p __os.
3125 * @param __os An output stream.
3126 * @param __x A %fisher_f_distribution random number distribution.
3128 * @returns The output stream with the state of @p __x inserted or in
3131 template<typename _RealType1, typename _CharT, typename _Traits>
3132 friend std::basic_ostream<_CharT, _Traits>&
3133 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3134 const std::fisher_f_distribution<_RealType1>& __x);
3137 * @brief Extracts a %fisher_f_distribution random number distribution
3138 * @p __x from the input stream @p __is.
3140 * @param __is An input stream.
3141 * @param __x A %fisher_f_distribution random number
3144 * @returns The input stream with @p __x extracted or in an error state.
3146 template<typename _RealType1, typename _CharT, typename _Traits>
3147 friend std::basic_istream<_CharT, _Traits>&
3148 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3149 std::fisher_f_distribution<_RealType1>& __x);
3152 template<typename _ForwardIterator,
3153 typename _UniformRandomNumberGenerator>
3155 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3156 _UniformRandomNumberGenerator& __urng);
3158 template<typename _ForwardIterator,
3159 typename _UniformRandomNumberGenerator>
3161 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3162 _UniformRandomNumberGenerator& __urng,
3163 const param_type& __p);
3165 param_type _M_param;
3167 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3171 * @brief Return true if two Fisher f distributions are different.
3173 template<typename _RealType>
3175 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3176 const std::fisher_f_distribution<_RealType>& __d2)
3177 { return !(__d1 == __d2); }
3180 * @brief A student_t_distribution random number distribution.
3182 * The formula for the normal probability mass function is:
3184 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3185 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3188 template<typename _RealType = double>
3189 class student_t_distribution
3191 static_assert(std::is_floating_point<_RealType>::value,
3192 "template argument not a floating point type");
3195 /** The type of the range of the distribution. */
3196 typedef _RealType result_type;
3197 /** Parameter type. */
3200 typedef student_t_distribution<_RealType> distribution_type;
3203 param_type(_RealType __n = _RealType(1))
3212 operator==(const param_type& __p1, const param_type& __p2)
3213 { return __p1._M_n == __p2._M_n; }
3220 student_t_distribution(_RealType __n = _RealType(1))
3221 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3225 student_t_distribution(const param_type& __p)
3226 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3230 * @brief Resets the distribution state.
3244 { return _M_param.n(); }
3247 * @brief Returns the parameter set of the distribution.
3251 { return _M_param; }
3254 * @brief Sets the parameter set of the distribution.
3255 * @param __param The new parameter set of the distribution.
3258 param(const param_type& __param)
3259 { _M_param = __param; }
3262 * @brief Returns the greatest lower bound value of the distribution.
3266 { return std::numeric_limits<result_type>::lowest(); }
3269 * @brief Returns the least upper bound value of the distribution.
3273 { return std::numeric_limits<result_type>::max(); }
3276 * @brief Generating functions.
3278 template<typename _UniformRandomNumberGenerator>
3280 operator()(_UniformRandomNumberGenerator& __urng)
3281 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3283 template<typename _UniformRandomNumberGenerator>
3285 operator()(_UniformRandomNumberGenerator& __urng,
3286 const param_type& __p)
3288 typedef typename std::gamma_distribution<result_type>::param_type
3291 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3292 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3295 template<typename _ForwardIterator,
3296 typename _UniformRandomNumberGenerator>
3298 __generate(_ForwardIterator __f, _ForwardIterator __t,
3299 _UniformRandomNumberGenerator& __urng)
3300 { this->__generate_impl(__f, __t, __urng); }
3302 template<typename _ForwardIterator,
3303 typename _UniformRandomNumberGenerator>
3305 __generate(_ForwardIterator __f, _ForwardIterator __t,
3306 _UniformRandomNumberGenerator& __urng,
3307 const param_type& __p)
3308 { this->__generate_impl(__f, __t, __urng, __p); }
3310 template<typename _UniformRandomNumberGenerator>
3312 __generate(result_type* __f, result_type* __t,
3313 _UniformRandomNumberGenerator& __urng)
3314 { this->__generate_impl(__f, __t, __urng); }
3316 template<typename _UniformRandomNumberGenerator>
3318 __generate(result_type* __f, result_type* __t,
3319 _UniformRandomNumberGenerator& __urng,
3320 const param_type& __p)
3321 { this->__generate_impl(__f, __t, __urng, __p); }
3324 * @brief Return true if two Student t distributions have
3325 * the same parameters and the sequences that would
3326 * be generated are equal.
3329 operator==(const student_t_distribution& __d1,
3330 const student_t_distribution& __d2)
3331 { return (__d1._M_param == __d2._M_param
3332 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3335 * @brief Inserts a %student_t_distribution random number distribution
3336 * @p __x into the output stream @p __os.
3338 * @param __os An output stream.
3339 * @param __x A %student_t_distribution random number distribution.
3341 * @returns The output stream with the state of @p __x inserted or in
3344 template<typename _RealType1, typename _CharT, typename _Traits>
3345 friend std::basic_ostream<_CharT, _Traits>&
3346 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3347 const std::student_t_distribution<_RealType1>& __x);
3350 * @brief Extracts a %student_t_distribution random number distribution
3351 * @p __x from the input stream @p __is.
3353 * @param __is An input stream.
3354 * @param __x A %student_t_distribution random number
3357 * @returns The input stream with @p __x extracted or in an error state.
3359 template<typename _RealType1, typename _CharT, typename _Traits>
3360 friend std::basic_istream<_CharT, _Traits>&
3361 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3362 std::student_t_distribution<_RealType1>& __x);
3365 template<typename _ForwardIterator,
3366 typename _UniformRandomNumberGenerator>
3368 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3369 _UniformRandomNumberGenerator& __urng);
3370 template<typename _ForwardIterator,
3371 typename _UniformRandomNumberGenerator>
3373 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3374 _UniformRandomNumberGenerator& __urng,
3375 const param_type& __p);
3377 param_type _M_param;
3379 std::normal_distribution<result_type> _M_nd;
3380 std::gamma_distribution<result_type> _M_gd;
3384 * @brief Return true if two Student t distributions are different.
3386 template<typename _RealType>
3388 operator!=(const std::student_t_distribution<_RealType>& __d1,
3389 const std::student_t_distribution<_RealType>& __d2)
3390 { return !(__d1 == __d2); }
3393 /* @} */ // group random_distributions_normal
3396 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3397 * @ingroup random_distributions
3402 * @brief A Bernoulli random number distribution.
3404 * Generates a sequence of true and false values with likelihood @f$p@f$
3405 * that true will come up and @f$(1 - p)@f$ that false will appear.
3407 class bernoulli_distribution
3410 /** The type of the range of the distribution. */
3411 typedef bool result_type;
3412 /** Parameter type. */
3415 typedef bernoulli_distribution distribution_type;
3418 param_type(double __p = 0.5)
3421 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3429 operator==(const param_type& __p1, const param_type& __p2)
3430 { return __p1._M_p == __p2._M_p; }
3438 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3440 * @param __p [IN] The likelihood of a true result being returned.
3441 * Must be in the interval @f$[0, 1]@f$.
3444 bernoulli_distribution(double __p = 0.5)
3449 bernoulli_distribution(const param_type& __p)
3454 * @brief Resets the distribution state.
3456 * Does nothing for a Bernoulli distribution.
3462 * @brief Returns the @p p parameter of the distribution.
3466 { return _M_param.p(); }
3469 * @brief Returns the parameter set of the distribution.
3473 { return _M_param; }
3476 * @brief Sets the parameter set of the distribution.
3477 * @param __param The new parameter set of the distribution.
3480 param(const param_type& __param)
3481 { _M_param = __param; }
3484 * @brief Returns the greatest lower bound value of the distribution.
3488 { return std::numeric_limits<result_type>::min(); }
3491 * @brief Returns the least upper bound value of the distribution.
3495 { return std::numeric_limits<result_type>::max(); }
3498 * @brief Generating functions.
3500 template<typename _UniformRandomNumberGenerator>
3502 operator()(_UniformRandomNumberGenerator& __urng)
3503 { return this->operator()(__urng, _M_param); }
3505 template<typename _UniformRandomNumberGenerator>
3507 operator()(_UniformRandomNumberGenerator& __urng,
3508 const param_type& __p)
3510 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3512 if ((__aurng() - __aurng.min())
3513 < __p.p() * (__aurng.max() - __aurng.min()))
3518 template<typename _ForwardIterator,
3519 typename _UniformRandomNumberGenerator>
3521 __generate(_ForwardIterator __f, _ForwardIterator __t,
3522 _UniformRandomNumberGenerator& __urng)
3523 { this->__generate(__f, __t, __urng, _M_param); }
3525 template<typename _ForwardIterator,
3526 typename _UniformRandomNumberGenerator>
3528 __generate(_ForwardIterator __f, _ForwardIterator __t,
3529 _UniformRandomNumberGenerator& __urng, const param_type& __p)
3530 { this->__generate_impl(__f, __t, __urng, __p); }
3532 template<typename _UniformRandomNumberGenerator>
3534 __generate(result_type* __f, result_type* __t,
3535 _UniformRandomNumberGenerator& __urng,
3536 const param_type& __p)
3537 { this->__generate_impl(__f, __t, __urng, __p); }
3540 * @brief Return true if two Bernoulli distributions have
3541 * the same parameters.
3544 operator==(const bernoulli_distribution& __d1,
3545 const bernoulli_distribution& __d2)
3546 { return __d1._M_param == __d2._M_param; }
3549 template<typename _ForwardIterator,
3550 typename _UniformRandomNumberGenerator>
3552 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3553 _UniformRandomNumberGenerator& __urng,
3554 const param_type& __p);
3556 param_type _M_param;
3560 * @brief Return true if two Bernoulli distributions have
3561 * different parameters.
3564 operator!=(const std::bernoulli_distribution& __d1,
3565 const std::bernoulli_distribution& __d2)
3566 { return !(__d1 == __d2); }
3569 * @brief Inserts a %bernoulli_distribution random number distribution
3570 * @p __x into the output stream @p __os.
3572 * @param __os An output stream.
3573 * @param __x A %bernoulli_distribution random number distribution.
3575 * @returns The output stream with the state of @p __x inserted or in
3578 template<typename _CharT, typename _Traits>
3579 std::basic_ostream<_CharT, _Traits>&
3580 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3581 const std::bernoulli_distribution& __x);
3584 * @brief Extracts a %bernoulli_distribution random number distribution
3585 * @p __x from the input stream @p __is.
3587 * @param __is An input stream.
3588 * @param __x A %bernoulli_distribution random number generator engine.
3590 * @returns The input stream with @p __x extracted or in an error state.
3592 template<typename _CharT, typename _Traits>
3593 std::basic_istream<_CharT, _Traits>&
3594 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3595 std::bernoulli_distribution& __x)
3599 __x.param(bernoulli_distribution::param_type(__p));
3605 * @brief A discrete binomial random number distribution.
3607 * The formula for the binomial probability density function is
3608 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3609 * and @f$p@f$ are the parameters of the distribution.
3611 template<typename _IntType = int>
3612 class binomial_distribution
3614 static_assert(std::is_integral<_IntType>::value,
3615 "template argument not an integral type");
3618 /** The type of the range of the distribution. */
3619 typedef _IntType result_type;
3620 /** Parameter type. */
3623 typedef binomial_distribution<_IntType> distribution_type;
3624 friend class binomial_distribution<_IntType>;
3627 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3628 : _M_t(__t), _M_p(__p)
3630 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3645 operator==(const param_type& __p1, const param_type& __p2)
3646 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3656 #if _GLIBCXX_USE_C99_MATH_TR1
3657 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3658 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3663 // constructors and member function
3665 binomial_distribution(_IntType __t = _IntType(1),
3667 : _M_param(__t, __p), _M_nd()
3671 binomial_distribution(const param_type& __p)
3672 : _M_param(__p), _M_nd()
3676 * @brief Resets the distribution state.
3683 * @brief Returns the distribution @p t parameter.
3687 { return _M_param.t(); }
3690 * @brief Returns the distribution @p p parameter.
3694 { return _M_param.p(); }
3697 * @brief Returns the parameter set of the distribution.
3701 { return _M_param; }
3704 * @brief Sets the parameter set of the distribution.
3705 * @param __param The new parameter set of the distribution.
3708 param(const param_type& __param)
3709 { _M_param = __param; }
3712 * @brief Returns the greatest lower bound value of the distribution.
3719 * @brief Returns the least upper bound value of the distribution.
3723 { return _M_param.t(); }
3726 * @brief Generating functions.
3728 template<typename _UniformRandomNumberGenerator>
3730 operator()(_UniformRandomNumberGenerator& __urng)
3731 { return this->operator()(__urng, _M_param); }
3733 template<typename _UniformRandomNumberGenerator>
3735 operator()(_UniformRandomNumberGenerator& __urng,
3736 const param_type& __p);
3738 template<typename _ForwardIterator,
3739 typename _UniformRandomNumberGenerator>
3741 __generate(_ForwardIterator __f, _ForwardIterator __t,
3742 _UniformRandomNumberGenerator& __urng)
3743 { this->__generate(__f, __t, __urng, _M_param); }
3745 template<typename _ForwardIterator,
3746 typename _UniformRandomNumberGenerator>
3748 __generate(_ForwardIterator __f, _ForwardIterator __t,
3749 _UniformRandomNumberGenerator& __urng,
3750 const param_type& __p)
3751 { this->__generate_impl(__f, __t, __urng, __p); }
3753 template<typename _UniformRandomNumberGenerator>
3755 __generate(result_type* __f, result_type* __t,
3756 _UniformRandomNumberGenerator& __urng,
3757 const param_type& __p)
3758 { this->__generate_impl(__f, __t, __urng, __p); }
3761 * @brief Return true if two binomial distributions have
3762 * the same parameters and the sequences that would
3763 * be generated are equal.
3766 operator==(const binomial_distribution& __d1,
3767 const binomial_distribution& __d2)
3768 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3769 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
3771 { return __d1._M_param == __d2._M_param; }
3775 * @brief Inserts a %binomial_distribution random number distribution
3776 * @p __x into the output stream @p __os.
3778 * @param __os An output stream.
3779 * @param __x A %binomial_distribution random number distribution.
3781 * @returns The output stream with the state of @p __x inserted or in
3784 template<typename _IntType1,
3785 typename _CharT, typename _Traits>
3786 friend std::basic_ostream<_CharT, _Traits>&
3787 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3788 const std::binomial_distribution<_IntType1>& __x);
3791 * @brief Extracts a %binomial_distribution random number distribution
3792 * @p __x from the input stream @p __is.
3794 * @param __is An input stream.
3795 * @param __x A %binomial_distribution random number generator engine.
3797 * @returns The input stream with @p __x extracted or in an error
3800 template<typename _IntType1,
3801 typename _CharT, typename _Traits>
3802 friend std::basic_istream<_CharT, _Traits>&
3803 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3804 std::binomial_distribution<_IntType1>& __x);
3807 template<typename _ForwardIterator,
3808 typename _UniformRandomNumberGenerator>
3810 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3811 _UniformRandomNumberGenerator& __urng,
3812 const param_type& __p);
3814 template<typename _UniformRandomNumberGenerator>
3816 _M_waiting(_UniformRandomNumberGenerator& __urng,
3817 _IntType __t, double __q);
3819 param_type _M_param;
3821 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3822 std::normal_distribution<double> _M_nd;
3826 * @brief Return true if two binomial distributions are different.
3828 template<typename _IntType>
3830 operator!=(const std::binomial_distribution<_IntType>& __d1,
3831 const std::binomial_distribution<_IntType>& __d2)
3832 { return !(__d1 == __d2); }
3836 * @brief A discrete geometric random number distribution.
3838 * The formula for the geometric probability density function is
3839 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3842 template<typename _IntType = int>
3843 class geometric_distribution
3845 static_assert(std::is_integral<_IntType>::value,
3846 "template argument not an integral type");
3849 /** The type of the range of the distribution. */
3850 typedef _IntType result_type;
3851 /** Parameter type. */
3854 typedef geometric_distribution<_IntType> distribution_type;
3855 friend class geometric_distribution<_IntType>;
3858 param_type(double __p = 0.5)
3861 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
3870 operator==(const param_type& __p1, const param_type& __p2)
3871 { return __p1._M_p == __p2._M_p; }
3876 { _M_log_1_p = std::log(1.0 - _M_p); }
3883 // constructors and member function
3885 geometric_distribution(double __p = 0.5)
3890 geometric_distribution(const param_type& __p)
3895 * @brief Resets the distribution state.
3897 * Does nothing for the geometric distribution.
3903 * @brief Returns the distribution parameter @p p.
3907 { return _M_param.p(); }
3910 * @brief Returns the parameter set of the distribution.
3914 { return _M_param; }
3917 * @brief Sets the parameter set of the distribution.
3918 * @param __param The new parameter set of the distribution.
3921 param(const param_type& __param)
3922 { _M_param = __param; }
3925 * @brief Returns the greatest lower bound value of the distribution.
3932 * @brief Returns the least upper bound value of the distribution.
3936 { return std::numeric_limits<result_type>::max(); }
3939 * @brief Generating functions.
3941 template<typename _UniformRandomNumberGenerator>
3943 operator()(_UniformRandomNumberGenerator& __urng)
3944 { return this->operator()(__urng, _M_param); }
3946 template<typename _UniformRandomNumberGenerator>
3948 operator()(_UniformRandomNumberGenerator& __urng,
3949 const param_type& __p);
3951 template<typename _ForwardIterator,
3952 typename _UniformRandomNumberGenerator>
3954 __generate(_ForwardIterator __f, _ForwardIterator __t,
3955 _UniformRandomNumberGenerator& __urng)
3956 { this->__generate(__f, __t, __urng, _M_param); }
3958 template<typename _ForwardIterator,
3959 typename _UniformRandomNumberGenerator>
3961 __generate(_ForwardIterator __f, _ForwardIterator __t,
3962 _UniformRandomNumberGenerator& __urng,
3963 const param_type& __p)
3964 { this->__generate_impl(__f, __t, __urng, __p); }
3966 template<typename _UniformRandomNumberGenerator>
3968 __generate(result_type* __f, result_type* __t,
3969 _UniformRandomNumberGenerator& __urng,
3970 const param_type& __p)
3971 { this->__generate_impl(__f, __t, __urng, __p); }
3974 * @brief Return true if two geometric distributions have
3975 * the same parameters.
3978 operator==(const geometric_distribution& __d1,
3979 const geometric_distribution& __d2)
3980 { return __d1._M_param == __d2._M_param; }
3983 template<typename _ForwardIterator,
3984 typename _UniformRandomNumberGenerator>
3986 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3987 _UniformRandomNumberGenerator& __urng,
3988 const param_type& __p);
3990 param_type _M_param;
3994 * @brief Return true if two geometric distributions have
3995 * different parameters.
3997 template<typename _IntType>
3999 operator!=(const std::geometric_distribution<_IntType>& __d1,
4000 const std::geometric_distribution<_IntType>& __d2)
4001 { return !(__d1 == __d2); }
4004 * @brief Inserts a %geometric_distribution random number distribution
4005 * @p __x into the output stream @p __os.
4007 * @param __os An output stream.
4008 * @param __x A %geometric_distribution random number distribution.
4010 * @returns The output stream with the state of @p __x inserted or in
4013 template<typename _IntType,
4014 typename _CharT, typename _Traits>
4015 std::basic_ostream<_CharT, _Traits>&
4016 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4017 const std::geometric_distribution<_IntType>& __x);
4020 * @brief Extracts a %geometric_distribution random number distribution
4021 * @p __x from the input stream @p __is.
4023 * @param __is An input stream.
4024 * @param __x A %geometric_distribution random number generator engine.
4026 * @returns The input stream with @p __x extracted or in an error state.
4028 template<typename _IntType,
4029 typename _CharT, typename _Traits>
4030 std::basic_istream<_CharT, _Traits>&
4031 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4032 std::geometric_distribution<_IntType>& __x);
4036 * @brief A negative_binomial_distribution random number distribution.
4038 * The formula for the negative binomial probability mass function is
4039 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4040 * and @f$p@f$ are the parameters of the distribution.
4042 template<typename _IntType = int>
4043 class negative_binomial_distribution
4045 static_assert(std::is_integral<_IntType>::value,
4046 "template argument not an integral type");
4049 /** The type of the range of the distribution. */
4050 typedef _IntType result_type;
4051 /** Parameter type. */
4054 typedef negative_binomial_distribution<_IntType> distribution_type;
4057 param_type(_IntType __k = 1, double __p = 0.5)
4058 : _M_k(__k), _M_p(__p)
4060 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
4072 operator==(const param_type& __p1, const param_type& __p2)
4073 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
4081 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
4082 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
4086 negative_binomial_distribution(const param_type& __p)
4087 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
4091 * @brief Resets the distribution state.
4098 * @brief Return the @f$k@f$ parameter of the distribution.
4102 { return _M_param.k(); }
4105 * @brief Return the @f$p@f$ parameter of the distribution.
4109 { return _M_param.p(); }
4112 * @brief Returns the parameter set of the distribution.
4116 { return _M_param; }
4119 * @brief Sets the parameter set of the distribution.
4120 * @param __param The new parameter set of the distribution.
4123 param(const param_type& __param)
4124 { _M_param = __param; }
4127 * @brief Returns the greatest lower bound value of the distribution.
4131 { return result_type(0); }
4134 * @brief Returns the least upper bound value of the distribution.
4138 { return std::numeric_limits<result_type>::max(); }
4141 * @brief Generating functions.
4143 template<typename _UniformRandomNumberGenerator>
4145 operator()(_UniformRandomNumberGenerator& __urng);
4147 template<typename _UniformRandomNumberGenerator>
4149 operator()(_UniformRandomNumberGenerator& __urng,
4150 const param_type& __p);
4152 template<typename _ForwardIterator,
4153 typename _UniformRandomNumberGenerator>
4155 __generate(_ForwardIterator __f, _ForwardIterator __t,
4156 _UniformRandomNumberGenerator& __urng)
4157 { this->__generate_impl(__f, __t, __urng); }
4159 template<typename _ForwardIterator,
4160 typename _UniformRandomNumberGenerator>
4162 __generate(_ForwardIterator __f, _ForwardIterator __t,
4163 _UniformRandomNumberGenerator& __urng,
4164 const param_type& __p)
4165 { this->__generate_impl(__f, __t, __urng, __p); }
4167 template<typename _UniformRandomNumberGenerator>
4169 __generate(result_type* __f, result_type* __t,
4170 _UniformRandomNumberGenerator& __urng)
4171 { this->__generate_impl(__f, __t, __urng); }
4173 template<typename _UniformRandomNumberGenerator>
4175 __generate(result_type* __f, result_type* __t,
4176 _UniformRandomNumberGenerator& __urng,
4177 const param_type& __p)
4178 { this->__generate_impl(__f, __t, __urng, __p); }
4181 * @brief Return true if two negative binomial distributions have
4182 * the same parameters and the sequences that would be
4183 * generated are equal.
4186 operator==(const negative_binomial_distribution& __d1,
4187 const negative_binomial_distribution& __d2)
4188 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
4191 * @brief Inserts a %negative_binomial_distribution random
4192 * number distribution @p __x into the output stream @p __os.
4194 * @param __os An output stream.
4195 * @param __x A %negative_binomial_distribution random number
4198 * @returns The output stream with the state of @p __x inserted or in
4201 template<typename _IntType1, typename _CharT, typename _Traits>
4202 friend std::basic_ostream<_CharT, _Traits>&
4203 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4204 const std::negative_binomial_distribution<_IntType1>& __x);
4207 * @brief Extracts a %negative_binomial_distribution random number
4208 * distribution @p __x from the input stream @p __is.
4210 * @param __is An input stream.
4211 * @param __x A %negative_binomial_distribution random number
4214 * @returns The input stream with @p __x extracted or in an error state.
4216 template<typename _IntType1, typename _CharT, typename _Traits>
4217 friend std::basic_istream<_CharT, _Traits>&
4218 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4219 std::negative_binomial_distribution<_IntType1>& __x);
4222 template<typename _ForwardIterator,
4223 typename _UniformRandomNumberGenerator>
4225 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4226 _UniformRandomNumberGenerator& __urng);
4227 template<typename _ForwardIterator,
4228 typename _UniformRandomNumberGenerator>
4230 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4231 _UniformRandomNumberGenerator& __urng,
4232 const param_type& __p);
4234 param_type _M_param;
4236 std::gamma_distribution<double> _M_gd;
4240 * @brief Return true if two negative binomial distributions are different.
4242 template<typename _IntType>
4244 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
4245 const std::negative_binomial_distribution<_IntType>& __d2)
4246 { return !(__d1 == __d2); }
4249 /* @} */ // group random_distributions_bernoulli
4252 * @addtogroup random_distributions_poisson Poisson Distributions
4253 * @ingroup random_distributions
4258 * @brief A discrete Poisson random number distribution.
4260 * The formula for the Poisson probability density function is
4261 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4262 * parameter of the distribution.
4264 template<typename _IntType = int>
4265 class poisson_distribution
4267 static_assert(std::is_integral<_IntType>::value,
4268 "template argument not an integral type");
4271 /** The type of the range of the distribution. */
4272 typedef _IntType result_type;
4273 /** Parameter type. */
4276 typedef poisson_distribution<_IntType> distribution_type;
4277 friend class poisson_distribution<_IntType>;
4280 param_type(double __mean = 1.0)
4283 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
4292 operator==(const param_type& __p1, const param_type& __p2)
4293 { return __p1._M_mean == __p2._M_mean; }
4296 // Hosts either log(mean) or the threshold of the simple method.
4303 #if _GLIBCXX_USE_C99_MATH_TR1
4304 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4308 // constructors and member function
4310 poisson_distribution(double __mean = 1.0)
4311 : _M_param(__mean), _M_nd()
4315 poisson_distribution(const param_type& __p)
4316 : _M_param(__p), _M_nd()
4320 * @brief Resets the distribution state.
4327 * @brief Returns the distribution parameter @p mean.
4331 { return _M_param.mean(); }
4334 * @brief Returns the parameter set of the distribution.
4338 { return _M_param; }
4341 * @brief Sets the parameter set of the distribution.
4342 * @param __param The new parameter set of the distribution.
4345 param(const param_type& __param)
4346 { _M_param = __param; }
4349 * @brief Returns the greatest lower bound value of the distribution.
4356 * @brief Returns the least upper bound value of the distribution.
4360 { return std::numeric_limits<result_type>::max(); }
4363 * @brief Generating functions.
4365 template<typename _UniformRandomNumberGenerator>
4367 operator()(_UniformRandomNumberGenerator& __urng)
4368 { return this->operator()(__urng, _M_param); }
4370 template<typename _UniformRandomNumberGenerator>
4372 operator()(_UniformRandomNumberGenerator& __urng,
4373 const param_type& __p);
4375 template<typename _ForwardIterator,
4376 typename _UniformRandomNumberGenerator>
4378 __generate(_ForwardIterator __f, _ForwardIterator __t,
4379 _UniformRandomNumberGenerator& __urng)
4380 { this->__generate(__f, __t, __urng, _M_param); }
4382 template<typename _ForwardIterator,
4383 typename _UniformRandomNumberGenerator>
4385 __generate(_ForwardIterator __f, _ForwardIterator __t,
4386 _UniformRandomNumberGenerator& __urng,
4387 const param_type& __p)
4388 { this->__generate_impl(__f, __t, __urng, __p); }
4390 template<typename _UniformRandomNumberGenerator>
4392 __generate(result_type* __f, result_type* __t,
4393 _UniformRandomNumberGenerator& __urng,
4394 const param_type& __p)
4395 { this->__generate_impl(__f, __t, __urng, __p); }
4398 * @brief Return true if two Poisson distributions have the same
4399 * parameters and the sequences that would be generated
4403 operator==(const poisson_distribution& __d1,
4404 const poisson_distribution& __d2)
4405 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4406 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4408 { return __d1._M_param == __d2._M_param; }
4412 * @brief Inserts a %poisson_distribution random number distribution
4413 * @p __x into the output stream @p __os.
4415 * @param __os An output stream.
4416 * @param __x A %poisson_distribution random number distribution.
4418 * @returns The output stream with the state of @p __x inserted or in
4421 template<typename _IntType1, typename _CharT, typename _Traits>
4422 friend std::basic_ostream<_CharT, _Traits>&
4423 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4424 const std::poisson_distribution<_IntType1>& __x);
4427 * @brief Extracts a %poisson_distribution random number distribution
4428 * @p __x from the input stream @p __is.
4430 * @param __is An input stream.
4431 * @param __x A %poisson_distribution random number generator engine.
4433 * @returns The input stream with @p __x extracted or in an error
4436 template<typename _IntType1, typename _CharT, typename _Traits>
4437 friend std::basic_istream<_CharT, _Traits>&
4438 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4439 std::poisson_distribution<_IntType1>& __x);
4442 template<typename _ForwardIterator,
4443 typename _UniformRandomNumberGenerator>
4445 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4446 _UniformRandomNumberGenerator& __urng,
4447 const param_type& __p);
4449 param_type _M_param;
4451 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4452 std::normal_distribution<double> _M_nd;
4456 * @brief Return true if two Poisson distributions are different.
4458 template<typename _IntType>
4460 operator!=(const std::poisson_distribution<_IntType>& __d1,
4461 const std::poisson_distribution<_IntType>& __d2)
4462 { return !(__d1 == __d2); }
4466 * @brief An exponential continuous distribution for random numbers.
4468 * The formula for the exponential probability density function is
4469 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4471 * <table border=1 cellpadding=10 cellspacing=0>
4472 * <caption align=top>Distribution Statistics</caption>
4473 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4474 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4475 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4476 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4477 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4480 template<typename _RealType = double>
4481 class exponential_distribution
4483 static_assert(std::is_floating_point<_RealType>::value,
4484 "template argument not a floating point type");
4487 /** The type of the range of the distribution. */
4488 typedef _RealType result_type;
4489 /** Parameter type. */
4492 typedef exponential_distribution<_RealType> distribution_type;
4495 param_type(_RealType __lambda = _RealType(1))
4496 : _M_lambda(__lambda)
4498 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4503 { return _M_lambda; }
4506 operator==(const param_type& __p1, const param_type& __p2)
4507 { return __p1._M_lambda == __p2._M_lambda; }
4510 _RealType _M_lambda;
4515 * @brief Constructs an exponential distribution with inverse scale
4516 * parameter @f$\lambda@f$.
4519 exponential_distribution(const result_type& __lambda = result_type(1))
4520 : _M_param(__lambda)
4524 exponential_distribution(const param_type& __p)
4529 * @brief Resets the distribution state.
4531 * Has no effect on exponential distributions.
4537 * @brief Returns the inverse scale parameter of the distribution.
4541 { return _M_param.lambda(); }
4544 * @brief Returns the parameter set of the distribution.
4548 { return _M_param; }
4551 * @brief Sets the parameter set of the distribution.
4552 * @param __param The new parameter set of the distribution.
4555 param(const param_type& __param)
4556 { _M_param = __param; }
4559 * @brief Returns the greatest lower bound value of the distribution.
4563 { return result_type(0); }
4566 * @brief Returns the least upper bound value of the distribution.
4570 { return std::numeric_limits<result_type>::max(); }
4573 * @brief Generating functions.
4575 template<typename _UniformRandomNumberGenerator>
4577 operator()(_UniformRandomNumberGenerator& __urng)
4578 { return this->operator()(__urng, _M_param); }
4580 template<typename _UniformRandomNumberGenerator>
4582 operator()(_UniformRandomNumberGenerator& __urng,
4583 const param_type& __p)
4585 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4587 return -std::log(result_type(1) - __aurng()) / __p.lambda();
4590 template<typename _ForwardIterator,
4591 typename _UniformRandomNumberGenerator>
4593 __generate(_ForwardIterator __f, _ForwardIterator __t,
4594 _UniformRandomNumberGenerator& __urng)
4595 { this->__generate(__f, __t, __urng, _M_param); }
4597 template<typename _ForwardIterator,
4598 typename _UniformRandomNumberGenerator>
4600 __generate(_ForwardIterator __f, _ForwardIterator __t,
4601 _UniformRandomNumberGenerator& __urng,
4602 const param_type& __p)
4603 { this->__generate_impl(__f, __t, __urng, __p); }
4605 template<typename _UniformRandomNumberGenerator>
4607 __generate(result_type* __f, result_type* __t,
4608 _UniformRandomNumberGenerator& __urng,
4609 const param_type& __p)
4610 { this->__generate_impl(__f, __t, __urng, __p); }
4613 * @brief Return true if two exponential distributions have the same
4617 operator==(const exponential_distribution& __d1,
4618 const exponential_distribution& __d2)
4619 { return __d1._M_param == __d2._M_param; }
4622 template<typename _ForwardIterator,
4623 typename _UniformRandomNumberGenerator>
4625 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4626 _UniformRandomNumberGenerator& __urng,
4627 const param_type& __p);
4629 param_type _M_param;
4633 * @brief Return true if two exponential distributions have different
4636 template<typename _RealType>
4638 operator!=(const std::exponential_distribution<_RealType>& __d1,
4639 const std::exponential_distribution<_RealType>& __d2)
4640 { return !(__d1 == __d2); }
4643 * @brief Inserts a %exponential_distribution random number distribution
4644 * @p __x into the output stream @p __os.
4646 * @param __os An output stream.
4647 * @param __x A %exponential_distribution random number distribution.
4649 * @returns The output stream with the state of @p __x inserted or in
4652 template<typename _RealType, typename _CharT, typename _Traits>
4653 std::basic_ostream<_CharT, _Traits>&
4654 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4655 const std::exponential_distribution<_RealType>& __x);
4658 * @brief Extracts a %exponential_distribution random number distribution
4659 * @p __x from the input stream @p __is.
4661 * @param __is An input stream.
4662 * @param __x A %exponential_distribution random number
4665 * @returns The input stream with @p __x extracted or in an error state.
4667 template<typename _RealType, typename _CharT, typename _Traits>
4668 std::basic_istream<_CharT, _Traits>&
4669 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4670 std::exponential_distribution<_RealType>& __x);
4674 * @brief A weibull_distribution random number distribution.
4676 * The formula for the normal probability density function is:
4678 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4679 * \exp{(-(\frac{x}{\beta})^\alpha)}
4682 template<typename _RealType = double>
4683 class weibull_distribution
4685 static_assert(std::is_floating_point<_RealType>::value,
4686 "template argument not a floating point type");
4689 /** The type of the range of the distribution. */
4690 typedef _RealType result_type;
4691 /** Parameter type. */
4694 typedef weibull_distribution<_RealType> distribution_type;
4697 param_type(_RealType __a = _RealType(1),
4698 _RealType __b = _RealType(1))
4699 : _M_a(__a), _M_b(__b)
4711 operator==(const param_type& __p1, const param_type& __p2)
4712 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4720 weibull_distribution(_RealType __a = _RealType(1),
4721 _RealType __b = _RealType(1))
4722 : _M_param(__a, __b)
4726 weibull_distribution(const param_type& __p)
4731 * @brief Resets the distribution state.
4738 * @brief Return the @f$a@f$ parameter of the distribution.
4742 { return _M_param.a(); }
4745 * @brief Return the @f$b@f$ parameter of the distribution.
4749 { return _M_param.b(); }
4752 * @brief Returns the parameter set of the distribution.
4756 { return _M_param; }
4759 * @brief Sets the parameter set of the distribution.
4760 * @param __param The new parameter set of the distribution.
4763 param(const param_type& __param)
4764 { _M_param = __param; }
4767 * @brief Returns the greatest lower bound value of the distribution.
4771 { return result_type(0); }
4774 * @brief Returns the least upper bound value of the distribution.
4778 { return std::numeric_limits<result_type>::max(); }
4781 * @brief Generating functions.
4783 template<typename _UniformRandomNumberGenerator>
4785 operator()(_UniformRandomNumberGenerator& __urng)
4786 { return this->operator()(__urng, _M_param); }
4788 template<typename _UniformRandomNumberGenerator>
4790 operator()(_UniformRandomNumberGenerator& __urng,
4791 const param_type& __p);
4793 template<typename _ForwardIterator,
4794 typename _UniformRandomNumberGenerator>
4796 __generate(_ForwardIterator __f, _ForwardIterator __t,
4797 _UniformRandomNumberGenerator& __urng)
4798 { this->__generate(__f, __t, __urng, _M_param); }
4800 template<typename _ForwardIterator,
4801 typename _UniformRandomNumberGenerator>
4803 __generate(_ForwardIterator __f, _ForwardIterator __t,
4804 _UniformRandomNumberGenerator& __urng,
4805 const param_type& __p)
4806 { this->__generate_impl(__f, __t, __urng, __p); }
4808 template<typename _UniformRandomNumberGenerator>
4810 __generate(result_type* __f, result_type* __t,
4811 _UniformRandomNumberGenerator& __urng,
4812 const param_type& __p)
4813 { this->__generate_impl(__f, __t, __urng, __p); }
4816 * @brief Return true if two Weibull distributions have the same
4820 operator==(const weibull_distribution& __d1,
4821 const weibull_distribution& __d2)
4822 { return __d1._M_param == __d2._M_param; }
4825 template<typename _ForwardIterator,
4826 typename _UniformRandomNumberGenerator>
4828 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4829 _UniformRandomNumberGenerator& __urng,
4830 const param_type& __p);
4832 param_type _M_param;
4836 * @brief Return true if two Weibull distributions have different
4839 template<typename _RealType>
4841 operator!=(const std::weibull_distribution<_RealType>& __d1,
4842 const std::weibull_distribution<_RealType>& __d2)
4843 { return !(__d1 == __d2); }
4846 * @brief Inserts a %weibull_distribution random number distribution
4847 * @p __x into the output stream @p __os.
4849 * @param __os An output stream.
4850 * @param __x A %weibull_distribution random number distribution.
4852 * @returns The output stream with the state of @p __x inserted or in
4855 template<typename _RealType, typename _CharT, typename _Traits>
4856 std::basic_ostream<_CharT, _Traits>&
4857 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4858 const std::weibull_distribution<_RealType>& __x);
4861 * @brief Extracts a %weibull_distribution random number distribution
4862 * @p __x from the input stream @p __is.
4864 * @param __is An input stream.
4865 * @param __x A %weibull_distribution random number
4868 * @returns The input stream with @p __x extracted or in an error state.
4870 template<typename _RealType, typename _CharT, typename _Traits>
4871 std::basic_istream<_CharT, _Traits>&
4872 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4873 std::weibull_distribution<_RealType>& __x);
4877 * @brief A extreme_value_distribution random number distribution.
4879 * The formula for the normal probability mass function is
4881 * p(x|a,b) = \frac{1}{b}
4882 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4885 template<typename _RealType = double>
4886 class extreme_value_distribution
4888 static_assert(std::is_floating_point<_RealType>::value,
4889 "template argument not a floating point type");
4892 /** The type of the range of the distribution. */
4893 typedef _RealType result_type;
4894 /** Parameter type. */
4897 typedef extreme_value_distribution<_RealType> distribution_type;
4900 param_type(_RealType __a = _RealType(0),
4901 _RealType __b = _RealType(1))
4902 : _M_a(__a), _M_b(__b)
4914 operator==(const param_type& __p1, const param_type& __p2)
4915 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4923 extreme_value_distribution(_RealType __a = _RealType(0),
4924 _RealType __b = _RealType(1))
4925 : _M_param(__a, __b)
4929 extreme_value_distribution(const param_type& __p)
4934 * @brief Resets the distribution state.
4941 * @brief Return the @f$a@f$ parameter of the distribution.
4945 { return _M_param.a(); }
4948 * @brief Return the @f$b@f$ parameter of the distribution.
4952 { return _M_param.b(); }
4955 * @brief Returns the parameter set of the distribution.
4959 { return _M_param; }
4962 * @brief Sets the parameter set of the distribution.
4963 * @param __param The new parameter set of the distribution.
4966 param(const param_type& __param)
4967 { _M_param = __param; }
4970 * @brief Returns the greatest lower bound value of the distribution.
4974 { return std::numeric_limits<result_type>::lowest(); }
4977 * @brief Returns the least upper bound value of the distribution.
4981 { return std::numeric_limits<result_type>::max(); }
4984 * @brief Generating functions.
4986 template<typename _UniformRandomNumberGenerator>
4988 operator()(_UniformRandomNumberGenerator& __urng)
4989 { return this->operator()(__urng, _M_param); }
4991 template<typename _UniformRandomNumberGenerator>
4993 operator()(_UniformRandomNumberGenerator& __urng,
4994 const param_type& __p);
4996 template<typename _ForwardIterator,
4997 typename _UniformRandomNumberGenerator>
4999 __generate(_ForwardIterator __f, _ForwardIterator __t,
5000 _UniformRandomNumberGenerator& __urng)
5001 { this->__generate(__f, __t, __urng, _M_param); }
5003 template<typename _ForwardIterator,
5004 typename _UniformRandomNumberGenerator>
5006 __generate(_ForwardIterator __f, _ForwardIterator __t,
5007 _UniformRandomNumberGenerator& __urng,
5008 const param_type& __p)
5009 { this->__generate_impl(__f, __t, __urng, __p); }
5011 template<typename _UniformRandomNumberGenerator>
5013 __generate(result_type* __f, result_type* __t,
5014 _UniformRandomNumberGenerator& __urng,
5015 const param_type& __p)
5016 { this->__generate_impl(__f, __t, __urng, __p); }
5019 * @brief Return true if two extreme value distributions have the same
5023 operator==(const extreme_value_distribution& __d1,
5024 const extreme_value_distribution& __d2)
5025 { return __d1._M_param == __d2._M_param; }
5028 template<typename _ForwardIterator,
5029 typename _UniformRandomNumberGenerator>
5031 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5032 _UniformRandomNumberGenerator& __urng,
5033 const param_type& __p);
5035 param_type _M_param;
5039 * @brief Return true if two extreme value distributions have different
5042 template<typename _RealType>
5044 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
5045 const std::extreme_value_distribution<_RealType>& __d2)
5046 { return !(__d1 == __d2); }
5049 * @brief Inserts a %extreme_value_distribution random number distribution
5050 * @p __x into the output stream @p __os.
5052 * @param __os An output stream.
5053 * @param __x A %extreme_value_distribution random number distribution.
5055 * @returns The output stream with the state of @p __x inserted or in
5058 template<typename _RealType, typename _CharT, typename _Traits>
5059 std::basic_ostream<_CharT, _Traits>&
5060 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5061 const std::extreme_value_distribution<_RealType>& __x);
5064 * @brief Extracts a %extreme_value_distribution random number
5065 * distribution @p __x from the input stream @p __is.
5067 * @param __is An input stream.
5068 * @param __x A %extreme_value_distribution random number
5071 * @returns The input stream with @p __x extracted or in an error state.
5073 template<typename _RealType, typename _CharT, typename _Traits>
5074 std::basic_istream<_CharT, _Traits>&
5075 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5076 std::extreme_value_distribution<_RealType>& __x);
5080 * @brief A discrete_distribution random number distribution.
5082 * The formula for the discrete probability mass function is
5085 template<typename _IntType = int>
5086 class discrete_distribution
5088 static_assert(std::is_integral<_IntType>::value,
5089 "template argument not an integral type");
5092 /** The type of the range of the distribution. */
5093 typedef _IntType result_type;
5094 /** Parameter type. */
5097 typedef discrete_distribution<_IntType> distribution_type;
5098 friend class discrete_distribution<_IntType>;
5101 : _M_prob(), _M_cp()
5104 template<typename _InputIterator>
5105 param_type(_InputIterator __wbegin,
5106 _InputIterator __wend)
5107 : _M_prob(__wbegin, __wend), _M_cp()
5108 { _M_initialize(); }
5110 param_type(initializer_list<double> __wil)
5111 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
5112 { _M_initialize(); }
5114 template<typename _Func>
5115 param_type(size_t __nw, double __xmin, double __xmax,
5118 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5119 param_type(const param_type&) = default;
5120 param_type& operator=(const param_type&) = default;
5123 probabilities() const
5124 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
5127 operator==(const param_type& __p1, const param_type& __p2)
5128 { return __p1._M_prob == __p2._M_prob; }
5134 std::vector<double> _M_prob;
5135 std::vector<double> _M_cp;
5138 discrete_distribution()
5142 template<typename _InputIterator>
5143 discrete_distribution(_InputIterator __wbegin,
5144 _InputIterator __wend)
5145 : _M_param(__wbegin, __wend)
5148 discrete_distribution(initializer_list<double> __wl)
5152 template<typename _Func>
5153 discrete_distribution(size_t __nw, double __xmin, double __xmax,
5155 : _M_param(__nw, __xmin, __xmax, __fw)
5159 discrete_distribution(const param_type& __p)
5164 * @brief Resets the distribution state.
5171 * @brief Returns the probabilities of the distribution.
5174 probabilities() const
5176 return _M_param._M_prob.empty()
5177 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
5181 * @brief Returns the parameter set of the distribution.
5185 { return _M_param; }
5188 * @brief Sets the parameter set of the distribution.
5189 * @param __param The new parameter set of the distribution.
5192 param(const param_type& __param)
5193 { _M_param = __param; }
5196 * @brief Returns the greatest lower bound value of the distribution.
5200 { return result_type(0); }
5203 * @brief Returns the least upper bound value of the distribution.
5208 return _M_param._M_prob.empty()
5209 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
5213 * @brief Generating functions.
5215 template<typename _UniformRandomNumberGenerator>
5217 operator()(_UniformRandomNumberGenerator& __urng)
5218 { return this->operator()(__urng, _M_param); }
5220 template<typename _UniformRandomNumberGenerator>
5222 operator()(_UniformRandomNumberGenerator& __urng,
5223 const param_type& __p);
5225 template<typename _ForwardIterator,
5226 typename _UniformRandomNumberGenerator>
5228 __generate(_ForwardIterator __f, _ForwardIterator __t,
5229 _UniformRandomNumberGenerator& __urng)
5230 { this->__generate(__f, __t, __urng, _M_param); }
5232 template<typename _ForwardIterator,
5233 typename _UniformRandomNumberGenerator>
5235 __generate(_ForwardIterator __f, _ForwardIterator __t,
5236 _UniformRandomNumberGenerator& __urng,
5237 const param_type& __p)
5238 { this->__generate_impl(__f, __t, __urng, __p); }
5240 template<typename _UniformRandomNumberGenerator>
5242 __generate(result_type* __f, result_type* __t,
5243 _UniformRandomNumberGenerator& __urng,
5244 const param_type& __p)
5245 { this->__generate_impl(__f, __t, __urng, __p); }
5248 * @brief Return true if two discrete distributions have the same
5252 operator==(const discrete_distribution& __d1,
5253 const discrete_distribution& __d2)
5254 { return __d1._M_param == __d2._M_param; }
5257 * @brief Inserts a %discrete_distribution random number distribution
5258 * @p __x into the output stream @p __os.
5260 * @param __os An output stream.
5261 * @param __x A %discrete_distribution random number distribution.
5263 * @returns The output stream with the state of @p __x inserted or in
5266 template<typename _IntType1, typename _CharT, typename _Traits>
5267 friend std::basic_ostream<_CharT, _Traits>&
5268 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5269 const std::discrete_distribution<_IntType1>& __x);
5272 * @brief Extracts a %discrete_distribution random number distribution
5273 * @p __x from the input stream @p __is.
5275 * @param __is An input stream.
5276 * @param __x A %discrete_distribution random number
5279 * @returns The input stream with @p __x extracted or in an error
5282 template<typename _IntType1, typename _CharT, typename _Traits>
5283 friend std::basic_istream<_CharT, _Traits>&
5284 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5285 std::discrete_distribution<_IntType1>& __x);
5288 template<typename _ForwardIterator,
5289 typename _UniformRandomNumberGenerator>
5291 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5292 _UniformRandomNumberGenerator& __urng,
5293 const param_type& __p);
5295 param_type _M_param;
5299 * @brief Return true if two discrete distributions have different
5302 template<typename _IntType>
5304 operator!=(const std::discrete_distribution<_IntType>& __d1,
5305 const std::discrete_distribution<_IntType>& __d2)
5306 { return !(__d1 == __d2); }
5310 * @brief A piecewise_constant_distribution random number distribution.
5312 * The formula for the piecewise constant probability mass function is
5315 template<typename _RealType = double>
5316 class piecewise_constant_distribution
5318 static_assert(std::is_floating_point<_RealType>::value,
5319 "template argument not a floating point type");
5322 /** The type of the range of the distribution. */
5323 typedef _RealType result_type;
5324 /** Parameter type. */
5327 typedef piecewise_constant_distribution<_RealType> distribution_type;
5328 friend class piecewise_constant_distribution<_RealType>;
5331 : _M_int(), _M_den(), _M_cp()
5334 template<typename _InputIteratorB, typename _InputIteratorW>
5335 param_type(_InputIteratorB __bfirst,
5336 _InputIteratorB __bend,
5337 _InputIteratorW __wbegin);
5339 template<typename _Func>
5340 param_type(initializer_list<_RealType> __bi, _Func __fw);
5342 template<typename _Func>
5343 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5346 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5347 param_type(const param_type&) = default;
5348 param_type& operator=(const param_type&) = default;
5350 std::vector<_RealType>
5355 std::vector<_RealType> __tmp(2);
5356 __tmp[1] = _RealType(1);
5365 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
5368 operator==(const param_type& __p1, const param_type& __p2)
5369 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
5375 std::vector<_RealType> _M_int;
5376 std::vector<double> _M_den;
5377 std::vector<double> _M_cp;
5381 piecewise_constant_distribution()
5385 template<typename _InputIteratorB, typename _InputIteratorW>
5386 piecewise_constant_distribution(_InputIteratorB __bfirst,
5387 _InputIteratorB __bend,
5388 _InputIteratorW __wbegin)
5389 : _M_param(__bfirst, __bend, __wbegin)
5392 template<typename _Func>
5393 piecewise_constant_distribution(initializer_list<_RealType> __bl,
5395 : _M_param(__bl, __fw)
5398 template<typename _Func>
5399 piecewise_constant_distribution(size_t __nw,
5400 _RealType __xmin, _RealType __xmax,
5402 : _M_param(__nw, __xmin, __xmax, __fw)
5406 piecewise_constant_distribution(const param_type& __p)
5411 * @brief Resets the distribution state.
5418 * @brief Returns a vector of the intervals.
5420 std::vector<_RealType>
5423 if (_M_param._M_int.empty())
5425 std::vector<_RealType> __tmp(2);
5426 __tmp[1] = _RealType(1);
5430 return _M_param._M_int;
5434 * @brief Returns a vector of the probability densities.
5439 return _M_param._M_den.empty()
5440 ? std::vector<double>(1, 1.0) : _M_param._M_den;
5444 * @brief Returns the parameter set of the distribution.
5448 { return _M_param; }
5451 * @brief Sets the parameter set of the distribution.
5452 * @param __param The new parameter set of the distribution.
5455 param(const param_type& __param)
5456 { _M_param = __param; }
5459 * @brief Returns the greatest lower bound value of the distribution.
5464 return _M_param._M_int.empty()
5465 ? result_type(0) : _M_param._M_int.front();
5469 * @brief Returns the least upper bound value of the distribution.
5474 return _M_param._M_int.empty()
5475 ? result_type(1) : _M_param._M_int.back();
5479 * @brief Generating functions.
5481 template<typename _UniformRandomNumberGenerator>
5483 operator()(_UniformRandomNumberGenerator& __urng)
5484 { return this->operator()(__urng, _M_param); }
5486 template<typename _UniformRandomNumberGenerator>
5488 operator()(_UniformRandomNumberGenerator& __urng,
5489 const param_type& __p);
5491 template<typename _ForwardIterator,
5492 typename _UniformRandomNumberGenerator>
5494 __generate(_ForwardIterator __f, _ForwardIterator __t,
5495 _UniformRandomNumberGenerator& __urng)
5496 { this->__generate(__f, __t, __urng, _M_param); }
5498 template<typename _ForwardIterator,
5499 typename _UniformRandomNumberGenerator>
5501 __generate(_ForwardIterator __f, _ForwardIterator __t,
5502 _UniformRandomNumberGenerator& __urng,
5503 const param_type& __p)
5504 { this->__generate_impl(__f, __t, __urng, __p); }
5506 template<typename _UniformRandomNumberGenerator>
5508 __generate(result_type* __f, result_type* __t,
5509 _UniformRandomNumberGenerator& __urng,
5510 const param_type& __p)
5511 { this->__generate_impl(__f, __t, __urng, __p); }
5514 * @brief Return true if two piecewise constant distributions have the
5518 operator==(const piecewise_constant_distribution& __d1,
5519 const piecewise_constant_distribution& __d2)
5520 { return __d1._M_param == __d2._M_param; }
5523 * @brief Inserts a %piecewise_constant_distribution random
5524 * number distribution @p __x into the output stream @p __os.
5526 * @param __os An output stream.
5527 * @param __x A %piecewise_constant_distribution random number
5530 * @returns The output stream with the state of @p __x inserted or in
5533 template<typename _RealType1, typename _CharT, typename _Traits>
5534 friend std::basic_ostream<_CharT, _Traits>&
5535 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5536 const std::piecewise_constant_distribution<_RealType1>& __x);
5539 * @brief Extracts a %piecewise_constant_distribution random
5540 * number distribution @p __x from the input stream @p __is.
5542 * @param __is An input stream.
5543 * @param __x A %piecewise_constant_distribution random number
5546 * @returns The input stream with @p __x extracted or in an error
5549 template<typename _RealType1, typename _CharT, typename _Traits>
5550 friend std::basic_istream<_CharT, _Traits>&
5551 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5552 std::piecewise_constant_distribution<_RealType1>& __x);
5555 template<typename _ForwardIterator,
5556 typename _UniformRandomNumberGenerator>
5558 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5559 _UniformRandomNumberGenerator& __urng,
5560 const param_type& __p);
5562 param_type _M_param;
5566 * @brief Return true if two piecewise constant distributions have
5567 * different parameters.
5569 template<typename _RealType>
5571 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5572 const std::piecewise_constant_distribution<_RealType>& __d2)
5573 { return !(__d1 == __d2); }
5577 * @brief A piecewise_linear_distribution random number distribution.
5579 * The formula for the piecewise linear probability mass function is
5582 template<typename _RealType = double>
5583 class piecewise_linear_distribution
5585 static_assert(std::is_floating_point<_RealType>::value,
5586 "template argument not a floating point type");
5589 /** The type of the range of the distribution. */
5590 typedef _RealType result_type;
5591 /** Parameter type. */
5594 typedef piecewise_linear_distribution<_RealType> distribution_type;
5595 friend class piecewise_linear_distribution<_RealType>;
5598 : _M_int(), _M_den(), _M_cp(), _M_m()
5601 template<typename _InputIteratorB, typename _InputIteratorW>
5602 param_type(_InputIteratorB __bfirst,
5603 _InputIteratorB __bend,
5604 _InputIteratorW __wbegin);
5606 template<typename _Func>
5607 param_type(initializer_list<_RealType> __bl, _Func __fw);
5609 template<typename _Func>
5610 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5613 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5614 param_type(const param_type&) = default;
5615 param_type& operator=(const param_type&) = default;
5617 std::vector<_RealType>
5622 std::vector<_RealType> __tmp(2);
5623 __tmp[1] = _RealType(1);
5632 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5635 operator==(const param_type& __p1, const param_type& __p2)
5636 { return (__p1._M_int == __p2._M_int
5637 && __p1._M_den == __p2._M_den); }
5643 std::vector<_RealType> _M_int;
5644 std::vector<double> _M_den;
5645 std::vector<double> _M_cp;
5646 std::vector<double> _M_m;
5650 piecewise_linear_distribution()
5654 template<typename _InputIteratorB, typename _InputIteratorW>
5655 piecewise_linear_distribution(_InputIteratorB __bfirst,
5656 _InputIteratorB __bend,
5657 _InputIteratorW __wbegin)
5658 : _M_param(__bfirst, __bend, __wbegin)
5661 template<typename _Func>
5662 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5664 : _M_param(__bl, __fw)
5667 template<typename _Func>
5668 piecewise_linear_distribution(size_t __nw,
5669 _RealType __xmin, _RealType __xmax,
5671 : _M_param(__nw, __xmin, __xmax, __fw)
5675 piecewise_linear_distribution(const param_type& __p)
5680 * Resets the distribution state.
5687 * @brief Return the intervals of the distribution.
5689 std::vector<_RealType>
5692 if (_M_param._M_int.empty())
5694 std::vector<_RealType> __tmp(2);
5695 __tmp[1] = _RealType(1);
5699 return _M_param._M_int;
5703 * @brief Return a vector of the probability densities of the
5709 return _M_param._M_den.empty()
5710 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5714 * @brief Returns the parameter set of the distribution.
5718 { return _M_param; }
5721 * @brief Sets the parameter set of the distribution.
5722 * @param __param The new parameter set of the distribution.
5725 param(const param_type& __param)
5726 { _M_param = __param; }
5729 * @brief Returns the greatest lower bound value of the distribution.
5734 return _M_param._M_int.empty()
5735 ? result_type(0) : _M_param._M_int.front();
5739 * @brief Returns the least upper bound value of the distribution.
5744 return _M_param._M_int.empty()
5745 ? result_type(1) : _M_param._M_int.back();
5749 * @brief Generating functions.
5751 template<typename _UniformRandomNumberGenerator>
5753 operator()(_UniformRandomNumberGenerator& __urng)
5754 { return this->operator()(__urng, _M_param); }
5756 template<typename _UniformRandomNumberGenerator>
5758 operator()(_UniformRandomNumberGenerator& __urng,
5759 const param_type& __p);
5761 template<typename _ForwardIterator,
5762 typename _UniformRandomNumberGenerator>
5764 __generate(_ForwardIterator __f, _ForwardIterator __t,
5765 _UniformRandomNumberGenerator& __urng)
5766 { this->__generate(__f, __t, __urng, _M_param); }
5768 template<typename _ForwardIterator,
5769 typename _UniformRandomNumberGenerator>
5771 __generate(_ForwardIterator __f, _ForwardIterator __t,
5772 _UniformRandomNumberGenerator& __urng,
5773 const param_type& __p)
5774 { this->__generate_impl(__f, __t, __urng, __p); }
5776 template<typename _UniformRandomNumberGenerator>
5778 __generate(result_type* __f, result_type* __t,
5779 _UniformRandomNumberGenerator& __urng,
5780 const param_type& __p)
5781 { this->__generate_impl(__f, __t, __urng, __p); }
5784 * @brief Return true if two piecewise linear distributions have the
5788 operator==(const piecewise_linear_distribution& __d1,
5789 const piecewise_linear_distribution& __d2)
5790 { return __d1._M_param == __d2._M_param; }
5793 * @brief Inserts a %piecewise_linear_distribution random number
5794 * distribution @p __x into the output stream @p __os.
5796 * @param __os An output stream.
5797 * @param __x A %piecewise_linear_distribution random number
5800 * @returns The output stream with the state of @p __x inserted or in
5803 template<typename _RealType1, typename _CharT, typename _Traits>
5804 friend std::basic_ostream<_CharT, _Traits>&
5805 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5806 const std::piecewise_linear_distribution<_RealType1>& __x);
5809 * @brief Extracts a %piecewise_linear_distribution random number
5810 * distribution @p __x from the input stream @p __is.
5812 * @param __is An input stream.
5813 * @param __x A %piecewise_linear_distribution random number
5816 * @returns The input stream with @p __x extracted or in an error
5819 template<typename _RealType1, typename _CharT, typename _Traits>
5820 friend std::basic_istream<_CharT, _Traits>&
5821 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5822 std::piecewise_linear_distribution<_RealType1>& __x);
5825 template<typename _ForwardIterator,
5826 typename _UniformRandomNumberGenerator>
5828 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5829 _UniformRandomNumberGenerator& __urng,
5830 const param_type& __p);
5832 param_type _M_param;
5836 * @brief Return true if two piecewise linear distributions have
5837 * different parameters.
5839 template<typename _RealType>
5841 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5842 const std::piecewise_linear_distribution<_RealType>& __d2)
5843 { return !(__d1 == __d2); }
5846 /* @} */ // group random_distributions_poisson
5848 /* @} */ // group random_distributions
5851 * @addtogroup random_utilities Random Number Utilities
5857 * @brief The seed_seq class generates sequences of seeds for random
5858 * number generators.
5864 /** The type of the seed vales. */
5865 typedef uint_least32_t result_type;
5867 /** Default constructor. */
5872 template<typename _IntType>
5873 seed_seq(std::initializer_list<_IntType> il);
5875 template<typename _InputIterator>
5876 seed_seq(_InputIterator __begin, _InputIterator __end);
5878 // generating functions
5879 template<typename _RandomAccessIterator>
5881 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5883 // property functions
5885 { return _M_v.size(); }
5887 template<typename OutputIterator>
5889 param(OutputIterator __dest) const
5890 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5894 std::vector<result_type> _M_v;
5897 /* @} */ // group random_utilities
5899 /* @} */ // group random
5901 _GLIBCXX_END_NAMESPACE_VERSION