1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2017 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 must be 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
,
239 "result_type must be 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
,
447 "result_type must be 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
,
662 "result_type must be an unsigned integral type");
663 static_assert(0u < __s
&& __s
< __r
,
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
,
1069 "result_type must be 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 "result_type must be a floating point type");
1708 /** The type of the range of the distribution. */
1709 typedef _RealType result_type
;
1711 /** Parameter type. */
1714 typedef uniform_real_distribution
<_RealType
> distribution_type
;
1717 param_type(_RealType __a
= _RealType(0),
1718 _RealType __b
= _RealType(1))
1719 : _M_a(__a
), _M_b(__b
)
1721 __glibcxx_assert(_M_a
<= _M_b
);
1733 operator==(const param_type
& __p1
, const param_type
& __p2
)
1734 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1737 operator!=(const param_type
& __p1
, const param_type
& __p2
)
1738 { return !(__p1
== __p2
); }
1747 * @brief Constructs a uniform_real_distribution object.
1749 * @param __a [IN] The lower bound of the distribution.
1750 * @param __b [IN] The upper bound of the distribution.
1753 uniform_real_distribution(_RealType __a
= _RealType(0),
1754 _RealType __b
= _RealType(1))
1755 : _M_param(__a
, __b
)
1759 uniform_real_distribution(const param_type
& __p
)
1764 * @brief Resets the distribution state.
1766 * Does nothing for the uniform real distribution.
1773 { return _M_param
.a(); }
1777 { return _M_param
.b(); }
1780 * @brief Returns the parameter set of the distribution.
1784 { return _M_param
; }
1787 * @brief Sets the parameter set of the distribution.
1788 * @param __param The new parameter set of the distribution.
1791 param(const param_type
& __param
)
1792 { _M_param
= __param
; }
1795 * @brief Returns the inclusive lower bound of the distribution range.
1799 { return this->a(); }
1802 * @brief Returns the inclusive upper bound of the distribution range.
1806 { return this->b(); }
1809 * @brief Generating functions.
1811 template<typename _UniformRandomNumberGenerator
>
1813 operator()(_UniformRandomNumberGenerator
& __urng
)
1814 { return this->operator()(__urng
, _M_param
); }
1816 template<typename _UniformRandomNumberGenerator
>
1818 operator()(_UniformRandomNumberGenerator
& __urng
,
1819 const param_type
& __p
)
1821 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1823 return (__aurng() * (__p
.b() - __p
.a())) + __p
.a();
1826 template<typename _ForwardIterator
,
1827 typename _UniformRandomNumberGenerator
>
1829 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1830 _UniformRandomNumberGenerator
& __urng
)
1831 { this->__generate(__f
, __t
, __urng
, _M_param
); }
1833 template<typename _ForwardIterator
,
1834 typename _UniformRandomNumberGenerator
>
1836 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1837 _UniformRandomNumberGenerator
& __urng
,
1838 const param_type
& __p
)
1839 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1841 template<typename _UniformRandomNumberGenerator
>
1843 __generate(result_type
* __f
, result_type
* __t
,
1844 _UniformRandomNumberGenerator
& __urng
,
1845 const param_type
& __p
)
1846 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1849 * @brief Return true if two uniform real distributions have
1850 * the same parameters.
1853 operator==(const uniform_real_distribution
& __d1
,
1854 const uniform_real_distribution
& __d2
)
1855 { return __d1
._M_param
== __d2
._M_param
; }
1858 template<typename _ForwardIterator
,
1859 typename _UniformRandomNumberGenerator
>
1861 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
1862 _UniformRandomNumberGenerator
& __urng
,
1863 const param_type
& __p
);
1865 param_type _M_param
;
1869 * @brief Return true if two uniform real distributions have
1870 * different parameters.
1872 template<typename _IntType
>
1874 operator!=(const std::uniform_real_distribution
<_IntType
>& __d1
,
1875 const std::uniform_real_distribution
<_IntType
>& __d2
)
1876 { return !(__d1
== __d2
); }
1879 * @brief Inserts a %uniform_real_distribution random number
1880 * distribution @p __x into the output stream @p __os.
1882 * @param __os An output stream.
1883 * @param __x A %uniform_real_distribution random number distribution.
1885 * @returns The output stream with the state of @p __x inserted or in
1888 template<typename _RealType
, typename _CharT
, typename _Traits
>
1889 std::basic_ostream
<_CharT
, _Traits
>&
1890 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1891 const std::uniform_real_distribution
<_RealType
>&);
1894 * @brief Extracts a %uniform_real_distribution random number distribution
1895 * @p __x from the input stream @p __is.
1897 * @param __is An input stream.
1898 * @param __x A %uniform_real_distribution random number generator engine.
1900 * @returns The input stream with @p __x extracted or in an error state.
1902 template<typename _RealType
, typename _CharT
, typename _Traits
>
1903 std::basic_istream
<_CharT
, _Traits
>&
1904 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1905 std::uniform_real_distribution
<_RealType
>&);
1907 /* @} */ // group random_distributions_uniform
1910 * @addtogroup random_distributions_normal Normal Distributions
1911 * @ingroup random_distributions
1916 * @brief A normal continuous distribution for random numbers.
1918 * The formula for the normal probability density function is
1920 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1921 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1924 template<typename _RealType
= double>
1925 class normal_distribution
1927 static_assert(std::is_floating_point
<_RealType
>::value
,
1928 "result_type must be a floating point type");
1931 /** The type of the range of the distribution. */
1932 typedef _RealType result_type
;
1934 /** Parameter type. */
1937 typedef normal_distribution
<_RealType
> distribution_type
;
1940 param_type(_RealType __mean
= _RealType(0),
1941 _RealType __stddev
= _RealType(1))
1942 : _M_mean(__mean
), _M_stddev(__stddev
)
1944 __glibcxx_assert(_M_stddev
> _RealType(0));
1953 { return _M_stddev
; }
1956 operator==(const param_type
& __p1
, const param_type
& __p2
)
1957 { return (__p1
._M_mean
== __p2
._M_mean
1958 && __p1
._M_stddev
== __p2
._M_stddev
); }
1961 operator!=(const param_type
& __p1
, const param_type
& __p2
)
1962 { return !(__p1
== __p2
); }
1966 _RealType _M_stddev
;
1971 * Constructs a normal distribution with parameters @f$mean@f$ and
1972 * standard deviation.
1975 normal_distribution(result_type __mean
= result_type(0),
1976 result_type __stddev
= result_type(1))
1977 : _M_param(__mean
, __stddev
), _M_saved_available(false)
1981 normal_distribution(const param_type
& __p
)
1982 : _M_param(__p
), _M_saved_available(false)
1986 * @brief Resets the distribution state.
1990 { _M_saved_available
= false; }
1993 * @brief Returns the mean of the distribution.
1997 { return _M_param
.mean(); }
2000 * @brief Returns the standard deviation of the distribution.
2004 { return _M_param
.stddev(); }
2007 * @brief Returns the parameter set of the distribution.
2011 { return _M_param
; }
2014 * @brief Sets the parameter set of the distribution.
2015 * @param __param The new parameter set of the distribution.
2018 param(const param_type
& __param
)
2019 { _M_param
= __param
; }
2022 * @brief Returns the greatest lower bound value of the distribution.
2026 { return std::numeric_limits
<result_type
>::lowest(); }
2029 * @brief Returns the least upper bound value of the distribution.
2033 { return std::numeric_limits
<result_type
>::max(); }
2036 * @brief Generating functions.
2038 template<typename _UniformRandomNumberGenerator
>
2040 operator()(_UniformRandomNumberGenerator
& __urng
)
2041 { return this->operator()(__urng
, _M_param
); }
2043 template<typename _UniformRandomNumberGenerator
>
2045 operator()(_UniformRandomNumberGenerator
& __urng
,
2046 const param_type
& __p
);
2048 template<typename _ForwardIterator
,
2049 typename _UniformRandomNumberGenerator
>
2051 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2052 _UniformRandomNumberGenerator
& __urng
)
2053 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2055 template<typename _ForwardIterator
,
2056 typename _UniformRandomNumberGenerator
>
2058 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2059 _UniformRandomNumberGenerator
& __urng
,
2060 const param_type
& __p
)
2061 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2063 template<typename _UniformRandomNumberGenerator
>
2065 __generate(result_type
* __f
, result_type
* __t
,
2066 _UniformRandomNumberGenerator
& __urng
,
2067 const param_type
& __p
)
2068 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2071 * @brief Return true if two normal distributions have
2072 * the same parameters and the sequences that would
2073 * be generated are equal.
2075 template<typename _RealType1
>
2077 operator==(const std::normal_distribution
<_RealType1
>& __d1
,
2078 const std::normal_distribution
<_RealType1
>& __d2
);
2081 * @brief Inserts a %normal_distribution random number distribution
2082 * @p __x into the output stream @p __os.
2084 * @param __os An output stream.
2085 * @param __x A %normal_distribution random number distribution.
2087 * @returns The output stream with the state of @p __x inserted or in
2090 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2091 friend std::basic_ostream
<_CharT
, _Traits
>&
2092 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2093 const std::normal_distribution
<_RealType1
>& __x
);
2096 * @brief Extracts a %normal_distribution random number distribution
2097 * @p __x from the input stream @p __is.
2099 * @param __is An input stream.
2100 * @param __x A %normal_distribution random number generator engine.
2102 * @returns The input stream with @p __x extracted or in an error
2105 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2106 friend std::basic_istream
<_CharT
, _Traits
>&
2107 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2108 std::normal_distribution
<_RealType1
>& __x
);
2111 template<typename _ForwardIterator
,
2112 typename _UniformRandomNumberGenerator
>
2114 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2115 _UniformRandomNumberGenerator
& __urng
,
2116 const param_type
& __p
);
2118 param_type _M_param
;
2119 result_type _M_saved
;
2120 bool _M_saved_available
;
2124 * @brief Return true if two normal distributions are different.
2126 template<typename _RealType
>
2128 operator!=(const std::normal_distribution
<_RealType
>& __d1
,
2129 const std::normal_distribution
<_RealType
>& __d2
)
2130 { return !(__d1
== __d2
); }
2134 * @brief A lognormal_distribution random number distribution.
2136 * The formula for the normal probability mass function is
2138 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2139 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2142 template<typename _RealType
= double>
2143 class lognormal_distribution
2145 static_assert(std::is_floating_point
<_RealType
>::value
,
2146 "result_type must be a floating point type");
2149 /** The type of the range of the distribution. */
2150 typedef _RealType result_type
;
2152 /** Parameter type. */
2155 typedef lognormal_distribution
<_RealType
> distribution_type
;
2158 param_type(_RealType __m
= _RealType(0),
2159 _RealType __s
= _RealType(1))
2160 : _M_m(__m
), _M_s(__s
)
2172 operator==(const param_type
& __p1
, const param_type
& __p2
)
2173 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_s
== __p2
._M_s
; }
2176 operator!=(const param_type
& __p1
, const param_type
& __p2
)
2177 { return !(__p1
== __p2
); }
2185 lognormal_distribution(_RealType __m
= _RealType(0),
2186 _RealType __s
= _RealType(1))
2187 : _M_param(__m
, __s
), _M_nd()
2191 lognormal_distribution(const param_type
& __p
)
2192 : _M_param(__p
), _M_nd()
2196 * Resets the distribution state.
2207 { return _M_param
.m(); }
2211 { return _M_param
.s(); }
2214 * @brief Returns the parameter set of the distribution.
2218 { return _M_param
; }
2221 * @brief Sets the parameter set of the distribution.
2222 * @param __param The new parameter set of the distribution.
2225 param(const param_type
& __param
)
2226 { _M_param
= __param
; }
2229 * @brief Returns the greatest lower bound value of the distribution.
2233 { return result_type(0); }
2236 * @brief Returns the least upper bound value of the distribution.
2240 { return std::numeric_limits
<result_type
>::max(); }
2243 * @brief Generating functions.
2245 template<typename _UniformRandomNumberGenerator
>
2247 operator()(_UniformRandomNumberGenerator
& __urng
)
2248 { return this->operator()(__urng
, _M_param
); }
2250 template<typename _UniformRandomNumberGenerator
>
2252 operator()(_UniformRandomNumberGenerator
& __urng
,
2253 const param_type
& __p
)
2254 { return std::exp(__p
.s() * _M_nd(__urng
) + __p
.m()); }
2256 template<typename _ForwardIterator
,
2257 typename _UniformRandomNumberGenerator
>
2259 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2260 _UniformRandomNumberGenerator
& __urng
)
2261 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2263 template<typename _ForwardIterator
,
2264 typename _UniformRandomNumberGenerator
>
2266 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2267 _UniformRandomNumberGenerator
& __urng
,
2268 const param_type
& __p
)
2269 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2271 template<typename _UniformRandomNumberGenerator
>
2273 __generate(result_type
* __f
, result_type
* __t
,
2274 _UniformRandomNumberGenerator
& __urng
,
2275 const param_type
& __p
)
2276 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2279 * @brief Return true if two lognormal distributions have
2280 * the same parameters and the sequences that would
2281 * be generated are equal.
2284 operator==(const lognormal_distribution
& __d1
,
2285 const lognormal_distribution
& __d2
)
2286 { return (__d1
._M_param
== __d2
._M_param
2287 && __d1
._M_nd
== __d2
._M_nd
); }
2290 * @brief Inserts a %lognormal_distribution random number distribution
2291 * @p __x into the output stream @p __os.
2293 * @param __os An output stream.
2294 * @param __x A %lognormal_distribution random number distribution.
2296 * @returns The output stream with the state of @p __x inserted or in
2299 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2300 friend std::basic_ostream
<_CharT
, _Traits
>&
2301 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2302 const std::lognormal_distribution
<_RealType1
>& __x
);
2305 * @brief Extracts a %lognormal_distribution random number distribution
2306 * @p __x from the input stream @p __is.
2308 * @param __is An input stream.
2309 * @param __x A %lognormal_distribution random number
2312 * @returns The input stream with @p __x extracted or in an error state.
2314 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2315 friend std::basic_istream
<_CharT
, _Traits
>&
2316 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2317 std::lognormal_distribution
<_RealType1
>& __x
);
2320 template<typename _ForwardIterator
,
2321 typename _UniformRandomNumberGenerator
>
2323 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2324 _UniformRandomNumberGenerator
& __urng
,
2325 const param_type
& __p
);
2327 param_type _M_param
;
2329 std::normal_distribution
<result_type
> _M_nd
;
2333 * @brief Return true if two lognormal distributions are different.
2335 template<typename _RealType
>
2337 operator!=(const std::lognormal_distribution
<_RealType
>& __d1
,
2338 const std::lognormal_distribution
<_RealType
>& __d2
)
2339 { return !(__d1
== __d2
); }
2343 * @brief A gamma continuous distribution for random numbers.
2345 * The formula for the gamma probability density function is:
2347 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2348 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2351 template<typename _RealType
= double>
2352 class gamma_distribution
2354 static_assert(std::is_floating_point
<_RealType
>::value
,
2355 "result_type must be a floating point type");
2358 /** The type of the range of the distribution. */
2359 typedef _RealType result_type
;
2361 /** Parameter type. */
2364 typedef gamma_distribution
<_RealType
> distribution_type
;
2365 friend class gamma_distribution
<_RealType
>;
2368 param_type(_RealType __alpha_val
= _RealType(1),
2369 _RealType __beta_val
= _RealType(1))
2370 : _M_alpha(__alpha_val
), _M_beta(__beta_val
)
2372 __glibcxx_assert(_M_alpha
> _RealType(0));
2378 { return _M_alpha
; }
2385 operator==(const param_type
& __p1
, const param_type
& __p2
)
2386 { return (__p1
._M_alpha
== __p2
._M_alpha
2387 && __p1
._M_beta
== __p2
._M_beta
); }
2390 operator!=(const param_type
& __p1
, const param_type
& __p2
)
2391 { return !(__p1
== __p2
); }
2400 _RealType _M_malpha
, _M_a2
;
2405 * @brief Constructs a gamma distribution with parameters
2406 * @f$\alpha@f$ and @f$\beta@f$.
2409 gamma_distribution(_RealType __alpha_val
= _RealType(1),
2410 _RealType __beta_val
= _RealType(1))
2411 : _M_param(__alpha_val
, __beta_val
), _M_nd()
2415 gamma_distribution(const param_type
& __p
)
2416 : _M_param(__p
), _M_nd()
2420 * @brief Resets the distribution state.
2427 * @brief Returns the @f$\alpha@f$ of the distribution.
2431 { return _M_param
.alpha(); }
2434 * @brief Returns the @f$\beta@f$ of the distribution.
2438 { return _M_param
.beta(); }
2441 * @brief Returns the parameter set of the distribution.
2445 { return _M_param
; }
2448 * @brief Sets the parameter set of the distribution.
2449 * @param __param The new parameter set of the distribution.
2452 param(const param_type
& __param
)
2453 { _M_param
= __param
; }
2456 * @brief Returns the greatest lower bound value of the distribution.
2460 { return result_type(0); }
2463 * @brief Returns the least upper bound value of the distribution.
2467 { return std::numeric_limits
<result_type
>::max(); }
2470 * @brief Generating functions.
2472 template<typename _UniformRandomNumberGenerator
>
2474 operator()(_UniformRandomNumberGenerator
& __urng
)
2475 { return this->operator()(__urng
, _M_param
); }
2477 template<typename _UniformRandomNumberGenerator
>
2479 operator()(_UniformRandomNumberGenerator
& __urng
,
2480 const param_type
& __p
);
2482 template<typename _ForwardIterator
,
2483 typename _UniformRandomNumberGenerator
>
2485 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2486 _UniformRandomNumberGenerator
& __urng
)
2487 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2489 template<typename _ForwardIterator
,
2490 typename _UniformRandomNumberGenerator
>
2492 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2493 _UniformRandomNumberGenerator
& __urng
,
2494 const param_type
& __p
)
2495 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2497 template<typename _UniformRandomNumberGenerator
>
2499 __generate(result_type
* __f
, result_type
* __t
,
2500 _UniformRandomNumberGenerator
& __urng
,
2501 const param_type
& __p
)
2502 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2505 * @brief Return true if two gamma distributions have the same
2506 * parameters and the sequences that would be generated
2510 operator==(const gamma_distribution
& __d1
,
2511 const gamma_distribution
& __d2
)
2512 { return (__d1
._M_param
== __d2
._M_param
2513 && __d1
._M_nd
== __d2
._M_nd
); }
2516 * @brief Inserts a %gamma_distribution random number distribution
2517 * @p __x into the output stream @p __os.
2519 * @param __os An output stream.
2520 * @param __x A %gamma_distribution random number distribution.
2522 * @returns The output stream with the state of @p __x inserted or in
2525 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2526 friend std::basic_ostream
<_CharT
, _Traits
>&
2527 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2528 const std::gamma_distribution
<_RealType1
>& __x
);
2531 * @brief Extracts a %gamma_distribution random number distribution
2532 * @p __x from the input stream @p __is.
2534 * @param __is An input stream.
2535 * @param __x A %gamma_distribution random number generator engine.
2537 * @returns The input stream with @p __x extracted or in an error state.
2539 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2540 friend std::basic_istream
<_CharT
, _Traits
>&
2541 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2542 std::gamma_distribution
<_RealType1
>& __x
);
2545 template<typename _ForwardIterator
,
2546 typename _UniformRandomNumberGenerator
>
2548 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2549 _UniformRandomNumberGenerator
& __urng
,
2550 const param_type
& __p
);
2552 param_type _M_param
;
2554 std::normal_distribution
<result_type
> _M_nd
;
2558 * @brief Return true if two gamma distributions are different.
2560 template<typename _RealType
>
2562 operator!=(const std::gamma_distribution
<_RealType
>& __d1
,
2563 const std::gamma_distribution
<_RealType
>& __d2
)
2564 { return !(__d1
== __d2
); }
2568 * @brief A chi_squared_distribution random number distribution.
2570 * The formula for the normal probability mass function is
2571 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2573 template<typename _RealType
= double>
2574 class chi_squared_distribution
2576 static_assert(std::is_floating_point
<_RealType
>::value
,
2577 "result_type must be a floating point type");
2580 /** The type of the range of the distribution. */
2581 typedef _RealType result_type
;
2583 /** Parameter type. */
2586 typedef chi_squared_distribution
<_RealType
> distribution_type
;
2589 param_type(_RealType __n
= _RealType(1))
2598 operator==(const param_type
& __p1
, const param_type
& __p2
)
2599 { return __p1
._M_n
== __p2
._M_n
; }
2602 operator!=(const param_type
& __p1
, const param_type
& __p2
)
2603 { return !(__p1
== __p2
); }
2610 chi_squared_distribution(_RealType __n
= _RealType(1))
2611 : _M_param(__n
), _M_gd(__n
/ 2)
2615 chi_squared_distribution(const param_type
& __p
)
2616 : _M_param(__p
), _M_gd(__p
.n() / 2)
2620 * @brief Resets the distribution state.
2631 { return _M_param
.n(); }
2634 * @brief Returns the parameter set of the distribution.
2638 { return _M_param
; }
2641 * @brief Sets the parameter set of the distribution.
2642 * @param __param The new parameter set of the distribution.
2645 param(const param_type
& __param
)
2646 { _M_param
= __param
; }
2649 * @brief Returns the greatest lower bound value of the distribution.
2653 { return result_type(0); }
2656 * @brief Returns the least upper bound value of the distribution.
2660 { return std::numeric_limits
<result_type
>::max(); }
2663 * @brief Generating functions.
2665 template<typename _UniformRandomNumberGenerator
>
2667 operator()(_UniformRandomNumberGenerator
& __urng
)
2668 { return 2 * _M_gd(__urng
); }
2670 template<typename _UniformRandomNumberGenerator
>
2672 operator()(_UniformRandomNumberGenerator
& __urng
,
2673 const param_type
& __p
)
2675 typedef typename
std::gamma_distribution
<result_type
>::param_type
2677 return 2 * _M_gd(__urng
, param_type(__p
.n() / 2));
2680 template<typename _ForwardIterator
,
2681 typename _UniformRandomNumberGenerator
>
2683 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2684 _UniformRandomNumberGenerator
& __urng
)
2685 { this->__generate_impl(__f
, __t
, __urng
); }
2687 template<typename _ForwardIterator
,
2688 typename _UniformRandomNumberGenerator
>
2690 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2691 _UniformRandomNumberGenerator
& __urng
,
2692 const param_type
& __p
)
2693 { typename
std::gamma_distribution
<result_type
>::param_type
2695 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2697 template<typename _UniformRandomNumberGenerator
>
2699 __generate(result_type
* __f
, result_type
* __t
,
2700 _UniformRandomNumberGenerator
& __urng
)
2701 { this->__generate_impl(__f
, __t
, __urng
); }
2703 template<typename _UniformRandomNumberGenerator
>
2705 __generate(result_type
* __f
, result_type
* __t
,
2706 _UniformRandomNumberGenerator
& __urng
,
2707 const param_type
& __p
)
2708 { typename
std::gamma_distribution
<result_type
>::param_type
2710 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2713 * @brief Return true if two Chi-squared distributions have
2714 * the same parameters and the sequences that would be
2715 * generated are equal.
2718 operator==(const chi_squared_distribution
& __d1
,
2719 const chi_squared_distribution
& __d2
)
2720 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
2723 * @brief Inserts a %chi_squared_distribution random number distribution
2724 * @p __x into the output stream @p __os.
2726 * @param __os An output stream.
2727 * @param __x A %chi_squared_distribution random number distribution.
2729 * @returns The output stream with the state of @p __x inserted or in
2732 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2733 friend std::basic_ostream
<_CharT
, _Traits
>&
2734 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2735 const std::chi_squared_distribution
<_RealType1
>& __x
);
2738 * @brief Extracts a %chi_squared_distribution random number distribution
2739 * @p __x from the input stream @p __is.
2741 * @param __is An input stream.
2742 * @param __x A %chi_squared_distribution random number
2745 * @returns The input stream with @p __x extracted or in an error state.
2747 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2748 friend std::basic_istream
<_CharT
, _Traits
>&
2749 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2750 std::chi_squared_distribution
<_RealType1
>& __x
);
2753 template<typename _ForwardIterator
,
2754 typename _UniformRandomNumberGenerator
>
2756 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2757 _UniformRandomNumberGenerator
& __urng
);
2759 template<typename _ForwardIterator
,
2760 typename _UniformRandomNumberGenerator
>
2762 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2763 _UniformRandomNumberGenerator
& __urng
,
2765 std::gamma_distribution
<result_type
>::param_type
& __p
);
2767 param_type _M_param
;
2769 std::gamma_distribution
<result_type
> _M_gd
;
2773 * @brief Return true if two Chi-squared distributions are different.
2775 template<typename _RealType
>
2777 operator!=(const std::chi_squared_distribution
<_RealType
>& __d1
,
2778 const std::chi_squared_distribution
<_RealType
>& __d2
)
2779 { return !(__d1
== __d2
); }
2783 * @brief A cauchy_distribution random number distribution.
2785 * The formula for the normal probability mass function is
2786 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2788 template<typename _RealType
= double>
2789 class cauchy_distribution
2791 static_assert(std::is_floating_point
<_RealType
>::value
,
2792 "result_type must be a floating point type");
2795 /** The type of the range of the distribution. */
2796 typedef _RealType result_type
;
2798 /** Parameter type. */
2801 typedef cauchy_distribution
<_RealType
> distribution_type
;
2804 param_type(_RealType __a
= _RealType(0),
2805 _RealType __b
= _RealType(1))
2806 : _M_a(__a
), _M_b(__b
)
2818 operator==(const param_type
& __p1
, const param_type
& __p2
)
2819 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
2822 operator!=(const param_type
& __p1
, const param_type
& __p2
)
2823 { return !(__p1
== __p2
); }
2831 cauchy_distribution(_RealType __a
= _RealType(0),
2832 _RealType __b
= _RealType(1))
2833 : _M_param(__a
, __b
)
2837 cauchy_distribution(const param_type
& __p
)
2842 * @brief Resets the distribution state.
2853 { return _M_param
.a(); }
2857 { return _M_param
.b(); }
2860 * @brief Returns the parameter set of the distribution.
2864 { return _M_param
; }
2867 * @brief Sets the parameter set of the distribution.
2868 * @param __param The new parameter set of the distribution.
2871 param(const param_type
& __param
)
2872 { _M_param
= __param
; }
2875 * @brief Returns the greatest lower bound value of the distribution.
2879 { return std::numeric_limits
<result_type
>::lowest(); }
2882 * @brief Returns the least upper bound value of the distribution.
2886 { return std::numeric_limits
<result_type
>::max(); }
2889 * @brief Generating functions.
2891 template<typename _UniformRandomNumberGenerator
>
2893 operator()(_UniformRandomNumberGenerator
& __urng
)
2894 { return this->operator()(__urng
, _M_param
); }
2896 template<typename _UniformRandomNumberGenerator
>
2898 operator()(_UniformRandomNumberGenerator
& __urng
,
2899 const param_type
& __p
);
2901 template<typename _ForwardIterator
,
2902 typename _UniformRandomNumberGenerator
>
2904 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2905 _UniformRandomNumberGenerator
& __urng
)
2906 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2908 template<typename _ForwardIterator
,
2909 typename _UniformRandomNumberGenerator
>
2911 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2912 _UniformRandomNumberGenerator
& __urng
,
2913 const param_type
& __p
)
2914 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2916 template<typename _UniformRandomNumberGenerator
>
2918 __generate(result_type
* __f
, result_type
* __t
,
2919 _UniformRandomNumberGenerator
& __urng
,
2920 const param_type
& __p
)
2921 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2924 * @brief Return true if two Cauchy distributions have
2925 * the same parameters.
2928 operator==(const cauchy_distribution
& __d1
,
2929 const cauchy_distribution
& __d2
)
2930 { return __d1
._M_param
== __d2
._M_param
; }
2933 template<typename _ForwardIterator
,
2934 typename _UniformRandomNumberGenerator
>
2936 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2937 _UniformRandomNumberGenerator
& __urng
,
2938 const param_type
& __p
);
2940 param_type _M_param
;
2944 * @brief Return true if two Cauchy distributions have
2945 * different parameters.
2947 template<typename _RealType
>
2949 operator!=(const std::cauchy_distribution
<_RealType
>& __d1
,
2950 const std::cauchy_distribution
<_RealType
>& __d2
)
2951 { return !(__d1
== __d2
); }
2954 * @brief Inserts a %cauchy_distribution random number distribution
2955 * @p __x into the output stream @p __os.
2957 * @param __os An output stream.
2958 * @param __x A %cauchy_distribution random number distribution.
2960 * @returns The output stream with the state of @p __x inserted or in
2963 template<typename _RealType
, typename _CharT
, typename _Traits
>
2964 std::basic_ostream
<_CharT
, _Traits
>&
2965 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2966 const std::cauchy_distribution
<_RealType
>& __x
);
2969 * @brief Extracts a %cauchy_distribution random number distribution
2970 * @p __x from the input stream @p __is.
2972 * @param __is An input stream.
2973 * @param __x A %cauchy_distribution random number
2976 * @returns The input stream with @p __x extracted or in an error state.
2978 template<typename _RealType
, typename _CharT
, typename _Traits
>
2979 std::basic_istream
<_CharT
, _Traits
>&
2980 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2981 std::cauchy_distribution
<_RealType
>& __x
);
2985 * @brief A fisher_f_distribution random number distribution.
2987 * The formula for the normal probability mass function is
2989 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2990 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2991 * (1 + \frac{mx}{n})^{-(m+n)/2}
2994 template<typename _RealType
= double>
2995 class fisher_f_distribution
2997 static_assert(std::is_floating_point
<_RealType
>::value
,
2998 "result_type must be a floating point type");
3001 /** The type of the range of the distribution. */
3002 typedef _RealType result_type
;
3004 /** Parameter type. */
3007 typedef fisher_f_distribution
<_RealType
> distribution_type
;
3010 param_type(_RealType __m
= _RealType(1),
3011 _RealType __n
= _RealType(1))
3012 : _M_m(__m
), _M_n(__n
)
3024 operator==(const param_type
& __p1
, const param_type
& __p2
)
3025 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_n
== __p2
._M_n
; }
3028 operator!=(const param_type
& __p1
, const param_type
& __p2
)
3029 { return !(__p1
== __p2
); }
3037 fisher_f_distribution(_RealType __m
= _RealType(1),
3038 _RealType __n
= _RealType(1))
3039 : _M_param(__m
, __n
), _M_gd_x(__m
/ 2), _M_gd_y(__n
/ 2)
3043 fisher_f_distribution(const param_type
& __p
)
3044 : _M_param(__p
), _M_gd_x(__p
.m() / 2), _M_gd_y(__p
.n() / 2)
3048 * @brief Resets the distribution state.
3062 { return _M_param
.m(); }
3066 { return _M_param
.n(); }
3069 * @brief Returns the parameter set of the distribution.
3073 { return _M_param
; }
3076 * @brief Sets the parameter set of the distribution.
3077 * @param __param The new parameter set of the distribution.
3080 param(const param_type
& __param
)
3081 { _M_param
= __param
; }
3084 * @brief Returns the greatest lower bound value of the distribution.
3088 { return result_type(0); }
3091 * @brief Returns the least upper bound value of the distribution.
3095 { return std::numeric_limits
<result_type
>::max(); }
3098 * @brief Generating functions.
3100 template<typename _UniformRandomNumberGenerator
>
3102 operator()(_UniformRandomNumberGenerator
& __urng
)
3103 { return (_M_gd_x(__urng
) * n()) / (_M_gd_y(__urng
) * m()); }
3105 template<typename _UniformRandomNumberGenerator
>
3107 operator()(_UniformRandomNumberGenerator
& __urng
,
3108 const param_type
& __p
)
3110 typedef typename
std::gamma_distribution
<result_type
>::param_type
3112 return ((_M_gd_x(__urng
, param_type(__p
.m() / 2)) * n())
3113 / (_M_gd_y(__urng
, param_type(__p
.n() / 2)) * m()));
3116 template<typename _ForwardIterator
,
3117 typename _UniformRandomNumberGenerator
>
3119 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3120 _UniformRandomNumberGenerator
& __urng
)
3121 { this->__generate_impl(__f
, __t
, __urng
); }
3123 template<typename _ForwardIterator
,
3124 typename _UniformRandomNumberGenerator
>
3126 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3127 _UniformRandomNumberGenerator
& __urng
,
3128 const param_type
& __p
)
3129 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3131 template<typename _UniformRandomNumberGenerator
>
3133 __generate(result_type
* __f
, result_type
* __t
,
3134 _UniformRandomNumberGenerator
& __urng
)
3135 { this->__generate_impl(__f
, __t
, __urng
); }
3137 template<typename _UniformRandomNumberGenerator
>
3139 __generate(result_type
* __f
, result_type
* __t
,
3140 _UniformRandomNumberGenerator
& __urng
,
3141 const param_type
& __p
)
3142 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3145 * @brief Return true if two Fisher f distributions have
3146 * the same parameters and the sequences that would
3147 * be generated are equal.
3150 operator==(const fisher_f_distribution
& __d1
,
3151 const fisher_f_distribution
& __d2
)
3152 { return (__d1
._M_param
== __d2
._M_param
3153 && __d1
._M_gd_x
== __d2
._M_gd_x
3154 && __d1
._M_gd_y
== __d2
._M_gd_y
); }
3157 * @brief Inserts a %fisher_f_distribution random number distribution
3158 * @p __x into the output stream @p __os.
3160 * @param __os An output stream.
3161 * @param __x A %fisher_f_distribution random number distribution.
3163 * @returns The output stream with the state of @p __x inserted or in
3166 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3167 friend std::basic_ostream
<_CharT
, _Traits
>&
3168 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3169 const std::fisher_f_distribution
<_RealType1
>& __x
);
3172 * @brief Extracts a %fisher_f_distribution random number distribution
3173 * @p __x from the input stream @p __is.
3175 * @param __is An input stream.
3176 * @param __x A %fisher_f_distribution random number
3179 * @returns The input stream with @p __x extracted or in an error state.
3181 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3182 friend std::basic_istream
<_CharT
, _Traits
>&
3183 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3184 std::fisher_f_distribution
<_RealType1
>& __x
);
3187 template<typename _ForwardIterator
,
3188 typename _UniformRandomNumberGenerator
>
3190 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3191 _UniformRandomNumberGenerator
& __urng
);
3193 template<typename _ForwardIterator
,
3194 typename _UniformRandomNumberGenerator
>
3196 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3197 _UniformRandomNumberGenerator
& __urng
,
3198 const param_type
& __p
);
3200 param_type _M_param
;
3202 std::gamma_distribution
<result_type
> _M_gd_x
, _M_gd_y
;
3206 * @brief Return true if two Fisher f distributions are different.
3208 template<typename _RealType
>
3210 operator!=(const std::fisher_f_distribution
<_RealType
>& __d1
,
3211 const std::fisher_f_distribution
<_RealType
>& __d2
)
3212 { return !(__d1
== __d2
); }
3215 * @brief A student_t_distribution random number distribution.
3217 * The formula for the normal probability mass function is:
3219 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3220 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3223 template<typename _RealType
= double>
3224 class student_t_distribution
3226 static_assert(std::is_floating_point
<_RealType
>::value
,
3227 "result_type must be a floating point type");
3230 /** The type of the range of the distribution. */
3231 typedef _RealType result_type
;
3233 /** Parameter type. */
3236 typedef student_t_distribution
<_RealType
> distribution_type
;
3239 param_type(_RealType __n
= _RealType(1))
3248 operator==(const param_type
& __p1
, const param_type
& __p2
)
3249 { return __p1
._M_n
== __p2
._M_n
; }
3252 operator!=(const param_type
& __p1
, const param_type
& __p2
)
3253 { return !(__p1
== __p2
); }
3260 student_t_distribution(_RealType __n
= _RealType(1))
3261 : _M_param(__n
), _M_nd(), _M_gd(__n
/ 2, 2)
3265 student_t_distribution(const param_type
& __p
)
3266 : _M_param(__p
), _M_nd(), _M_gd(__p
.n() / 2, 2)
3270 * @brief Resets the distribution state.
3284 { return _M_param
.n(); }
3287 * @brief Returns the parameter set of the distribution.
3291 { return _M_param
; }
3294 * @brief Sets the parameter set of the distribution.
3295 * @param __param The new parameter set of the distribution.
3298 param(const param_type
& __param
)
3299 { _M_param
= __param
; }
3302 * @brief Returns the greatest lower bound value of the distribution.
3306 { return std::numeric_limits
<result_type
>::lowest(); }
3309 * @brief Returns the least upper bound value of the distribution.
3313 { return std::numeric_limits
<result_type
>::max(); }
3316 * @brief Generating functions.
3318 template<typename _UniformRandomNumberGenerator
>
3320 operator()(_UniformRandomNumberGenerator
& __urng
)
3321 { return _M_nd(__urng
) * std::sqrt(n() / _M_gd(__urng
)); }
3323 template<typename _UniformRandomNumberGenerator
>
3325 operator()(_UniformRandomNumberGenerator
& __urng
,
3326 const param_type
& __p
)
3328 typedef typename
std::gamma_distribution
<result_type
>::param_type
3331 const result_type __g
= _M_gd(__urng
, param_type(__p
.n() / 2, 2));
3332 return _M_nd(__urng
) * std::sqrt(__p
.n() / __g
);
3335 template<typename _ForwardIterator
,
3336 typename _UniformRandomNumberGenerator
>
3338 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3339 _UniformRandomNumberGenerator
& __urng
)
3340 { this->__generate_impl(__f
, __t
, __urng
); }
3342 template<typename _ForwardIterator
,
3343 typename _UniformRandomNumberGenerator
>
3345 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3346 _UniformRandomNumberGenerator
& __urng
,
3347 const param_type
& __p
)
3348 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3350 template<typename _UniformRandomNumberGenerator
>
3352 __generate(result_type
* __f
, result_type
* __t
,
3353 _UniformRandomNumberGenerator
& __urng
)
3354 { this->__generate_impl(__f
, __t
, __urng
); }
3356 template<typename _UniformRandomNumberGenerator
>
3358 __generate(result_type
* __f
, result_type
* __t
,
3359 _UniformRandomNumberGenerator
& __urng
,
3360 const param_type
& __p
)
3361 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3364 * @brief Return true if two Student t distributions have
3365 * the same parameters and the sequences that would
3366 * be generated are equal.
3369 operator==(const student_t_distribution
& __d1
,
3370 const student_t_distribution
& __d2
)
3371 { return (__d1
._M_param
== __d2
._M_param
3372 && __d1
._M_nd
== __d2
._M_nd
&& __d1
._M_gd
== __d2
._M_gd
); }
3375 * @brief Inserts a %student_t_distribution random number distribution
3376 * @p __x into the output stream @p __os.
3378 * @param __os An output stream.
3379 * @param __x A %student_t_distribution random number distribution.
3381 * @returns The output stream with the state of @p __x inserted or in
3384 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3385 friend std::basic_ostream
<_CharT
, _Traits
>&
3386 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3387 const std::student_t_distribution
<_RealType1
>& __x
);
3390 * @brief Extracts a %student_t_distribution random number distribution
3391 * @p __x from the input stream @p __is.
3393 * @param __is An input stream.
3394 * @param __x A %student_t_distribution random number
3397 * @returns The input stream with @p __x extracted or in an error state.
3399 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3400 friend std::basic_istream
<_CharT
, _Traits
>&
3401 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3402 std::student_t_distribution
<_RealType1
>& __x
);
3405 template<typename _ForwardIterator
,
3406 typename _UniformRandomNumberGenerator
>
3408 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3409 _UniformRandomNumberGenerator
& __urng
);
3410 template<typename _ForwardIterator
,
3411 typename _UniformRandomNumberGenerator
>
3413 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3414 _UniformRandomNumberGenerator
& __urng
,
3415 const param_type
& __p
);
3417 param_type _M_param
;
3419 std::normal_distribution
<result_type
> _M_nd
;
3420 std::gamma_distribution
<result_type
> _M_gd
;
3424 * @brief Return true if two Student t distributions are different.
3426 template<typename _RealType
>
3428 operator!=(const std::student_t_distribution
<_RealType
>& __d1
,
3429 const std::student_t_distribution
<_RealType
>& __d2
)
3430 { return !(__d1
== __d2
); }
3433 /* @} */ // group random_distributions_normal
3436 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3437 * @ingroup random_distributions
3442 * @brief A Bernoulli random number distribution.
3444 * Generates a sequence of true and false values with likelihood @f$p@f$
3445 * that true will come up and @f$(1 - p)@f$ that false will appear.
3447 class bernoulli_distribution
3450 /** The type of the range of the distribution. */
3451 typedef bool result_type
;
3453 /** Parameter type. */
3456 typedef bernoulli_distribution distribution_type
;
3459 param_type(double __p
= 0.5)
3462 __glibcxx_assert((_M_p
>= 0.0) && (_M_p
<= 1.0));
3470 operator==(const param_type
& __p1
, const param_type
& __p2
)
3471 { return __p1
._M_p
== __p2
._M_p
; }
3474 operator!=(const param_type
& __p1
, const param_type
& __p2
)
3475 { return !(__p1
== __p2
); }
3483 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3485 * @param __p [IN] The likelihood of a true result being returned.
3486 * Must be in the interval @f$[0, 1]@f$.
3489 bernoulli_distribution(double __p
= 0.5)
3494 bernoulli_distribution(const param_type
& __p
)
3499 * @brief Resets the distribution state.
3501 * Does nothing for a Bernoulli distribution.
3507 * @brief Returns the @p p parameter of the distribution.
3511 { return _M_param
.p(); }
3514 * @brief Returns the parameter set of the distribution.
3518 { return _M_param
; }
3521 * @brief Sets the parameter set of the distribution.
3522 * @param __param The new parameter set of the distribution.
3525 param(const param_type
& __param
)
3526 { _M_param
= __param
; }
3529 * @brief Returns the greatest lower bound value of the distribution.
3533 { return std::numeric_limits
<result_type
>::min(); }
3536 * @brief Returns the least upper bound value of the distribution.
3540 { return std::numeric_limits
<result_type
>::max(); }
3543 * @brief Generating functions.
3545 template<typename _UniformRandomNumberGenerator
>
3547 operator()(_UniformRandomNumberGenerator
& __urng
)
3548 { return this->operator()(__urng
, _M_param
); }
3550 template<typename _UniformRandomNumberGenerator
>
3552 operator()(_UniformRandomNumberGenerator
& __urng
,
3553 const param_type
& __p
)
3555 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
3557 if ((__aurng() - __aurng
.min())
3558 < __p
.p() * (__aurng
.max() - __aurng
.min()))
3563 template<typename _ForwardIterator
,
3564 typename _UniformRandomNumberGenerator
>
3566 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3567 _UniformRandomNumberGenerator
& __urng
)
3568 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3570 template<typename _ForwardIterator
,
3571 typename _UniformRandomNumberGenerator
>
3573 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3574 _UniformRandomNumberGenerator
& __urng
, const param_type
& __p
)
3575 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3577 template<typename _UniformRandomNumberGenerator
>
3579 __generate(result_type
* __f
, result_type
* __t
,
3580 _UniformRandomNumberGenerator
& __urng
,
3581 const param_type
& __p
)
3582 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3585 * @brief Return true if two Bernoulli distributions have
3586 * the same parameters.
3589 operator==(const bernoulli_distribution
& __d1
,
3590 const bernoulli_distribution
& __d2
)
3591 { return __d1
._M_param
== __d2
._M_param
; }
3594 template<typename _ForwardIterator
,
3595 typename _UniformRandomNumberGenerator
>
3597 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3598 _UniformRandomNumberGenerator
& __urng
,
3599 const param_type
& __p
);
3601 param_type _M_param
;
3605 * @brief Return true if two Bernoulli distributions have
3606 * different parameters.
3609 operator!=(const std::bernoulli_distribution
& __d1
,
3610 const std::bernoulli_distribution
& __d2
)
3611 { return !(__d1
== __d2
); }
3614 * @brief Inserts a %bernoulli_distribution random number distribution
3615 * @p __x into the output stream @p __os.
3617 * @param __os An output stream.
3618 * @param __x A %bernoulli_distribution random number distribution.
3620 * @returns The output stream with the state of @p __x inserted or in
3623 template<typename _CharT
, typename _Traits
>
3624 std::basic_ostream
<_CharT
, _Traits
>&
3625 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3626 const std::bernoulli_distribution
& __x
);
3629 * @brief Extracts a %bernoulli_distribution random number distribution
3630 * @p __x from the input stream @p __is.
3632 * @param __is An input stream.
3633 * @param __x A %bernoulli_distribution random number generator engine.
3635 * @returns The input stream with @p __x extracted or in an error state.
3637 template<typename _CharT
, typename _Traits
>
3638 std::basic_istream
<_CharT
, _Traits
>&
3639 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3640 std::bernoulli_distribution
& __x
)
3644 __x
.param(bernoulli_distribution::param_type(__p
));
3650 * @brief A discrete binomial random number distribution.
3652 * The formula for the binomial probability density function is
3653 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3654 * and @f$p@f$ are the parameters of the distribution.
3656 template<typename _IntType
= int>
3657 class binomial_distribution
3659 static_assert(std::is_integral
<_IntType
>::value
,
3660 "result_type must be an integral type");
3663 /** The type of the range of the distribution. */
3664 typedef _IntType result_type
;
3666 /** Parameter type. */
3669 typedef binomial_distribution
<_IntType
> distribution_type
;
3670 friend class binomial_distribution
<_IntType
>;
3673 param_type(_IntType __t
= _IntType(1), double __p
= 0.5)
3674 : _M_t(__t
), _M_p(__p
)
3676 __glibcxx_assert((_M_t
>= _IntType(0))
3691 operator==(const param_type
& __p1
, const param_type
& __p2
)
3692 { return __p1
._M_t
== __p2
._M_t
&& __p1
._M_p
== __p2
._M_p
; }
3695 operator!=(const param_type
& __p1
, const param_type
& __p2
)
3696 { return !(__p1
== __p2
); }
3706 #if _GLIBCXX_USE_C99_MATH_TR1
3707 double _M_d1
, _M_d2
, _M_s1
, _M_s2
, _M_c
,
3708 _M_a1
, _M_a123
, _M_s
, _M_lf
, _M_lp1p
;
3713 // constructors and member function
3715 binomial_distribution(_IntType __t
= _IntType(1),
3717 : _M_param(__t
, __p
), _M_nd()
3721 binomial_distribution(const param_type
& __p
)
3722 : _M_param(__p
), _M_nd()
3726 * @brief Resets the distribution state.
3733 * @brief Returns the distribution @p t parameter.
3737 { return _M_param
.t(); }
3740 * @brief Returns the distribution @p p parameter.
3744 { return _M_param
.p(); }
3747 * @brief Returns the parameter set of the distribution.
3751 { return _M_param
; }
3754 * @brief Sets the parameter set of the distribution.
3755 * @param __param The new parameter set of the distribution.
3758 param(const param_type
& __param
)
3759 { _M_param
= __param
; }
3762 * @brief Returns the greatest lower bound value of the distribution.
3769 * @brief Returns the least upper bound value of the distribution.
3773 { return _M_param
.t(); }
3776 * @brief Generating functions.
3778 template<typename _UniformRandomNumberGenerator
>
3780 operator()(_UniformRandomNumberGenerator
& __urng
)
3781 { return this->operator()(__urng
, _M_param
); }
3783 template<typename _UniformRandomNumberGenerator
>
3785 operator()(_UniformRandomNumberGenerator
& __urng
,
3786 const param_type
& __p
);
3788 template<typename _ForwardIterator
,
3789 typename _UniformRandomNumberGenerator
>
3791 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3792 _UniformRandomNumberGenerator
& __urng
)
3793 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3795 template<typename _ForwardIterator
,
3796 typename _UniformRandomNumberGenerator
>
3798 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3799 _UniformRandomNumberGenerator
& __urng
,
3800 const param_type
& __p
)
3801 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3803 template<typename _UniformRandomNumberGenerator
>
3805 __generate(result_type
* __f
, result_type
* __t
,
3806 _UniformRandomNumberGenerator
& __urng
,
3807 const param_type
& __p
)
3808 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3811 * @brief Return true if two binomial distributions have
3812 * the same parameters and the sequences that would
3813 * be generated are equal.
3816 operator==(const binomial_distribution
& __d1
,
3817 const binomial_distribution
& __d2
)
3818 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3819 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
3821 { return __d1
._M_param
== __d2
._M_param
; }
3825 * @brief Inserts a %binomial_distribution random number distribution
3826 * @p __x into the output stream @p __os.
3828 * @param __os An output stream.
3829 * @param __x A %binomial_distribution random number distribution.
3831 * @returns The output stream with the state of @p __x inserted or in
3834 template<typename _IntType1
,
3835 typename _CharT
, typename _Traits
>
3836 friend std::basic_ostream
<_CharT
, _Traits
>&
3837 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3838 const std::binomial_distribution
<_IntType1
>& __x
);
3841 * @brief Extracts a %binomial_distribution random number distribution
3842 * @p __x from the input stream @p __is.
3844 * @param __is An input stream.
3845 * @param __x A %binomial_distribution random number generator engine.
3847 * @returns The input stream with @p __x extracted or in an error
3850 template<typename _IntType1
,
3851 typename _CharT
, typename _Traits
>
3852 friend std::basic_istream
<_CharT
, _Traits
>&
3853 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3854 std::binomial_distribution
<_IntType1
>& __x
);
3857 template<typename _ForwardIterator
,
3858 typename _UniformRandomNumberGenerator
>
3860 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3861 _UniformRandomNumberGenerator
& __urng
,
3862 const param_type
& __p
);
3864 template<typename _UniformRandomNumberGenerator
>
3866 _M_waiting(_UniformRandomNumberGenerator
& __urng
,
3867 _IntType __t
, double __q
);
3869 param_type _M_param
;
3871 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3872 std::normal_distribution
<double> _M_nd
;
3876 * @brief Return true if two binomial distributions are different.
3878 template<typename _IntType
>
3880 operator!=(const std::binomial_distribution
<_IntType
>& __d1
,
3881 const std::binomial_distribution
<_IntType
>& __d2
)
3882 { return !(__d1
== __d2
); }
3886 * @brief A discrete geometric random number distribution.
3888 * The formula for the geometric probability density function is
3889 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3892 template<typename _IntType
= int>
3893 class geometric_distribution
3895 static_assert(std::is_integral
<_IntType
>::value
,
3896 "result_type must be an integral type");
3899 /** The type of the range of the distribution. */
3900 typedef _IntType result_type
;
3902 /** Parameter type. */
3905 typedef geometric_distribution
<_IntType
> distribution_type
;
3906 friend class geometric_distribution
<_IntType
>;
3909 param_type(double __p
= 0.5)
3912 __glibcxx_assert((_M_p
> 0.0) && (_M_p
< 1.0));
3921 operator==(const param_type
& __p1
, const param_type
& __p2
)
3922 { return __p1
._M_p
== __p2
._M_p
; }
3925 operator!=(const param_type
& __p1
, const param_type
& __p2
)
3926 { return !(__p1
== __p2
); }
3931 { _M_log_1_p
= std::log(1.0 - _M_p
); }
3938 // constructors and member function
3940 geometric_distribution(double __p
= 0.5)
3945 geometric_distribution(const param_type
& __p
)
3950 * @brief Resets the distribution state.
3952 * Does nothing for the geometric distribution.
3958 * @brief Returns the distribution parameter @p p.
3962 { return _M_param
.p(); }
3965 * @brief Returns the parameter set of the distribution.
3969 { return _M_param
; }
3972 * @brief Sets the parameter set of the distribution.
3973 * @param __param The new parameter set of the distribution.
3976 param(const param_type
& __param
)
3977 { _M_param
= __param
; }
3980 * @brief Returns the greatest lower bound value of the distribution.
3987 * @brief Returns the least upper bound value of the distribution.
3991 { return std::numeric_limits
<result_type
>::max(); }
3994 * @brief Generating functions.
3996 template<typename _UniformRandomNumberGenerator
>
3998 operator()(_UniformRandomNumberGenerator
& __urng
)
3999 { return this->operator()(__urng
, _M_param
); }
4001 template<typename _UniformRandomNumberGenerator
>
4003 operator()(_UniformRandomNumberGenerator
& __urng
,
4004 const param_type
& __p
);
4006 template<typename _ForwardIterator
,
4007 typename _UniformRandomNumberGenerator
>
4009 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4010 _UniformRandomNumberGenerator
& __urng
)
4011 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4013 template<typename _ForwardIterator
,
4014 typename _UniformRandomNumberGenerator
>
4016 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4017 _UniformRandomNumberGenerator
& __urng
,
4018 const param_type
& __p
)
4019 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4021 template<typename _UniformRandomNumberGenerator
>
4023 __generate(result_type
* __f
, result_type
* __t
,
4024 _UniformRandomNumberGenerator
& __urng
,
4025 const param_type
& __p
)
4026 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4029 * @brief Return true if two geometric distributions have
4030 * the same parameters.
4033 operator==(const geometric_distribution
& __d1
,
4034 const geometric_distribution
& __d2
)
4035 { return __d1
._M_param
== __d2
._M_param
; }
4038 template<typename _ForwardIterator
,
4039 typename _UniformRandomNumberGenerator
>
4041 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4042 _UniformRandomNumberGenerator
& __urng
,
4043 const param_type
& __p
);
4045 param_type _M_param
;
4049 * @brief Return true if two geometric distributions have
4050 * different parameters.
4052 template<typename _IntType
>
4054 operator!=(const std::geometric_distribution
<_IntType
>& __d1
,
4055 const std::geometric_distribution
<_IntType
>& __d2
)
4056 { return !(__d1
== __d2
); }
4059 * @brief Inserts a %geometric_distribution random number distribution
4060 * @p __x into the output stream @p __os.
4062 * @param __os An output stream.
4063 * @param __x A %geometric_distribution random number distribution.
4065 * @returns The output stream with the state of @p __x inserted or in
4068 template<typename _IntType
,
4069 typename _CharT
, typename _Traits
>
4070 std::basic_ostream
<_CharT
, _Traits
>&
4071 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4072 const std::geometric_distribution
<_IntType
>& __x
);
4075 * @brief Extracts a %geometric_distribution random number distribution
4076 * @p __x from the input stream @p __is.
4078 * @param __is An input stream.
4079 * @param __x A %geometric_distribution random number generator engine.
4081 * @returns The input stream with @p __x extracted or in an error state.
4083 template<typename _IntType
,
4084 typename _CharT
, typename _Traits
>
4085 std::basic_istream
<_CharT
, _Traits
>&
4086 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4087 std::geometric_distribution
<_IntType
>& __x
);
4091 * @brief A negative_binomial_distribution random number distribution.
4093 * The formula for the negative binomial probability mass function is
4094 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4095 * and @f$p@f$ are the parameters of the distribution.
4097 template<typename _IntType
= int>
4098 class negative_binomial_distribution
4100 static_assert(std::is_integral
<_IntType
>::value
,
4101 "result_type must be an integral type");
4104 /** The type of the range of the distribution. */
4105 typedef _IntType result_type
;
4107 /** Parameter type. */
4110 typedef negative_binomial_distribution
<_IntType
> distribution_type
;
4113 param_type(_IntType __k
= 1, double __p
= 0.5)
4114 : _M_k(__k
), _M_p(__p
)
4116 __glibcxx_assert((_M_k
> 0) && (_M_p
> 0.0) && (_M_p
<= 1.0));
4128 operator==(const param_type
& __p1
, const param_type
& __p2
)
4129 { return __p1
._M_k
== __p2
._M_k
&& __p1
._M_p
== __p2
._M_p
; }
4132 operator!=(const param_type
& __p1
, const param_type
& __p2
)
4133 { return !(__p1
== __p2
); }
4141 negative_binomial_distribution(_IntType __k
= 1, double __p
= 0.5)
4142 : _M_param(__k
, __p
), _M_gd(__k
, (1.0 - __p
) / __p
)
4146 negative_binomial_distribution(const param_type
& __p
)
4147 : _M_param(__p
), _M_gd(__p
.k(), (1.0 - __p
.p()) / __p
.p())
4151 * @brief Resets the distribution state.
4158 * @brief Return the @f$k@f$ parameter of the distribution.
4162 { return _M_param
.k(); }
4165 * @brief Return the @f$p@f$ parameter of the distribution.
4169 { return _M_param
.p(); }
4172 * @brief Returns the parameter set of the distribution.
4176 { return _M_param
; }
4179 * @brief Sets the parameter set of the distribution.
4180 * @param __param The new parameter set of the distribution.
4183 param(const param_type
& __param
)
4184 { _M_param
= __param
; }
4187 * @brief Returns the greatest lower bound value of the distribution.
4191 { return result_type(0); }
4194 * @brief Returns the least upper bound value of the distribution.
4198 { return std::numeric_limits
<result_type
>::max(); }
4201 * @brief Generating functions.
4203 template<typename _UniformRandomNumberGenerator
>
4205 operator()(_UniformRandomNumberGenerator
& __urng
);
4207 template<typename _UniformRandomNumberGenerator
>
4209 operator()(_UniformRandomNumberGenerator
& __urng
,
4210 const param_type
& __p
);
4212 template<typename _ForwardIterator
,
4213 typename _UniformRandomNumberGenerator
>
4215 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4216 _UniformRandomNumberGenerator
& __urng
)
4217 { this->__generate_impl(__f
, __t
, __urng
); }
4219 template<typename _ForwardIterator
,
4220 typename _UniformRandomNumberGenerator
>
4222 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4223 _UniformRandomNumberGenerator
& __urng
,
4224 const param_type
& __p
)
4225 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4227 template<typename _UniformRandomNumberGenerator
>
4229 __generate(result_type
* __f
, result_type
* __t
,
4230 _UniformRandomNumberGenerator
& __urng
)
4231 { this->__generate_impl(__f
, __t
, __urng
); }
4233 template<typename _UniformRandomNumberGenerator
>
4235 __generate(result_type
* __f
, result_type
* __t
,
4236 _UniformRandomNumberGenerator
& __urng
,
4237 const param_type
& __p
)
4238 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4241 * @brief Return true if two negative binomial distributions have
4242 * the same parameters and the sequences that would be
4243 * generated are equal.
4246 operator==(const negative_binomial_distribution
& __d1
,
4247 const negative_binomial_distribution
& __d2
)
4248 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
4251 * @brief Inserts a %negative_binomial_distribution random
4252 * number distribution @p __x into the output stream @p __os.
4254 * @param __os An output stream.
4255 * @param __x A %negative_binomial_distribution random number
4258 * @returns The output stream with the state of @p __x inserted or in
4261 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4262 friend std::basic_ostream
<_CharT
, _Traits
>&
4263 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4264 const std::negative_binomial_distribution
<_IntType1
>& __x
);
4267 * @brief Extracts a %negative_binomial_distribution random number
4268 * distribution @p __x from the input stream @p __is.
4270 * @param __is An input stream.
4271 * @param __x A %negative_binomial_distribution random number
4274 * @returns The input stream with @p __x extracted or in an error state.
4276 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4277 friend std::basic_istream
<_CharT
, _Traits
>&
4278 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4279 std::negative_binomial_distribution
<_IntType1
>& __x
);
4282 template<typename _ForwardIterator
,
4283 typename _UniformRandomNumberGenerator
>
4285 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4286 _UniformRandomNumberGenerator
& __urng
);
4287 template<typename _ForwardIterator
,
4288 typename _UniformRandomNumberGenerator
>
4290 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4291 _UniformRandomNumberGenerator
& __urng
,
4292 const param_type
& __p
);
4294 param_type _M_param
;
4296 std::gamma_distribution
<double> _M_gd
;
4300 * @brief Return true if two negative binomial distributions are different.
4302 template<typename _IntType
>
4304 operator!=(const std::negative_binomial_distribution
<_IntType
>& __d1
,
4305 const std::negative_binomial_distribution
<_IntType
>& __d2
)
4306 { return !(__d1
== __d2
); }
4309 /* @} */ // group random_distributions_bernoulli
4312 * @addtogroup random_distributions_poisson Poisson Distributions
4313 * @ingroup random_distributions
4318 * @brief A discrete Poisson random number distribution.
4320 * The formula for the Poisson probability density function is
4321 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4322 * parameter of the distribution.
4324 template<typename _IntType
= int>
4325 class poisson_distribution
4327 static_assert(std::is_integral
<_IntType
>::value
,
4328 "result_type must be an integral type");
4331 /** The type of the range of the distribution. */
4332 typedef _IntType result_type
;
4334 /** Parameter type. */
4337 typedef poisson_distribution
<_IntType
> distribution_type
;
4338 friend class poisson_distribution
<_IntType
>;
4341 param_type(double __mean
= 1.0)
4344 __glibcxx_assert(_M_mean
> 0.0);
4353 operator==(const param_type
& __p1
, const param_type
& __p2
)
4354 { return __p1
._M_mean
== __p2
._M_mean
; }
4357 operator!=(const param_type
& __p1
, const param_type
& __p2
)
4358 { return !(__p1
== __p2
); }
4361 // Hosts either log(mean) or the threshold of the simple method.
4368 #if _GLIBCXX_USE_C99_MATH_TR1
4369 double _M_lfm
, _M_sm
, _M_d
, _M_scx
, _M_1cx
, _M_c2b
, _M_cb
;
4373 // constructors and member function
4375 poisson_distribution(double __mean
= 1.0)
4376 : _M_param(__mean
), _M_nd()
4380 poisson_distribution(const param_type
& __p
)
4381 : _M_param(__p
), _M_nd()
4385 * @brief Resets the distribution state.
4392 * @brief Returns the distribution parameter @p mean.
4396 { return _M_param
.mean(); }
4399 * @brief Returns the parameter set of the distribution.
4403 { return _M_param
; }
4406 * @brief Sets the parameter set of the distribution.
4407 * @param __param The new parameter set of the distribution.
4410 param(const param_type
& __param
)
4411 { _M_param
= __param
; }
4414 * @brief Returns the greatest lower bound value of the distribution.
4421 * @brief Returns the least upper bound value of the distribution.
4425 { return std::numeric_limits
<result_type
>::max(); }
4428 * @brief Generating functions.
4430 template<typename _UniformRandomNumberGenerator
>
4432 operator()(_UniformRandomNumberGenerator
& __urng
)
4433 { return this->operator()(__urng
, _M_param
); }
4435 template<typename _UniformRandomNumberGenerator
>
4437 operator()(_UniformRandomNumberGenerator
& __urng
,
4438 const param_type
& __p
);
4440 template<typename _ForwardIterator
,
4441 typename _UniformRandomNumberGenerator
>
4443 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4444 _UniformRandomNumberGenerator
& __urng
)
4445 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4447 template<typename _ForwardIterator
,
4448 typename _UniformRandomNumberGenerator
>
4450 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4451 _UniformRandomNumberGenerator
& __urng
,
4452 const param_type
& __p
)
4453 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4455 template<typename _UniformRandomNumberGenerator
>
4457 __generate(result_type
* __f
, result_type
* __t
,
4458 _UniformRandomNumberGenerator
& __urng
,
4459 const param_type
& __p
)
4460 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4463 * @brief Return true if two Poisson distributions have the same
4464 * parameters and the sequences that would be generated
4468 operator==(const poisson_distribution
& __d1
,
4469 const poisson_distribution
& __d2
)
4470 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4471 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
4473 { return __d1
._M_param
== __d2
._M_param
; }
4477 * @brief Inserts a %poisson_distribution random number distribution
4478 * @p __x into the output stream @p __os.
4480 * @param __os An output stream.
4481 * @param __x A %poisson_distribution random number distribution.
4483 * @returns The output stream with the state of @p __x inserted or in
4486 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4487 friend std::basic_ostream
<_CharT
, _Traits
>&
4488 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4489 const std::poisson_distribution
<_IntType1
>& __x
);
4492 * @brief Extracts a %poisson_distribution random number distribution
4493 * @p __x from the input stream @p __is.
4495 * @param __is An input stream.
4496 * @param __x A %poisson_distribution random number generator engine.
4498 * @returns The input stream with @p __x extracted or in an error
4501 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4502 friend std::basic_istream
<_CharT
, _Traits
>&
4503 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4504 std::poisson_distribution
<_IntType1
>& __x
);
4507 template<typename _ForwardIterator
,
4508 typename _UniformRandomNumberGenerator
>
4510 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4511 _UniformRandomNumberGenerator
& __urng
,
4512 const param_type
& __p
);
4514 param_type _M_param
;
4516 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4517 std::normal_distribution
<double> _M_nd
;
4521 * @brief Return true if two Poisson distributions are different.
4523 template<typename _IntType
>
4525 operator!=(const std::poisson_distribution
<_IntType
>& __d1
,
4526 const std::poisson_distribution
<_IntType
>& __d2
)
4527 { return !(__d1
== __d2
); }
4531 * @brief An exponential continuous distribution for random numbers.
4533 * The formula for the exponential probability density function is
4534 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4536 * <table border=1 cellpadding=10 cellspacing=0>
4537 * <caption align=top>Distribution Statistics</caption>
4538 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4539 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4540 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4541 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4542 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4545 template<typename _RealType
= double>
4546 class exponential_distribution
4548 static_assert(std::is_floating_point
<_RealType
>::value
,
4549 "result_type must be a floating point type");
4552 /** The type of the range of the distribution. */
4553 typedef _RealType result_type
;
4555 /** Parameter type. */
4558 typedef exponential_distribution
<_RealType
> distribution_type
;
4561 param_type(_RealType __lambda
= _RealType(1))
4562 : _M_lambda(__lambda
)
4564 __glibcxx_assert(_M_lambda
> _RealType(0));
4569 { return _M_lambda
; }
4572 operator==(const param_type
& __p1
, const param_type
& __p2
)
4573 { return __p1
._M_lambda
== __p2
._M_lambda
; }
4576 operator!=(const param_type
& __p1
, const param_type
& __p2
)
4577 { return !(__p1
== __p2
); }
4580 _RealType _M_lambda
;
4585 * @brief Constructs an exponential distribution with inverse scale
4586 * parameter @f$\lambda@f$.
4589 exponential_distribution(const result_type
& __lambda
= result_type(1))
4590 : _M_param(__lambda
)
4594 exponential_distribution(const param_type
& __p
)
4599 * @brief Resets the distribution state.
4601 * Has no effect on exponential distributions.
4607 * @brief Returns the inverse scale parameter of the distribution.
4611 { return _M_param
.lambda(); }
4614 * @brief Returns the parameter set of the distribution.
4618 { return _M_param
; }
4621 * @brief Sets the parameter set of the distribution.
4622 * @param __param The new parameter set of the distribution.
4625 param(const param_type
& __param
)
4626 { _M_param
= __param
; }
4629 * @brief Returns the greatest lower bound value of the distribution.
4633 { return result_type(0); }
4636 * @brief Returns the least upper bound value of the distribution.
4640 { return std::numeric_limits
<result_type
>::max(); }
4643 * @brief Generating functions.
4645 template<typename _UniformRandomNumberGenerator
>
4647 operator()(_UniformRandomNumberGenerator
& __urng
)
4648 { return this->operator()(__urng
, _M_param
); }
4650 template<typename _UniformRandomNumberGenerator
>
4652 operator()(_UniformRandomNumberGenerator
& __urng
,
4653 const param_type
& __p
)
4655 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
4657 return -std::log(result_type(1) - __aurng()) / __p
.lambda();
4660 template<typename _ForwardIterator
,
4661 typename _UniformRandomNumberGenerator
>
4663 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4664 _UniformRandomNumberGenerator
& __urng
)
4665 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4667 template<typename _ForwardIterator
,
4668 typename _UniformRandomNumberGenerator
>
4670 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4671 _UniformRandomNumberGenerator
& __urng
,
4672 const param_type
& __p
)
4673 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4675 template<typename _UniformRandomNumberGenerator
>
4677 __generate(result_type
* __f
, result_type
* __t
,
4678 _UniformRandomNumberGenerator
& __urng
,
4679 const param_type
& __p
)
4680 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4683 * @brief Return true if two exponential distributions have the same
4687 operator==(const exponential_distribution
& __d1
,
4688 const exponential_distribution
& __d2
)
4689 { return __d1
._M_param
== __d2
._M_param
; }
4692 template<typename _ForwardIterator
,
4693 typename _UniformRandomNumberGenerator
>
4695 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4696 _UniformRandomNumberGenerator
& __urng
,
4697 const param_type
& __p
);
4699 param_type _M_param
;
4703 * @brief Return true if two exponential distributions have different
4706 template<typename _RealType
>
4708 operator!=(const std::exponential_distribution
<_RealType
>& __d1
,
4709 const std::exponential_distribution
<_RealType
>& __d2
)
4710 { return !(__d1
== __d2
); }
4713 * @brief Inserts a %exponential_distribution random number distribution
4714 * @p __x into the output stream @p __os.
4716 * @param __os An output stream.
4717 * @param __x A %exponential_distribution random number distribution.
4719 * @returns The output stream with the state of @p __x inserted or in
4722 template<typename _RealType
, typename _CharT
, typename _Traits
>
4723 std::basic_ostream
<_CharT
, _Traits
>&
4724 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4725 const std::exponential_distribution
<_RealType
>& __x
);
4728 * @brief Extracts a %exponential_distribution random number distribution
4729 * @p __x from the input stream @p __is.
4731 * @param __is An input stream.
4732 * @param __x A %exponential_distribution random number
4735 * @returns The input stream with @p __x extracted or in an error state.
4737 template<typename _RealType
, typename _CharT
, typename _Traits
>
4738 std::basic_istream
<_CharT
, _Traits
>&
4739 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4740 std::exponential_distribution
<_RealType
>& __x
);
4744 * @brief A weibull_distribution random number distribution.
4746 * The formula for the normal probability density function is:
4748 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4749 * \exp{(-(\frac{x}{\beta})^\alpha)}
4752 template<typename _RealType
= double>
4753 class weibull_distribution
4755 static_assert(std::is_floating_point
<_RealType
>::value
,
4756 "result_type must be a floating point type");
4759 /** The type of the range of the distribution. */
4760 typedef _RealType result_type
;
4762 /** Parameter type. */
4765 typedef weibull_distribution
<_RealType
> distribution_type
;
4768 param_type(_RealType __a
= _RealType(1),
4769 _RealType __b
= _RealType(1))
4770 : _M_a(__a
), _M_b(__b
)
4782 operator==(const param_type
& __p1
, const param_type
& __p2
)
4783 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
4786 operator!=(const param_type
& __p1
, const param_type
& __p2
)
4787 { return !(__p1
== __p2
); }
4795 weibull_distribution(_RealType __a
= _RealType(1),
4796 _RealType __b
= _RealType(1))
4797 : _M_param(__a
, __b
)
4801 weibull_distribution(const param_type
& __p
)
4806 * @brief Resets the distribution state.
4813 * @brief Return the @f$a@f$ parameter of the distribution.
4817 { return _M_param
.a(); }
4820 * @brief Return the @f$b@f$ parameter of the distribution.
4824 { return _M_param
.b(); }
4827 * @brief Returns the parameter set of the distribution.
4831 { return _M_param
; }
4834 * @brief Sets the parameter set of the distribution.
4835 * @param __param The new parameter set of the distribution.
4838 param(const param_type
& __param
)
4839 { _M_param
= __param
; }
4842 * @brief Returns the greatest lower bound value of the distribution.
4846 { return result_type(0); }
4849 * @brief Returns the least upper bound value of the distribution.
4853 { return std::numeric_limits
<result_type
>::max(); }
4856 * @brief Generating functions.
4858 template<typename _UniformRandomNumberGenerator
>
4860 operator()(_UniformRandomNumberGenerator
& __urng
)
4861 { return this->operator()(__urng
, _M_param
); }
4863 template<typename _UniformRandomNumberGenerator
>
4865 operator()(_UniformRandomNumberGenerator
& __urng
,
4866 const param_type
& __p
);
4868 template<typename _ForwardIterator
,
4869 typename _UniformRandomNumberGenerator
>
4871 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4872 _UniformRandomNumberGenerator
& __urng
)
4873 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4875 template<typename _ForwardIterator
,
4876 typename _UniformRandomNumberGenerator
>
4878 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4879 _UniformRandomNumberGenerator
& __urng
,
4880 const param_type
& __p
)
4881 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4883 template<typename _UniformRandomNumberGenerator
>
4885 __generate(result_type
* __f
, result_type
* __t
,
4886 _UniformRandomNumberGenerator
& __urng
,
4887 const param_type
& __p
)
4888 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4891 * @brief Return true if two Weibull distributions have the same
4895 operator==(const weibull_distribution
& __d1
,
4896 const weibull_distribution
& __d2
)
4897 { return __d1
._M_param
== __d2
._M_param
; }
4900 template<typename _ForwardIterator
,
4901 typename _UniformRandomNumberGenerator
>
4903 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4904 _UniformRandomNumberGenerator
& __urng
,
4905 const param_type
& __p
);
4907 param_type _M_param
;
4911 * @brief Return true if two Weibull distributions have different
4914 template<typename _RealType
>
4916 operator!=(const std::weibull_distribution
<_RealType
>& __d1
,
4917 const std::weibull_distribution
<_RealType
>& __d2
)
4918 { return !(__d1
== __d2
); }
4921 * @brief Inserts a %weibull_distribution random number distribution
4922 * @p __x into the output stream @p __os.
4924 * @param __os An output stream.
4925 * @param __x A %weibull_distribution random number distribution.
4927 * @returns The output stream with the state of @p __x inserted or in
4930 template<typename _RealType
, typename _CharT
, typename _Traits
>
4931 std::basic_ostream
<_CharT
, _Traits
>&
4932 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4933 const std::weibull_distribution
<_RealType
>& __x
);
4936 * @brief Extracts a %weibull_distribution random number distribution
4937 * @p __x from the input stream @p __is.
4939 * @param __is An input stream.
4940 * @param __x A %weibull_distribution random number
4943 * @returns The input stream with @p __x extracted or in an error state.
4945 template<typename _RealType
, typename _CharT
, typename _Traits
>
4946 std::basic_istream
<_CharT
, _Traits
>&
4947 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4948 std::weibull_distribution
<_RealType
>& __x
);
4952 * @brief A extreme_value_distribution random number distribution.
4954 * The formula for the normal probability mass function is
4956 * p(x|a,b) = \frac{1}{b}
4957 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4960 template<typename _RealType
= double>
4961 class extreme_value_distribution
4963 static_assert(std::is_floating_point
<_RealType
>::value
,
4964 "result_type must be a floating point type");
4967 /** The type of the range of the distribution. */
4968 typedef _RealType result_type
;
4970 /** Parameter type. */
4973 typedef extreme_value_distribution
<_RealType
> distribution_type
;
4976 param_type(_RealType __a
= _RealType(0),
4977 _RealType __b
= _RealType(1))
4978 : _M_a(__a
), _M_b(__b
)
4990 operator==(const param_type
& __p1
, const param_type
& __p2
)
4991 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
4994 operator!=(const param_type
& __p1
, const param_type
& __p2
)
4995 { return !(__p1
== __p2
); }
5003 extreme_value_distribution(_RealType __a
= _RealType(0),
5004 _RealType __b
= _RealType(1))
5005 : _M_param(__a
, __b
)
5009 extreme_value_distribution(const param_type
& __p
)
5014 * @brief Resets the distribution state.
5021 * @brief Return the @f$a@f$ parameter of the distribution.
5025 { return _M_param
.a(); }
5028 * @brief Return the @f$b@f$ parameter of the distribution.
5032 { return _M_param
.b(); }
5035 * @brief Returns the parameter set of the distribution.
5039 { return _M_param
; }
5042 * @brief Sets the parameter set of the distribution.
5043 * @param __param The new parameter set of the distribution.
5046 param(const param_type
& __param
)
5047 { _M_param
= __param
; }
5050 * @brief Returns the greatest lower bound value of the distribution.
5054 { return std::numeric_limits
<result_type
>::lowest(); }
5057 * @brief Returns the least upper bound value of the distribution.
5061 { return std::numeric_limits
<result_type
>::max(); }
5064 * @brief Generating functions.
5066 template<typename _UniformRandomNumberGenerator
>
5068 operator()(_UniformRandomNumberGenerator
& __urng
)
5069 { return this->operator()(__urng
, _M_param
); }
5071 template<typename _UniformRandomNumberGenerator
>
5073 operator()(_UniformRandomNumberGenerator
& __urng
,
5074 const param_type
& __p
);
5076 template<typename _ForwardIterator
,
5077 typename _UniformRandomNumberGenerator
>
5079 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5080 _UniformRandomNumberGenerator
& __urng
)
5081 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5083 template<typename _ForwardIterator
,
5084 typename _UniformRandomNumberGenerator
>
5086 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5087 _UniformRandomNumberGenerator
& __urng
,
5088 const param_type
& __p
)
5089 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5091 template<typename _UniformRandomNumberGenerator
>
5093 __generate(result_type
* __f
, result_type
* __t
,
5094 _UniformRandomNumberGenerator
& __urng
,
5095 const param_type
& __p
)
5096 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5099 * @brief Return true if two extreme value distributions have the same
5103 operator==(const extreme_value_distribution
& __d1
,
5104 const extreme_value_distribution
& __d2
)
5105 { return __d1
._M_param
== __d2
._M_param
; }
5108 template<typename _ForwardIterator
,
5109 typename _UniformRandomNumberGenerator
>
5111 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5112 _UniformRandomNumberGenerator
& __urng
,
5113 const param_type
& __p
);
5115 param_type _M_param
;
5119 * @brief Return true if two extreme value distributions have different
5122 template<typename _RealType
>
5124 operator!=(const std::extreme_value_distribution
<_RealType
>& __d1
,
5125 const std::extreme_value_distribution
<_RealType
>& __d2
)
5126 { return !(__d1
== __d2
); }
5129 * @brief Inserts a %extreme_value_distribution random number distribution
5130 * @p __x into the output stream @p __os.
5132 * @param __os An output stream.
5133 * @param __x A %extreme_value_distribution random number distribution.
5135 * @returns The output stream with the state of @p __x inserted or in
5138 template<typename _RealType
, typename _CharT
, typename _Traits
>
5139 std::basic_ostream
<_CharT
, _Traits
>&
5140 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5141 const std::extreme_value_distribution
<_RealType
>& __x
);
5144 * @brief Extracts a %extreme_value_distribution random number
5145 * distribution @p __x from the input stream @p __is.
5147 * @param __is An input stream.
5148 * @param __x A %extreme_value_distribution random number
5151 * @returns The input stream with @p __x extracted or in an error state.
5153 template<typename _RealType
, typename _CharT
, typename _Traits
>
5154 std::basic_istream
<_CharT
, _Traits
>&
5155 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5156 std::extreme_value_distribution
<_RealType
>& __x
);
5160 * @brief A discrete_distribution random number distribution.
5162 * The formula for the discrete probability mass function is
5165 template<typename _IntType
= int>
5166 class discrete_distribution
5168 static_assert(std::is_integral
<_IntType
>::value
,
5169 "result_type must be an integral type");
5172 /** The type of the range of the distribution. */
5173 typedef _IntType result_type
;
5175 /** Parameter type. */
5178 typedef discrete_distribution
<_IntType
> distribution_type
;
5179 friend class discrete_distribution
<_IntType
>;
5182 : _M_prob(), _M_cp()
5185 template<typename _InputIterator
>
5186 param_type(_InputIterator __wbegin
,
5187 _InputIterator __wend
)
5188 : _M_prob(__wbegin
, __wend
), _M_cp()
5189 { _M_initialize(); }
5191 param_type(initializer_list
<double> __wil
)
5192 : _M_prob(__wil
.begin(), __wil
.end()), _M_cp()
5193 { _M_initialize(); }
5195 template<typename _Func
>
5196 param_type(size_t __nw
, double __xmin
, double __xmax
,
5199 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5200 param_type(const param_type
&) = default;
5201 param_type
& operator=(const param_type
&) = default;
5204 probabilities() const
5205 { return _M_prob
.empty() ? std::vector
<double>(1, 1.0) : _M_prob
; }
5208 operator==(const param_type
& __p1
, const param_type
& __p2
)
5209 { return __p1
._M_prob
== __p2
._M_prob
; }
5212 operator!=(const param_type
& __p1
, const param_type
& __p2
)
5213 { return !(__p1
== __p2
); }
5219 std::vector
<double> _M_prob
;
5220 std::vector
<double> _M_cp
;
5223 discrete_distribution()
5227 template<typename _InputIterator
>
5228 discrete_distribution(_InputIterator __wbegin
,
5229 _InputIterator __wend
)
5230 : _M_param(__wbegin
, __wend
)
5233 discrete_distribution(initializer_list
<double> __wl
)
5237 template<typename _Func
>
5238 discrete_distribution(size_t __nw
, double __xmin
, double __xmax
,
5240 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5244 discrete_distribution(const param_type
& __p
)
5249 * @brief Resets the distribution state.
5256 * @brief Returns the probabilities of the distribution.
5259 probabilities() const
5261 return _M_param
._M_prob
.empty()
5262 ? std::vector
<double>(1, 1.0) : _M_param
._M_prob
;
5266 * @brief Returns the parameter set of the distribution.
5270 { return _M_param
; }
5273 * @brief Sets the parameter set of the distribution.
5274 * @param __param The new parameter set of the distribution.
5277 param(const param_type
& __param
)
5278 { _M_param
= __param
; }
5281 * @brief Returns the greatest lower bound value of the distribution.
5285 { return result_type(0); }
5288 * @brief Returns the least upper bound value of the distribution.
5293 return _M_param
._M_prob
.empty()
5294 ? result_type(0) : result_type(_M_param
._M_prob
.size() - 1);
5298 * @brief Generating functions.
5300 template<typename _UniformRandomNumberGenerator
>
5302 operator()(_UniformRandomNumberGenerator
& __urng
)
5303 { return this->operator()(__urng
, _M_param
); }
5305 template<typename _UniformRandomNumberGenerator
>
5307 operator()(_UniformRandomNumberGenerator
& __urng
,
5308 const param_type
& __p
);
5310 template<typename _ForwardIterator
,
5311 typename _UniformRandomNumberGenerator
>
5313 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5314 _UniformRandomNumberGenerator
& __urng
)
5315 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5317 template<typename _ForwardIterator
,
5318 typename _UniformRandomNumberGenerator
>
5320 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5321 _UniformRandomNumberGenerator
& __urng
,
5322 const param_type
& __p
)
5323 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5325 template<typename _UniformRandomNumberGenerator
>
5327 __generate(result_type
* __f
, result_type
* __t
,
5328 _UniformRandomNumberGenerator
& __urng
,
5329 const param_type
& __p
)
5330 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5333 * @brief Return true if two discrete distributions have the same
5337 operator==(const discrete_distribution
& __d1
,
5338 const discrete_distribution
& __d2
)
5339 { return __d1
._M_param
== __d2
._M_param
; }
5342 * @brief Inserts a %discrete_distribution random number distribution
5343 * @p __x into the output stream @p __os.
5345 * @param __os An output stream.
5346 * @param __x A %discrete_distribution random number distribution.
5348 * @returns The output stream with the state of @p __x inserted or in
5351 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5352 friend std::basic_ostream
<_CharT
, _Traits
>&
5353 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5354 const std::discrete_distribution
<_IntType1
>& __x
);
5357 * @brief Extracts a %discrete_distribution random number distribution
5358 * @p __x from the input stream @p __is.
5360 * @param __is An input stream.
5361 * @param __x A %discrete_distribution random number
5364 * @returns The input stream with @p __x extracted or in an error
5367 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5368 friend std::basic_istream
<_CharT
, _Traits
>&
5369 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5370 std::discrete_distribution
<_IntType1
>& __x
);
5373 template<typename _ForwardIterator
,
5374 typename _UniformRandomNumberGenerator
>
5376 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5377 _UniformRandomNumberGenerator
& __urng
,
5378 const param_type
& __p
);
5380 param_type _M_param
;
5384 * @brief Return true if two discrete distributions have different
5387 template<typename _IntType
>
5389 operator!=(const std::discrete_distribution
<_IntType
>& __d1
,
5390 const std::discrete_distribution
<_IntType
>& __d2
)
5391 { return !(__d1
== __d2
); }
5395 * @brief A piecewise_constant_distribution random number distribution.
5397 * The formula for the piecewise constant probability mass function is
5400 template<typename _RealType
= double>
5401 class piecewise_constant_distribution
5403 static_assert(std::is_floating_point
<_RealType
>::value
,
5404 "result_type must be a floating point type");
5407 /** The type of the range of the distribution. */
5408 typedef _RealType result_type
;
5410 /** Parameter type. */
5413 typedef piecewise_constant_distribution
<_RealType
> distribution_type
;
5414 friend class piecewise_constant_distribution
<_RealType
>;
5417 : _M_int(), _M_den(), _M_cp()
5420 template<typename _InputIteratorB
, typename _InputIteratorW
>
5421 param_type(_InputIteratorB __bfirst
,
5422 _InputIteratorB __bend
,
5423 _InputIteratorW __wbegin
);
5425 template<typename _Func
>
5426 param_type(initializer_list
<_RealType
> __bi
, _Func __fw
);
5428 template<typename _Func
>
5429 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5432 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5433 param_type(const param_type
&) = default;
5434 param_type
& operator=(const param_type
&) = default;
5436 std::vector
<_RealType
>
5441 std::vector
<_RealType
> __tmp(2);
5442 __tmp
[1] = _RealType(1);
5451 { return _M_den
.empty() ? std::vector
<double>(1, 1.0) : _M_den
; }
5454 operator==(const param_type
& __p1
, const param_type
& __p2
)
5455 { return __p1
._M_int
== __p2
._M_int
&& __p1
._M_den
== __p2
._M_den
; }
5458 operator!=(const param_type
& __p1
, const param_type
& __p2
)
5459 { return !(__p1
== __p2
); }
5465 std::vector
<_RealType
> _M_int
;
5466 std::vector
<double> _M_den
;
5467 std::vector
<double> _M_cp
;
5471 piecewise_constant_distribution()
5475 template<typename _InputIteratorB
, typename _InputIteratorW
>
5476 piecewise_constant_distribution(_InputIteratorB __bfirst
,
5477 _InputIteratorB __bend
,
5478 _InputIteratorW __wbegin
)
5479 : _M_param(__bfirst
, __bend
, __wbegin
)
5482 template<typename _Func
>
5483 piecewise_constant_distribution(initializer_list
<_RealType
> __bl
,
5485 : _M_param(__bl
, __fw
)
5488 template<typename _Func
>
5489 piecewise_constant_distribution(size_t __nw
,
5490 _RealType __xmin
, _RealType __xmax
,
5492 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5496 piecewise_constant_distribution(const param_type
& __p
)
5501 * @brief Resets the distribution state.
5508 * @brief Returns a vector of the intervals.
5510 std::vector
<_RealType
>
5513 if (_M_param
._M_int
.empty())
5515 std::vector
<_RealType
> __tmp(2);
5516 __tmp
[1] = _RealType(1);
5520 return _M_param
._M_int
;
5524 * @brief Returns a vector of the probability densities.
5529 return _M_param
._M_den
.empty()
5530 ? std::vector
<double>(1, 1.0) : _M_param
._M_den
;
5534 * @brief Returns the parameter set of the distribution.
5538 { return _M_param
; }
5541 * @brief Sets the parameter set of the distribution.
5542 * @param __param The new parameter set of the distribution.
5545 param(const param_type
& __param
)
5546 { _M_param
= __param
; }
5549 * @brief Returns the greatest lower bound value of the distribution.
5554 return _M_param
._M_int
.empty()
5555 ? result_type(0) : _M_param
._M_int
.front();
5559 * @brief Returns the least upper bound value of the distribution.
5564 return _M_param
._M_int
.empty()
5565 ? result_type(1) : _M_param
._M_int
.back();
5569 * @brief Generating functions.
5571 template<typename _UniformRandomNumberGenerator
>
5573 operator()(_UniformRandomNumberGenerator
& __urng
)
5574 { return this->operator()(__urng
, _M_param
); }
5576 template<typename _UniformRandomNumberGenerator
>
5578 operator()(_UniformRandomNumberGenerator
& __urng
,
5579 const param_type
& __p
);
5581 template<typename _ForwardIterator
,
5582 typename _UniformRandomNumberGenerator
>
5584 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5585 _UniformRandomNumberGenerator
& __urng
)
5586 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5588 template<typename _ForwardIterator
,
5589 typename _UniformRandomNumberGenerator
>
5591 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5592 _UniformRandomNumberGenerator
& __urng
,
5593 const param_type
& __p
)
5594 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5596 template<typename _UniformRandomNumberGenerator
>
5598 __generate(result_type
* __f
, result_type
* __t
,
5599 _UniformRandomNumberGenerator
& __urng
,
5600 const param_type
& __p
)
5601 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5604 * @brief Return true if two piecewise constant distributions have the
5608 operator==(const piecewise_constant_distribution
& __d1
,
5609 const piecewise_constant_distribution
& __d2
)
5610 { return __d1
._M_param
== __d2
._M_param
; }
5613 * @brief Inserts a %piecewise_constant_distribution random
5614 * number distribution @p __x into the output stream @p __os.
5616 * @param __os An output stream.
5617 * @param __x A %piecewise_constant_distribution random number
5620 * @returns The output stream with the state of @p __x inserted or in
5623 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5624 friend std::basic_ostream
<_CharT
, _Traits
>&
5625 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5626 const std::piecewise_constant_distribution
<_RealType1
>& __x
);
5629 * @brief Extracts a %piecewise_constant_distribution random
5630 * number distribution @p __x from the input stream @p __is.
5632 * @param __is An input stream.
5633 * @param __x A %piecewise_constant_distribution random number
5636 * @returns The input stream with @p __x extracted or in an error
5639 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5640 friend std::basic_istream
<_CharT
, _Traits
>&
5641 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5642 std::piecewise_constant_distribution
<_RealType1
>& __x
);
5645 template<typename _ForwardIterator
,
5646 typename _UniformRandomNumberGenerator
>
5648 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5649 _UniformRandomNumberGenerator
& __urng
,
5650 const param_type
& __p
);
5652 param_type _M_param
;
5656 * @brief Return true if two piecewise constant distributions have
5657 * different parameters.
5659 template<typename _RealType
>
5661 operator!=(const std::piecewise_constant_distribution
<_RealType
>& __d1
,
5662 const std::piecewise_constant_distribution
<_RealType
>& __d2
)
5663 { return !(__d1
== __d2
); }
5667 * @brief A piecewise_linear_distribution random number distribution.
5669 * The formula for the piecewise linear probability mass function is
5672 template<typename _RealType
= double>
5673 class piecewise_linear_distribution
5675 static_assert(std::is_floating_point
<_RealType
>::value
,
5676 "result_type must be a floating point type");
5679 /** The type of the range of the distribution. */
5680 typedef _RealType result_type
;
5682 /** Parameter type. */
5685 typedef piecewise_linear_distribution
<_RealType
> distribution_type
;
5686 friend class piecewise_linear_distribution
<_RealType
>;
5689 : _M_int(), _M_den(), _M_cp(), _M_m()
5692 template<typename _InputIteratorB
, typename _InputIteratorW
>
5693 param_type(_InputIteratorB __bfirst
,
5694 _InputIteratorB __bend
,
5695 _InputIteratorW __wbegin
);
5697 template<typename _Func
>
5698 param_type(initializer_list
<_RealType
> __bl
, _Func __fw
);
5700 template<typename _Func
>
5701 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5704 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5705 param_type(const param_type
&) = default;
5706 param_type
& operator=(const param_type
&) = default;
5708 std::vector
<_RealType
>
5713 std::vector
<_RealType
> __tmp(2);
5714 __tmp
[1] = _RealType(1);
5723 { return _M_den
.empty() ? std::vector
<double>(2, 1.0) : _M_den
; }
5726 operator==(const param_type
& __p1
, const param_type
& __p2
)
5727 { return __p1
._M_int
== __p2
._M_int
&& __p1
._M_den
== __p2
._M_den
; }
5730 operator!=(const param_type
& __p1
, const param_type
& __p2
)
5731 { return !(__p1
== __p2
); }
5737 std::vector
<_RealType
> _M_int
;
5738 std::vector
<double> _M_den
;
5739 std::vector
<double> _M_cp
;
5740 std::vector
<double> _M_m
;
5744 piecewise_linear_distribution()
5748 template<typename _InputIteratorB
, typename _InputIteratorW
>
5749 piecewise_linear_distribution(_InputIteratorB __bfirst
,
5750 _InputIteratorB __bend
,
5751 _InputIteratorW __wbegin
)
5752 : _M_param(__bfirst
, __bend
, __wbegin
)
5755 template<typename _Func
>
5756 piecewise_linear_distribution(initializer_list
<_RealType
> __bl
,
5758 : _M_param(__bl
, __fw
)
5761 template<typename _Func
>
5762 piecewise_linear_distribution(size_t __nw
,
5763 _RealType __xmin
, _RealType __xmax
,
5765 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5769 piecewise_linear_distribution(const param_type
& __p
)
5774 * Resets the distribution state.
5781 * @brief Return the intervals of the distribution.
5783 std::vector
<_RealType
>
5786 if (_M_param
._M_int
.empty())
5788 std::vector
<_RealType
> __tmp(2);
5789 __tmp
[1] = _RealType(1);
5793 return _M_param
._M_int
;
5797 * @brief Return a vector of the probability densities of the
5803 return _M_param
._M_den
.empty()
5804 ? std::vector
<double>(2, 1.0) : _M_param
._M_den
;
5808 * @brief Returns the parameter set of the distribution.
5812 { return _M_param
; }
5815 * @brief Sets the parameter set of the distribution.
5816 * @param __param The new parameter set of the distribution.
5819 param(const param_type
& __param
)
5820 { _M_param
= __param
; }
5823 * @brief Returns the greatest lower bound value of the distribution.
5828 return _M_param
._M_int
.empty()
5829 ? result_type(0) : _M_param
._M_int
.front();
5833 * @brief Returns the least upper bound value of the distribution.
5838 return _M_param
._M_int
.empty()
5839 ? result_type(1) : _M_param
._M_int
.back();
5843 * @brief Generating functions.
5845 template<typename _UniformRandomNumberGenerator
>
5847 operator()(_UniformRandomNumberGenerator
& __urng
)
5848 { return this->operator()(__urng
, _M_param
); }
5850 template<typename _UniformRandomNumberGenerator
>
5852 operator()(_UniformRandomNumberGenerator
& __urng
,
5853 const param_type
& __p
);
5855 template<typename _ForwardIterator
,
5856 typename _UniformRandomNumberGenerator
>
5858 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5859 _UniformRandomNumberGenerator
& __urng
)
5860 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5862 template<typename _ForwardIterator
,
5863 typename _UniformRandomNumberGenerator
>
5865 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5866 _UniformRandomNumberGenerator
& __urng
,
5867 const param_type
& __p
)
5868 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5870 template<typename _UniformRandomNumberGenerator
>
5872 __generate(result_type
* __f
, result_type
* __t
,
5873 _UniformRandomNumberGenerator
& __urng
,
5874 const param_type
& __p
)
5875 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5878 * @brief Return true if two piecewise linear distributions have the
5882 operator==(const piecewise_linear_distribution
& __d1
,
5883 const piecewise_linear_distribution
& __d2
)
5884 { return __d1
._M_param
== __d2
._M_param
; }
5887 * @brief Inserts a %piecewise_linear_distribution random number
5888 * distribution @p __x into the output stream @p __os.
5890 * @param __os An output stream.
5891 * @param __x A %piecewise_linear_distribution random number
5894 * @returns The output stream with the state of @p __x inserted or in
5897 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5898 friend std::basic_ostream
<_CharT
, _Traits
>&
5899 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5900 const std::piecewise_linear_distribution
<_RealType1
>& __x
);
5903 * @brief Extracts a %piecewise_linear_distribution random number
5904 * distribution @p __x from the input stream @p __is.
5906 * @param __is An input stream.
5907 * @param __x A %piecewise_linear_distribution random number
5910 * @returns The input stream with @p __x extracted or in an error
5913 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5914 friend std::basic_istream
<_CharT
, _Traits
>&
5915 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5916 std::piecewise_linear_distribution
<_RealType1
>& __x
);
5919 template<typename _ForwardIterator
,
5920 typename _UniformRandomNumberGenerator
>
5922 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5923 _UniformRandomNumberGenerator
& __urng
,
5924 const param_type
& __p
);
5926 param_type _M_param
;
5930 * @brief Return true if two piecewise linear distributions have
5931 * different parameters.
5933 template<typename _RealType
>
5935 operator!=(const std::piecewise_linear_distribution
<_RealType
>& __d1
,
5936 const std::piecewise_linear_distribution
<_RealType
>& __d2
)
5937 { return !(__d1
== __d2
); }
5940 /* @} */ // group random_distributions_poisson
5942 /* @} */ // group random_distributions
5945 * @addtogroup random_utilities Random Number Utilities
5951 * @brief The seed_seq class generates sequences of seeds for random
5952 * number generators.
5957 /** The type of the seed vales. */
5958 typedef uint_least32_t result_type
;
5960 /** Default constructor. */
5965 template<typename _IntType
>
5966 seed_seq(std::initializer_list
<_IntType
> il
);
5968 template<typename _InputIterator
>
5969 seed_seq(_InputIterator __begin
, _InputIterator __end
);
5971 // generating functions
5972 template<typename _RandomAccessIterator
>
5974 generate(_RandomAccessIterator __begin
, _RandomAccessIterator __end
);
5976 // property functions
5977 size_t size() const noexcept
5978 { return _M_v
.size(); }
5980 template<typename OutputIterator
>
5982 param(OutputIterator __dest
) const
5983 { std::copy(_M_v
.begin(), _M_v
.end(), __dest
); }
5985 // no copy functions
5986 seed_seq(const seed_seq
&) = delete;
5987 seed_seq
& operator=(const seed_seq
&) = delete;
5990 std::vector
<result_type
> _M_v
;
5993 /* @} */ // group random_utilities
5995 /* @} */ // group random
5997 _GLIBCXX_END_NAMESPACE_VERSION