1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009, 2010, 2011, 2012 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}
36 namespace std
_GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 // [26.4] Random number generation
43 * @defgroup random Random Number Generation
46 * A facility for generating random numbers on selected distributions.
51 * @brief A function template for converting the output of a (integral)
52 * uniform random number generator to a floatng point result in the range
55 template<typename _RealType
, size_t __bits
,
56 typename _UniformRandomNumberGenerator
>
58 generate_canonical(_UniformRandomNumberGenerator
& __g
);
60 _GLIBCXX_END_NAMESPACE_VERSION
63 * Implementation-space details.
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _UIntType
, size_t __w
,
70 bool = __w
< static_cast<size_t>
71 (std::numeric_limits
<_UIntType
>::digits
)>
73 { static const _UIntType __value
= 0; };
75 template<typename _UIntType
, size_t __w
>
76 struct _Shift
<_UIntType
, __w
, true>
77 { static const _UIntType __value
= _UIntType(1) << __w
; };
80 int __which
= ((__s
<= __CHAR_BIT__
* sizeof (int))
81 + (__s
<= __CHAR_BIT__
* sizeof (long))
82 + (__s
<= __CHAR_BIT__
* sizeof (long long))
83 /* assume long long no bigger than __int128 */
85 struct _Select_uint_least_t
87 static_assert(__which
< 0, /* needs to be dependent */
88 "sorry, would be too much trouble for a slow result");
92 struct _Select_uint_least_t
<__s
, 4>
93 { typedef unsigned int type
; };
96 struct _Select_uint_least_t
<__s
, 3>
97 { typedef unsigned long type
; };
100 struct _Select_uint_least_t
<__s
, 2>
101 { typedef unsigned long long type
; };
103 #ifdef _GLIBCXX_USE_INT128
105 struct _Select_uint_least_t
<__s
, 1>
106 { typedef unsigned __int128 type
; };
109 // Assume a != 0, a < m, c < m, x < m.
110 template<typename _Tp
, _Tp __m
, _Tp __a
, _Tp __c
,
111 bool __big_enough
= (!(__m
& (__m
- 1))
112 || (_Tp(-1) - __c
) / __a
>= __m
- 1),
113 bool __schrage_ok
= __m
% __a
< __m
/ __a
>
116 typedef typename _Select_uint_least_t
<std::__lg(__a
)
117 + std::__lg(__m
) + 2>::type _Tp2
;
120 { return static_cast<_Tp
>((_Tp2(__a
) * __x
+ __c
) % __m
); }
124 template<typename _Tp
, _Tp __m
, _Tp __a
, _Tp __c
>
125 struct _Mod
<_Tp
, __m
, __a
, __c
, false, true>
132 // - for m == 2^n or m == 0, unsigned integer overflow is safe.
133 // - a * (m - 1) + c fits in _Tp, there is no overflow.
134 template<typename _Tp
, _Tp __m
, _Tp __a
, _Tp __c
, bool __s
>
135 struct _Mod
<_Tp
, __m
, __a
, __c
, true, __s
>
140 _Tp __res
= __a
* __x
+ __c
;
147 template<typename _Tp
, _Tp __m
, _Tp __a
= 1, _Tp __c
= 0>
150 { return _Mod
<_Tp
, __m
, __a
, __c
>::__calc(__x
); }
153 * An adaptor class for converting the output of any Generator into
154 * the input for a specific Distribution.
156 template<typename _Engine
, typename _DInputType
>
161 _Adaptor(_Engine
& __g
)
166 { return _DInputType(0); }
170 { return _DInputType(1); }
173 * Converts a value generated by the adapted random number generator
174 * into a value in the input domain for the dependent random number
180 return std::generate_canonical
<_DInputType
,
181 std::numeric_limits
<_DInputType
>::digits
,
189 _GLIBCXX_END_NAMESPACE_VERSION
190 } // namespace __detail
192 _GLIBCXX_BEGIN_NAMESPACE_VERSION
195 * @addtogroup random_generators Random Number Generators
198 * These classes define objects which provide random or pseudorandom
199 * numbers, either from a discrete or a continuous interval. The
200 * random number generator supplied as a part of this library are
201 * all uniform random number generators which provide a sequence of
202 * random number uniformly distributed over their range.
204 * A number generator is a function object with an operator() that
205 * takes zero arguments and returns a number.
207 * A compliant random number generator must satisfy the following
208 * requirements. <table border=1 cellpadding=10 cellspacing=0>
209 * <caption align=top>Random Number Generator Requirements</caption>
210 * <tr><td>To be documented.</td></tr> </table>
216 * @brief A model of a linear congruential random number generator.
218 * A random number generator that produces pseudorandom numbers via
221 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
224 * The template parameter @p _UIntType must be an unsigned integral type
225 * large enough to store values up to (__m-1). If the template parameter
226 * @p __m is 0, the modulus @p __m used is
227 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
228 * parameters @p __a and @p __c must be less than @p __m.
230 * The size of the state is @f$1@f$.
232 template<typename _UIntType
, _UIntType __a
, _UIntType __c
, _UIntType __m
>
233 class linear_congruential_engine
235 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
236 "substituting _UIntType not an unsigned integral type");
237 static_assert(__m
== 0u || (__a
< __m
&& __c
< __m
),
238 "template argument substituting __m out of bounds");
241 /** The type of the generated random value. */
242 typedef _UIntType result_type
;
244 /** The multiplier. */
245 static constexpr result_type multiplier
= __a
;
247 static constexpr result_type increment
= __c
;
249 static constexpr result_type modulus
= __m
;
250 static constexpr result_type default_seed
= 1u;
253 * @brief Constructs a %linear_congruential_engine random number
254 * generator engine with seed @p __s. The default seed value
257 * @param __s The initial seed value.
260 linear_congruential_engine(result_type __s
= default_seed
)
264 * @brief Constructs a %linear_congruential_engine random number
265 * generator engine seeded from the seed sequence @p __q.
267 * @param __q the seed sequence.
269 template<typename _Sseq
, typename
= typename
270 std::enable_if
<!std::is_same
<_Sseq
, linear_congruential_engine
>::value
>
273 linear_congruential_engine(_Sseq
& __q
)
277 * @brief Reseeds the %linear_congruential_engine random number generator
278 * engine sequence to the seed @p __s.
280 * @param __s The new seed.
283 seed(result_type __s
= default_seed
);
286 * @brief Reseeds the %linear_congruential_engine random number generator
288 * sequence using values from the seed sequence @p __q.
290 * @param __q the seed sequence.
292 template<typename _Sseq
>
293 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
297 * @brief Gets the smallest possible value in the output range.
299 * The minimum depends on the @p __c parameter: if it is zero, the
300 * minimum generated must be > 0, otherwise 0 is allowed.
302 static constexpr result_type
304 { return __c
== 0u ? 1u : 0u; }
307 * @brief Gets the largest possible value in the output range.
309 static constexpr result_type
314 * @brief Discard a sequence of random numbers.
317 discard(unsigned long long __z
)
319 for (; __z
!= 0ULL; --__z
)
324 * @brief Gets the next random number in the sequence.
329 _M_x
= __detail::__mod
<_UIntType
, __m
, __a
, __c
>(_M_x
);
334 * @brief Compares two linear congruential random number generator
335 * objects of the same type for equality.
337 * @param __lhs A linear congruential random number generator object.
338 * @param __rhs Another linear congruential random number generator
341 * @returns true if the infinite sequences of generated values
342 * would be equal, false otherwise.
345 operator==(const linear_congruential_engine
& __lhs
,
346 const linear_congruential_engine
& __rhs
)
347 { return __lhs
._M_x
== __rhs
._M_x
; }
350 * @brief Writes the textual representation of the state x(i) of x to
353 * @param __os The output stream.
354 * @param __lcr A % linear_congruential_engine random number generator.
357 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
358 _UIntType1 __m1
, typename _CharT
, typename _Traits
>
359 friend std::basic_ostream
<_CharT
, _Traits
>&
360 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
361 const std::linear_congruential_engine
<_UIntType1
,
362 __a1
, __c1
, __m1
>& __lcr
);
365 * @brief Sets the state of the engine by reading its textual
366 * representation from @p __is.
368 * The textual representation must have been previously written using
369 * an output stream whose imbued locale and whose type's template
370 * specialization arguments _CharT and _Traits were the same as those
373 * @param __is The input stream.
374 * @param __lcr A % linear_congruential_engine random number generator.
377 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
378 _UIntType1 __m1
, typename _CharT
, typename _Traits
>
379 friend std::basic_istream
<_CharT
, _Traits
>&
380 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
381 std::linear_congruential_engine
<_UIntType1
, __a1
,
389 * @brief Compares two linear congruential random number generator
390 * objects of the same type for inequality.
392 * @param __lhs A linear congruential random number generator object.
393 * @param __rhs Another linear congruential random number generator
396 * @returns true if the infinite sequences of generated values
397 * would be different, false otherwise.
399 template<typename _UIntType
, _UIntType __a
, _UIntType __c
, _UIntType __m
>
401 operator!=(const std::linear_congruential_engine
<_UIntType
, __a
,
403 const std::linear_congruential_engine
<_UIntType
, __a
,
405 { return !(__lhs
== __rhs
); }
409 * A generalized feedback shift register discrete random number generator.
411 * This algorithm avoids multiplication and division and is designed to be
412 * friendly to a pipelined architecture. If the parameters are chosen
413 * correctly, this generator will produce numbers with a very long period and
414 * fairly good apparent entropy, although still not cryptographically strong.
416 * The best way to use this generator is with the predefined mt19937 class.
418 * This algorithm was originally invented by Makoto Matsumoto and
421 * @tparam __w Word size, the number of bits in each element of
423 * @tparam __n The degree of recursion.
424 * @tparam __m The period parameter.
425 * @tparam __r The separation point bit index.
426 * @tparam __a The last row of the twist matrix.
427 * @tparam __u The first right-shift tempering matrix parameter.
428 * @tparam __d The first right-shift tempering matrix mask.
429 * @tparam __s The first left-shift tempering matrix parameter.
430 * @tparam __b The first left-shift tempering matrix mask.
431 * @tparam __t The second left-shift tempering matrix parameter.
432 * @tparam __c The second left-shift tempering matrix mask.
433 * @tparam __l The second right-shift tempering matrix parameter.
434 * @tparam __f Initialization multiplier.
436 template<typename _UIntType
, size_t __w
,
437 size_t __n
, size_t __m
, size_t __r
,
438 _UIntType __a
, size_t __u
, _UIntType __d
, size_t __s
,
439 _UIntType __b
, size_t __t
,
440 _UIntType __c
, size_t __l
, _UIntType __f
>
441 class mersenne_twister_engine
443 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
444 "substituting _UIntType not an unsigned integral type");
445 static_assert(1u <= __m
&& __m
<= __n
,
446 "template argument substituting __m out of bounds");
447 static_assert(__r
<= __w
, "template argument substituting "
449 static_assert(__u
<= __w
, "template argument substituting "
451 static_assert(__s
<= __w
, "template argument substituting "
453 static_assert(__t
<= __w
, "template argument substituting "
455 static_assert(__l
<= __w
, "template argument substituting "
457 static_assert(__w
<= std::numeric_limits
<_UIntType
>::digits
,
458 "template argument substituting __w out of bound");
459 static_assert(__a
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
460 "template argument substituting __a out of bound");
461 static_assert(__b
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
462 "template argument substituting __b out of bound");
463 static_assert(__c
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
464 "template argument substituting __c out of bound");
465 static_assert(__d
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
466 "template argument substituting __d out of bound");
467 static_assert(__f
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
468 "template argument substituting __f out of bound");
471 /** The type of the generated random value. */
472 typedef _UIntType result_type
;
475 static constexpr size_t word_size
= __w
;
476 static constexpr size_t state_size
= __n
;
477 static constexpr size_t shift_size
= __m
;
478 static constexpr size_t mask_bits
= __r
;
479 static constexpr result_type xor_mask
= __a
;
480 static constexpr size_t tempering_u
= __u
;
481 static constexpr result_type tempering_d
= __d
;
482 static constexpr size_t tempering_s
= __s
;
483 static constexpr result_type tempering_b
= __b
;
484 static constexpr size_t tempering_t
= __t
;
485 static constexpr result_type tempering_c
= __c
;
486 static constexpr size_t tempering_l
= __l
;
487 static constexpr result_type initialization_multiplier
= __f
;
488 static constexpr result_type default_seed
= 5489u;
490 // constructors and member function
492 mersenne_twister_engine(result_type __sd
= default_seed
)
496 * @brief Constructs a %mersenne_twister_engine random number generator
497 * engine seeded from the seed sequence @p __q.
499 * @param __q the seed sequence.
501 template<typename _Sseq
, typename
= typename
502 std::enable_if
<!std::is_same
<_Sseq
, mersenne_twister_engine
>::value
>
505 mersenne_twister_engine(_Sseq
& __q
)
509 seed(result_type __sd
= default_seed
);
511 template<typename _Sseq
>
512 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
516 * @brief Gets the smallest possible value in the output range.
518 static constexpr result_type
523 * @brief Gets the largest possible value in the output range.
525 static constexpr result_type
527 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
530 * @brief Discard a sequence of random numbers.
533 discard(unsigned long long __z
);
539 * @brief Compares two % mersenne_twister_engine random number generator
540 * objects of the same type for equality.
542 * @param __lhs A % mersenne_twister_engine random number generator
544 * @param __rhs Another % mersenne_twister_engine random number
547 * @returns true if the infinite sequences of generated values
548 * would be equal, false otherwise.
551 operator==(const mersenne_twister_engine
& __lhs
,
552 const mersenne_twister_engine
& __rhs
)
553 { return (std::equal(__lhs
._M_x
, __lhs
._M_x
+ state_size
, __rhs
._M_x
)
554 && __lhs
._M_p
== __rhs
._M_p
); }
557 * @brief Inserts the current state of a % mersenne_twister_engine
558 * random number generator engine @p __x into the output stream
561 * @param __os An output stream.
562 * @param __x A % mersenne_twister_engine random number generator
565 * @returns The output stream with the state of @p __x inserted or in
568 template<typename _UIntType1
,
569 size_t __w1
, size_t __n1
,
570 size_t __m1
, size_t __r1
,
571 _UIntType1 __a1
, size_t __u1
,
572 _UIntType1 __d1
, size_t __s1
,
573 _UIntType1 __b1
, size_t __t1
,
574 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
575 typename _CharT
, typename _Traits
>
576 friend std::basic_ostream
<_CharT
, _Traits
>&
577 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
578 const std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
,
579 __m1
, __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
583 * @brief Extracts the current state of a % mersenne_twister_engine
584 * random number generator engine @p __x from the input stream
587 * @param __is An input stream.
588 * @param __x A % mersenne_twister_engine random number generator
591 * @returns The input stream with the state of @p __x extracted or in
594 template<typename _UIntType1
,
595 size_t __w1
, size_t __n1
,
596 size_t __m1
, size_t __r1
,
597 _UIntType1 __a1
, size_t __u1
,
598 _UIntType1 __d1
, size_t __s1
,
599 _UIntType1 __b1
, size_t __t1
,
600 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
601 typename _CharT
, typename _Traits
>
602 friend std::basic_istream
<_CharT
, _Traits
>&
603 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
604 std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
, __m1
,
605 __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
611 _UIntType _M_x
[state_size
];
616 * @brief Compares two % mersenne_twister_engine random number generator
617 * objects of the same type for inequality.
619 * @param __lhs A % mersenne_twister_engine random number generator
621 * @param __rhs Another % mersenne_twister_engine random number
624 * @returns true if the infinite sequences of generated values
625 * would be different, false otherwise.
627 template<typename _UIntType
, size_t __w
,
628 size_t __n
, size_t __m
, size_t __r
,
629 _UIntType __a
, size_t __u
, _UIntType __d
, size_t __s
,
630 _UIntType __b
, size_t __t
,
631 _UIntType __c
, size_t __l
, _UIntType __f
>
633 operator!=(const std::mersenne_twister_engine
<_UIntType
, __w
, __n
, __m
,
634 __r
, __a
, __u
, __d
, __s
, __b
, __t
, __c
, __l
, __f
>& __lhs
,
635 const std::mersenne_twister_engine
<_UIntType
, __w
, __n
, __m
,
636 __r
, __a
, __u
, __d
, __s
, __b
, __t
, __c
, __l
, __f
>& __rhs
)
637 { return !(__lhs
== __rhs
); }
641 * @brief The Marsaglia-Zaman generator.
643 * This is a model of a Generalized Fibonacci discrete random number
644 * generator, sometimes referred to as the SWC generator.
646 * A discrete random number generator that produces pseudorandom
649 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
652 * The size of the state is @f$r@f$
653 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
655 * @var _M_x The state of the generator. This is a ring buffer.
656 * @var _M_carry The carry.
657 * @var _M_p Current index of x(i - r).
659 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
660 class subtract_with_carry_engine
662 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
663 "substituting _UIntType not an unsigned integral type");
664 static_assert(0u < __s
&& __s
< __r
,
665 "template argument substituting __s out of bounds");
666 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
667 "template argument substituting __w out of bounds");
670 /** The type of the generated random value. */
671 typedef _UIntType result_type
;
674 static constexpr size_t word_size
= __w
;
675 static constexpr size_t short_lag
= __s
;
676 static constexpr size_t long_lag
= __r
;
677 static constexpr result_type default_seed
= 19780503u;
680 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
681 * random number generator.
684 subtract_with_carry_engine(result_type __sd
= default_seed
)
688 * @brief Constructs a %subtract_with_carry_engine random number engine
689 * seeded from the seed sequence @p __q.
691 * @param __q the seed sequence.
693 template<typename _Sseq
, typename
= typename
694 std::enable_if
<!std::is_same
<_Sseq
, subtract_with_carry_engine
>::value
>
697 subtract_with_carry_engine(_Sseq
& __q
)
701 * @brief Seeds the initial state @f$x_0@f$ of the random number
704 * N1688[4.19] modifies this as follows. If @p __value == 0,
705 * sets value to 19780503. In any case, with a linear
706 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
707 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
708 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
709 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
710 * set carry to 1, otherwise sets carry to 0.
713 seed(result_type __sd
= default_seed
);
716 * @brief Seeds the initial state @f$x_0@f$ of the
717 * % subtract_with_carry_engine random number generator.
719 template<typename _Sseq
>
720 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
724 * @brief Gets the inclusive minimum value of the range of random
725 * integers returned by this generator.
727 static constexpr result_type
732 * @brief Gets the inclusive maximum value of the range of random
733 * integers returned by this generator.
735 static constexpr result_type
737 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
740 * @brief Discard a sequence of random numbers.
743 discard(unsigned long long __z
)
745 for (; __z
!= 0ULL; --__z
)
750 * @brief Gets the next random number in the sequence.
756 * @brief Compares two % subtract_with_carry_engine random number
757 * generator objects of the same type for equality.
759 * @param __lhs A % subtract_with_carry_engine random number generator
761 * @param __rhs Another % subtract_with_carry_engine random number
764 * @returns true if the infinite sequences of generated values
765 * would be equal, false otherwise.
768 operator==(const subtract_with_carry_engine
& __lhs
,
769 const subtract_with_carry_engine
& __rhs
)
770 { return (std::equal(__lhs
._M_x
, __lhs
._M_x
+ long_lag
, __rhs
._M_x
)
771 && __lhs
._M_carry
== __rhs
._M_carry
772 && __lhs
._M_p
== __rhs
._M_p
); }
775 * @brief Inserts the current state of a % subtract_with_carry_engine
776 * random number generator engine @p __x into the output stream
779 * @param __os An output stream.
780 * @param __x A % subtract_with_carry_engine random number generator
783 * @returns The output stream with the state of @p __x inserted or in
786 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
787 typename _CharT
, typename _Traits
>
788 friend std::basic_ostream
<_CharT
, _Traits
>&
789 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
790 const std::subtract_with_carry_engine
<_UIntType1
, __w1
,
794 * @brief Extracts the current state of a % subtract_with_carry_engine
795 * random number generator engine @p __x from the input stream
798 * @param __is An input stream.
799 * @param __x A % subtract_with_carry_engine random number generator
802 * @returns The input stream with the state of @p __x extracted or in
805 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
806 typename _CharT
, typename _Traits
>
807 friend std::basic_istream
<_CharT
, _Traits
>&
808 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
809 std::subtract_with_carry_engine
<_UIntType1
, __w1
,
813 _UIntType _M_x
[long_lag
];
819 * @brief Compares two % subtract_with_carry_engine random number
820 * generator objects of the same type for inequality.
822 * @param __lhs A % subtract_with_carry_engine random number generator
824 * @param __rhs Another % subtract_with_carry_engine random number
827 * @returns true if the infinite sequences of generated values
828 * would be different, false otherwise.
830 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
832 operator!=(const std::subtract_with_carry_engine
<_UIntType
, __w
,
834 const std::subtract_with_carry_engine
<_UIntType
, __w
,
836 { return !(__lhs
== __rhs
); }
840 * Produces random numbers from some base engine by discarding blocks of
843 * 0 <= @p __r <= @p __p
845 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
846 class discard_block_engine
848 static_assert(1 <= __r
&& __r
<= __p
,
849 "template argument substituting __r out of bounds");
852 /** The type of the generated random value. */
853 typedef typename
_RandomNumberEngine::result_type result_type
;
856 static constexpr size_t block_size
= __p
;
857 static constexpr size_t used_block
= __r
;
860 * @brief Constructs a default %discard_block_engine engine.
862 * The underlying engine is default constructed as well.
864 discard_block_engine()
865 : _M_b(), _M_n(0) { }
868 * @brief Copy constructs a %discard_block_engine engine.
870 * Copies an existing base class random number generator.
871 * @param __rng An existing (base class) engine object.
874 discard_block_engine(const _RandomNumberEngine
& __rng
)
875 : _M_b(__rng
), _M_n(0) { }
878 * @brief Move constructs a %discard_block_engine engine.
880 * Copies an existing base class random number generator.
881 * @param __rng An existing (base class) engine object.
884 discard_block_engine(_RandomNumberEngine
&& __rng
)
885 : _M_b(std::move(__rng
)), _M_n(0) { }
888 * @brief Seed constructs a %discard_block_engine engine.
890 * Constructs the underlying generator engine seeded with @p __s.
891 * @param __s A seed value for the base class engine.
894 discard_block_engine(result_type __s
)
895 : _M_b(__s
), _M_n(0) { }
898 * @brief Generator construct a %discard_block_engine engine.
900 * @param __q A seed sequence.
902 template<typename _Sseq
, typename
= typename
903 std::enable_if
<!std::is_same
<_Sseq
, discard_block_engine
>::value
904 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
907 discard_block_engine(_Sseq
& __q
)
912 * @brief Reseeds the %discard_block_engine object with the default
913 * seed for the underlying base class generator engine.
923 * @brief Reseeds the %discard_block_engine object with the default
924 * seed for the underlying base class generator engine.
927 seed(result_type __s
)
934 * @brief Reseeds the %discard_block_engine object with the given seed
936 * @param __q A seed generator function.
938 template<typename _Sseq
>
947 * @brief Gets a const reference to the underlying generator engine
950 const _RandomNumberEngine
&
951 base() const noexcept
955 * @brief Gets the minimum value in the generated random number range.
957 static constexpr result_type
959 { return _RandomNumberEngine::min(); }
962 * @brief Gets the maximum value in the generated random number range.
964 static constexpr result_type
966 { return _RandomNumberEngine::max(); }
969 * @brief Discard a sequence of random numbers.
972 discard(unsigned long long __z
)
974 for (; __z
!= 0ULL; --__z
)
979 * @brief Gets the next value in the generated random number sequence.
985 * @brief Compares two %discard_block_engine random number generator
986 * objects of the same type for equality.
988 * @param __lhs A %discard_block_engine random number generator object.
989 * @param __rhs Another %discard_block_engine random number generator
992 * @returns true if the infinite sequences of generated values
993 * would be equal, false otherwise.
996 operator==(const discard_block_engine
& __lhs
,
997 const discard_block_engine
& __rhs
)
998 { return __lhs
._M_b
== __rhs
._M_b
&& __lhs
._M_n
== __rhs
._M_n
; }
1001 * @brief Inserts the current state of a %discard_block_engine random
1002 * number generator engine @p __x into the output stream
1005 * @param __os An output stream.
1006 * @param __x A %discard_block_engine random number generator engine.
1008 * @returns The output stream with the state of @p __x inserted or in
1011 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1012 typename _CharT
, typename _Traits
>
1013 friend std::basic_ostream
<_CharT
, _Traits
>&
1014 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1015 const std::discard_block_engine
<_RandomNumberEngine1
,
1019 * @brief Extracts the current state of a % subtract_with_carry_engine
1020 * random number generator engine @p __x from the input stream
1023 * @param __is An input stream.
1024 * @param __x A %discard_block_engine random number generator engine.
1026 * @returns The input stream with the state of @p __x extracted or in
1029 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1030 typename _CharT
, typename _Traits
>
1031 friend std::basic_istream
<_CharT
, _Traits
>&
1032 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1033 std::discard_block_engine
<_RandomNumberEngine1
,
1037 _RandomNumberEngine _M_b
;
1042 * @brief Compares two %discard_block_engine random number generator
1043 * objects of the same type for inequality.
1045 * @param __lhs A %discard_block_engine random number generator object.
1046 * @param __rhs Another %discard_block_engine random number generator
1049 * @returns true if the infinite sequences of generated values
1050 * would be different, false otherwise.
1052 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
1054 operator!=(const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1056 const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1058 { return !(__lhs
== __rhs
); }
1062 * Produces random numbers by combining random numbers from some base
1063 * engine to produce random numbers with a specifies number of bits @p __w.
1065 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1066 class independent_bits_engine
1068 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
1069 "substituting _UIntType not an unsigned integral type");
1070 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
1071 "template argument substituting __w out of bounds");
1074 /** The type of the generated random value. */
1075 typedef _UIntType result_type
;
1078 * @brief Constructs a default %independent_bits_engine engine.
1080 * The underlying engine is default constructed as well.
1082 independent_bits_engine()
1086 * @brief Copy constructs a %independent_bits_engine engine.
1088 * Copies an existing base class random number generator.
1089 * @param __rng An existing (base class) engine object.
1092 independent_bits_engine(const _RandomNumberEngine
& __rng
)
1096 * @brief Move constructs a %independent_bits_engine engine.
1098 * Copies an existing base class random number generator.
1099 * @param __rng An existing (base class) engine object.
1102 independent_bits_engine(_RandomNumberEngine
&& __rng
)
1103 : _M_b(std::move(__rng
)) { }
1106 * @brief Seed constructs a %independent_bits_engine engine.
1108 * Constructs the underlying generator engine seeded with @p __s.
1109 * @param __s A seed value for the base class engine.
1112 independent_bits_engine(result_type __s
)
1116 * @brief Generator construct a %independent_bits_engine engine.
1118 * @param __q A seed sequence.
1120 template<typename _Sseq
, typename
= typename
1121 std::enable_if
<!std::is_same
<_Sseq
, independent_bits_engine
>::value
1122 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1125 independent_bits_engine(_Sseq
& __q
)
1130 * @brief Reseeds the %independent_bits_engine object with the default
1131 * seed for the underlying base class generator engine.
1138 * @brief Reseeds the %independent_bits_engine object with the default
1139 * seed for the underlying base class generator engine.
1142 seed(result_type __s
)
1146 * @brief Reseeds the %independent_bits_engine object with the given
1148 * @param __q A seed generator function.
1150 template<typename _Sseq
>
1156 * @brief Gets a const reference to the underlying generator engine
1159 const _RandomNumberEngine
&
1160 base() const noexcept
1164 * @brief Gets the minimum value in the generated random number range.
1166 static constexpr result_type
1171 * @brief Gets the maximum value in the generated random number range.
1173 static constexpr result_type
1175 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
1178 * @brief Discard a sequence of random numbers.
1181 discard(unsigned long long __z
)
1183 for (; __z
!= 0ULL; --__z
)
1188 * @brief Gets the next value in the generated random number sequence.
1194 * @brief Compares two %independent_bits_engine random number generator
1195 * objects of the same type for equality.
1197 * @param __lhs A %independent_bits_engine random number generator
1199 * @param __rhs Another %independent_bits_engine random number generator
1202 * @returns true if the infinite sequences of generated values
1203 * would be equal, false otherwise.
1206 operator==(const independent_bits_engine
& __lhs
,
1207 const independent_bits_engine
& __rhs
)
1208 { return __lhs
._M_b
== __rhs
._M_b
; }
1211 * @brief Extracts the current state of a % subtract_with_carry_engine
1212 * random number generator engine @p __x from the input stream
1215 * @param __is An input stream.
1216 * @param __x A %independent_bits_engine random number generator
1219 * @returns The input stream with the state of @p __x extracted or in
1222 template<typename _CharT
, typename _Traits
>
1223 friend std::basic_istream
<_CharT
, _Traits
>&
1224 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1225 std::independent_bits_engine
<_RandomNumberEngine
,
1226 __w
, _UIntType
>& __x
)
1233 _RandomNumberEngine _M_b
;
1237 * @brief Compares two %independent_bits_engine random number generator
1238 * objects of the same type for inequality.
1240 * @param __lhs A %independent_bits_engine random number generator
1242 * @param __rhs Another %independent_bits_engine random number generator
1245 * @returns true if the infinite sequences of generated values
1246 * would be different, false otherwise.
1248 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1250 operator!=(const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1252 const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1254 { return !(__lhs
== __rhs
); }
1257 * @brief Inserts the current state of a %independent_bits_engine random
1258 * number generator engine @p __x into the output stream @p __os.
1260 * @param __os An output stream.
1261 * @param __x A %independent_bits_engine random number generator engine.
1263 * @returns The output stream with the state of @p __x inserted or in
1266 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
,
1267 typename _CharT
, typename _Traits
>
1268 std::basic_ostream
<_CharT
, _Traits
>&
1269 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1270 const std::independent_bits_engine
<_RandomNumberEngine
,
1271 __w
, _UIntType
>& __x
)
1279 * @brief Produces random numbers by combining random numbers from some
1280 * base engine to produce random numbers with a specifies number of bits
1283 template<typename _RandomNumberEngine
, size_t __k
>
1284 class shuffle_order_engine
1286 static_assert(1u <= __k
, "template argument substituting "
1287 "__k out of bound");
1290 /** The type of the generated random value. */
1291 typedef typename
_RandomNumberEngine::result_type result_type
;
1293 static constexpr size_t table_size
= __k
;
1296 * @brief Constructs a default %shuffle_order_engine engine.
1298 * The underlying engine is default constructed as well.
1300 shuffle_order_engine()
1302 { _M_initialize(); }
1305 * @brief Copy constructs a %shuffle_order_engine engine.
1307 * Copies an existing base class random number generator.
1308 * @param __rng An existing (base class) engine object.
1311 shuffle_order_engine(const _RandomNumberEngine
& __rng
)
1313 { _M_initialize(); }
1316 * @brief Move constructs a %shuffle_order_engine engine.
1318 * Copies an existing base class random number generator.
1319 * @param __rng An existing (base class) engine object.
1322 shuffle_order_engine(_RandomNumberEngine
&& __rng
)
1323 : _M_b(std::move(__rng
))
1324 { _M_initialize(); }
1327 * @brief Seed constructs a %shuffle_order_engine engine.
1329 * Constructs the underlying generator engine seeded with @p __s.
1330 * @param __s A seed value for the base class engine.
1333 shuffle_order_engine(result_type __s
)
1335 { _M_initialize(); }
1338 * @brief Generator construct a %shuffle_order_engine engine.
1340 * @param __q A seed sequence.
1342 template<typename _Sseq
, typename
= typename
1343 std::enable_if
<!std::is_same
<_Sseq
, shuffle_order_engine
>::value
1344 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1347 shuffle_order_engine(_Sseq
& __q
)
1349 { _M_initialize(); }
1352 * @brief Reseeds the %shuffle_order_engine object with the default seed
1353 for the underlying base class generator engine.
1363 * @brief Reseeds the %shuffle_order_engine object with the default seed
1364 * for the underlying base class generator engine.
1367 seed(result_type __s
)
1374 * @brief Reseeds the %shuffle_order_engine object with the given seed
1376 * @param __q A seed generator function.
1378 template<typename _Sseq
>
1387 * Gets a const reference to the underlying generator engine object.
1389 const _RandomNumberEngine
&
1390 base() const noexcept
1394 * Gets the minimum value in the generated random number range.
1396 static constexpr result_type
1398 { return _RandomNumberEngine::min(); }
1401 * Gets the maximum value in the generated random number range.
1403 static constexpr result_type
1405 { return _RandomNumberEngine::max(); }
1408 * Discard a sequence of random numbers.
1411 discard(unsigned long long __z
)
1413 for (; __z
!= 0ULL; --__z
)
1418 * Gets the next value in the generated random number sequence.
1424 * Compares two %shuffle_order_engine random number generator objects
1425 * of the same type for equality.
1427 * @param __lhs A %shuffle_order_engine random number generator object.
1428 * @param __rhs Another %shuffle_order_engine random number generator
1431 * @returns true if the infinite sequences of generated values
1432 * would be equal, false otherwise.
1435 operator==(const shuffle_order_engine
& __lhs
,
1436 const shuffle_order_engine
& __rhs
)
1437 { return (__lhs
._M_b
== __rhs
._M_b
1438 && std::equal(__lhs
._M_v
, __lhs
._M_v
+ __k
, __rhs
._M_v
)
1439 && __lhs
._M_y
== __rhs
._M_y
); }
1442 * @brief Inserts the current state of a %shuffle_order_engine random
1443 * number generator engine @p __x into the output stream
1446 * @param __os An output stream.
1447 * @param __x A %shuffle_order_engine random number generator engine.
1449 * @returns The output stream with the state of @p __x inserted or in
1452 template<typename _RandomNumberEngine1
, size_t __k1
,
1453 typename _CharT
, typename _Traits
>
1454 friend std::basic_ostream
<_CharT
, _Traits
>&
1455 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1456 const std::shuffle_order_engine
<_RandomNumberEngine1
,
1460 * @brief Extracts the current state of a % subtract_with_carry_engine
1461 * random number generator engine @p __x from the input stream
1464 * @param __is An input stream.
1465 * @param __x A %shuffle_order_engine random number generator engine.
1467 * @returns The input stream with the state of @p __x extracted or in
1470 template<typename _RandomNumberEngine1
, size_t __k1
,
1471 typename _CharT
, typename _Traits
>
1472 friend std::basic_istream
<_CharT
, _Traits
>&
1473 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1474 std::shuffle_order_engine
<_RandomNumberEngine1
, __k1
>& __x
);
1477 void _M_initialize()
1479 for (size_t __i
= 0; __i
< __k
; ++__i
)
1484 _RandomNumberEngine _M_b
;
1485 result_type _M_v
[__k
];
1490 * Compares two %shuffle_order_engine random number generator objects
1491 * of the same type for inequality.
1493 * @param __lhs A %shuffle_order_engine random number generator object.
1494 * @param __rhs Another %shuffle_order_engine random number generator
1497 * @returns true if the infinite sequences of generated values
1498 * would be different, false otherwise.
1500 template<typename _RandomNumberEngine
, size_t __k
>
1502 operator!=(const std::shuffle_order_engine
<_RandomNumberEngine
,
1504 const std::shuffle_order_engine
<_RandomNumberEngine
,
1506 { return !(__lhs
== __rhs
); }
1510 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1512 typedef linear_congruential_engine
<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1516 * An alternative LCR (Lehmer Generator function).
1518 typedef linear_congruential_engine
<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1522 * The classic Mersenne Twister.
1525 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1526 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1527 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1529 typedef mersenne_twister_engine
<
1535 0xefc60000UL
, 18, 1812433253UL> mt19937
;
1538 * An alternative Mersenne Twister.
1540 typedef mersenne_twister_engine
<
1543 0xb5026f5aa96619e9ULL
, 29,
1544 0x5555555555555555ULL
, 17,
1545 0x71d67fffeda60000ULL
, 37,
1546 0xfff7eee000000000ULL
, 43,
1547 6364136223846793005ULL> mt19937_64
;
1549 typedef subtract_with_carry_engine
<uint_fast32_t, 24, 10, 24>
1552 typedef subtract_with_carry_engine
<uint_fast64_t, 48, 5, 12>
1555 typedef discard_block_engine
<ranlux24_base
, 223, 23> ranlux24
;
1557 typedef discard_block_engine
<ranlux48_base
, 389, 11> ranlux48
;
1559 typedef shuffle_order_engine
<minstd_rand0
, 256> knuth_b
;
1561 typedef minstd_rand0 default_random_engine
;
1564 * A standard interface to a platform-specific non-deterministic
1565 * random number generator (if any are available).
1570 /** The type of the generated random value. */
1571 typedef unsigned int result_type
;
1573 // constructors, destructors and member functions
1575 #ifdef _GLIBCXX_USE_RANDOM_TR1
1578 random_device(const std::string
& __token
= "default")
1589 random_device(const std::string
& __token
= "mt19937")
1590 { return _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
1653 * @brief Uniform discrete distribution for random numbers.
1654 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1655 * probability throughout the range.
1657 template<typename _IntType
= int>
1658 class uniform_int_distribution
1660 static_assert(std::is_integral
<_IntType
>::value
,
1661 "template argument not an integral type");
1664 /** The type of the range of the distribution. */
1665 typedef _IntType result_type
;
1666 /** Parameter type. */
1669 typedef uniform_int_distribution
<_IntType
> distribution_type
;
1672 param_type(_IntType __a
= 0,
1673 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1674 : _M_a(__a
), _M_b(__b
)
1676 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1688 operator==(const param_type
& __p1
, const param_type
& __p2
)
1689 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1698 * @brief Constructs a uniform distribution object.
1701 uniform_int_distribution(_IntType __a
= 0,
1702 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1703 : _M_param(__a
, __b
)
1707 uniform_int_distribution(const param_type
& __p
)
1712 * @brief Resets the distribution state.
1714 * Does nothing for the uniform integer distribution.
1721 { return _M_param
.a(); }
1725 { return _M_param
.b(); }
1728 * @brief Returns the parameter set of the distribution.
1732 { return _M_param
; }
1735 * @brief Sets the parameter set of the distribution.
1736 * @param __param The new parameter set of the distribution.
1739 param(const param_type
& __param
)
1740 { _M_param
= __param
; }
1743 * @brief Returns the inclusive lower bound of the distribution range.
1747 { return this->a(); }
1750 * @brief Returns the inclusive upper bound of the distribution range.
1754 { return this->b(); }
1757 * @brief Generating functions.
1759 template<typename _UniformRandomNumberGenerator
>
1761 operator()(_UniformRandomNumberGenerator
& __urng
)
1762 { return this->operator()(__urng
, this->param()); }
1764 template<typename _UniformRandomNumberGenerator
>
1766 operator()(_UniformRandomNumberGenerator
& __urng
,
1767 const param_type
& __p
);
1769 template<typename _ForwardIterator
,
1770 typename _UniformRandomNumberGenerator
>
1772 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1773 _UniformRandomNumberGenerator
& __urng
)
1774 { this->__generate(__f
, __t
, __urng
, this->param()); }
1776 template<typename _ForwardIterator
,
1777 typename _UniformRandomNumberGenerator
>
1779 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1780 _UniformRandomNumberGenerator
& __urng
,
1781 const param_type
& __p
)
1782 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1784 template<typename _UniformRandomNumberGenerator
>
1786 __generate(result_type
* __f
, result_type
* __t
,
1787 _UniformRandomNumberGenerator
& __urng
,
1788 const param_type
& __p
)
1789 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1792 template<typename _ForwardIterator
,
1793 typename _UniformRandomNumberGenerator
>
1795 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
1796 _UniformRandomNumberGenerator
& __urng
,
1797 const param_type
& __p
);
1799 param_type _M_param
;
1803 * @brief Return true if two uniform integer distributions have
1804 * the same parameters.
1806 template<typename _IntType
>
1808 operator==(const std::uniform_int_distribution
<_IntType
>& __d1
,
1809 const std::uniform_int_distribution
<_IntType
>& __d2
)
1810 { return __d1
.param() == __d2
.param(); }
1813 * @brief Return true if two uniform integer distributions have
1814 * different parameters.
1816 template<typename _IntType
>
1818 operator!=(const std::uniform_int_distribution
<_IntType
>& __d1
,
1819 const std::uniform_int_distribution
<_IntType
>& __d2
)
1820 { return !(__d1
== __d2
); }
1823 * @brief Inserts a %uniform_int_distribution random number
1824 * distribution @p __x into the output stream @p os.
1826 * @param __os An output stream.
1827 * @param __x A %uniform_int_distribution random number distribution.
1829 * @returns The output stream with the state of @p __x inserted or in
1832 template<typename _IntType
, typename _CharT
, typename _Traits
>
1833 std::basic_ostream
<_CharT
, _Traits
>&
1834 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1835 const std::uniform_int_distribution
<_IntType
>&);
1838 * @brief Extracts a %uniform_int_distribution random number distribution
1839 * @p __x from the input stream @p __is.
1841 * @param __is An input stream.
1842 * @param __x A %uniform_int_distribution random number generator engine.
1844 * @returns The input stream with @p __x extracted or in an error state.
1846 template<typename _IntType
, typename _CharT
, typename _Traits
>
1847 std::basic_istream
<_CharT
, _Traits
>&
1848 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1849 std::uniform_int_distribution
<_IntType
>&);
1853 * @brief Uniform continuous distribution for random numbers.
1855 * A continuous random distribution on the range [min, max) with equal
1856 * probability throughout the range. The URNG should be real-valued and
1857 * deliver number in the range [0, 1).
1859 template<typename _RealType
= double>
1860 class uniform_real_distribution
1862 static_assert(std::is_floating_point
<_RealType
>::value
,
1863 "template argument not a floating point type");
1866 /** The type of the range of the distribution. */
1867 typedef _RealType result_type
;
1868 /** Parameter type. */
1871 typedef uniform_real_distribution
<_RealType
> distribution_type
;
1874 param_type(_RealType __a
= _RealType(0),
1875 _RealType __b
= _RealType(1))
1876 : _M_a(__a
), _M_b(__b
)
1878 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1890 operator==(const param_type
& __p1
, const param_type
& __p2
)
1891 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1900 * @brief Constructs a uniform_real_distribution object.
1902 * @param __a [IN] The lower bound of the distribution.
1903 * @param __b [IN] The upper bound of the distribution.
1906 uniform_real_distribution(_RealType __a
= _RealType(0),
1907 _RealType __b
= _RealType(1))
1908 : _M_param(__a
, __b
)
1912 uniform_real_distribution(const param_type
& __p
)
1917 * @brief Resets the distribution state.
1919 * Does nothing for the uniform real distribution.
1926 { return _M_param
.a(); }
1930 { return _M_param
.b(); }
1933 * @brief Returns the parameter set of the distribution.
1937 { return _M_param
; }
1940 * @brief Sets the parameter set of the distribution.
1941 * @param __param The new parameter set of the distribution.
1944 param(const param_type
& __param
)
1945 { _M_param
= __param
; }
1948 * @brief Returns the inclusive lower bound of the distribution range.
1952 { return this->a(); }
1955 * @brief Returns the inclusive upper bound of the distribution range.
1959 { return this->b(); }
1962 * @brief Generating functions.
1964 template<typename _UniformRandomNumberGenerator
>
1966 operator()(_UniformRandomNumberGenerator
& __urng
)
1967 { return this->operator()(__urng
, this->param()); }
1969 template<typename _UniformRandomNumberGenerator
>
1971 operator()(_UniformRandomNumberGenerator
& __urng
,
1972 const param_type
& __p
)
1974 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1976 return (__aurng() * (__p
.b() - __p
.a())) + __p
.a();
1979 template<typename _ForwardIterator
,
1980 typename _UniformRandomNumberGenerator
>
1982 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1983 _UniformRandomNumberGenerator
& __urng
)
1984 { this->__generate(__f
, __t
, __urng
, this->param()); }
1986 template<typename _ForwardIterator
,
1987 typename _UniformRandomNumberGenerator
>
1989 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1990 _UniformRandomNumberGenerator
& __urng
,
1991 const param_type
& __p
)
1992 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1994 template<typename _UniformRandomNumberGenerator
>
1996 __generate(result_type
* __f
, result_type
* __t
,
1997 _UniformRandomNumberGenerator
& __urng
,
1998 const param_type
& __p
)
1999 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2002 template<typename _ForwardIterator
,
2003 typename _UniformRandomNumberGenerator
>
2005 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2006 _UniformRandomNumberGenerator
& __urng
,
2007 const param_type
& __p
);
2009 param_type _M_param
;
2013 * @brief Return true if two uniform real distributions have
2014 * the same parameters.
2016 template<typename _IntType
>
2018 operator==(const std::uniform_real_distribution
<_IntType
>& __d1
,
2019 const std::uniform_real_distribution
<_IntType
>& __d2
)
2020 { return __d1
.param() == __d2
.param(); }
2023 * @brief Return true if two uniform real distributions have
2024 * different parameters.
2026 template<typename _IntType
>
2028 operator!=(const std::uniform_real_distribution
<_IntType
>& __d1
,
2029 const std::uniform_real_distribution
<_IntType
>& __d2
)
2030 { return !(__d1
== __d2
); }
2033 * @brief Inserts a %uniform_real_distribution random number
2034 * distribution @p __x into the output stream @p __os.
2036 * @param __os An output stream.
2037 * @param __x A %uniform_real_distribution random number distribution.
2039 * @returns The output stream with the state of @p __x inserted or in
2042 template<typename _RealType
, typename _CharT
, typename _Traits
>
2043 std::basic_ostream
<_CharT
, _Traits
>&
2044 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2045 const std::uniform_real_distribution
<_RealType
>&);
2048 * @brief Extracts a %uniform_real_distribution random number distribution
2049 * @p __x from the input stream @p __is.
2051 * @param __is An input stream.
2052 * @param __x A %uniform_real_distribution random number generator engine.
2054 * @returns The input stream with @p __x extracted or in an error state.
2056 template<typename _RealType
, typename _CharT
, typename _Traits
>
2057 std::basic_istream
<_CharT
, _Traits
>&
2058 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2059 std::uniform_real_distribution
<_RealType
>&);
2061 /* @} */ // group random_distributions_uniform
2064 * @addtogroup random_distributions_normal Normal Distributions
2065 * @ingroup random_distributions
2070 * @brief A normal continuous distribution for random numbers.
2072 * The formula for the normal probability density function is
2074 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
2075 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
2078 template<typename _RealType
= double>
2079 class normal_distribution
2081 static_assert(std::is_floating_point
<_RealType
>::value
,
2082 "template argument not a floating point type");
2085 /** The type of the range of the distribution. */
2086 typedef _RealType result_type
;
2087 /** Parameter type. */
2090 typedef normal_distribution
<_RealType
> distribution_type
;
2093 param_type(_RealType __mean
= _RealType(0),
2094 _RealType __stddev
= _RealType(1))
2095 : _M_mean(__mean
), _M_stddev(__stddev
)
2097 _GLIBCXX_DEBUG_ASSERT(_M_stddev
> _RealType(0));
2106 { return _M_stddev
; }
2109 operator==(const param_type
& __p1
, const param_type
& __p2
)
2110 { return (__p1
._M_mean
== __p2
._M_mean
2111 && __p1
._M_stddev
== __p2
._M_stddev
); }
2115 _RealType _M_stddev
;
2120 * Constructs a normal distribution with parameters @f$mean@f$ and
2121 * standard deviation.
2124 normal_distribution(result_type __mean
= result_type(0),
2125 result_type __stddev
= result_type(1))
2126 : _M_param(__mean
, __stddev
), _M_saved_available(false)
2130 normal_distribution(const param_type
& __p
)
2131 : _M_param(__p
), _M_saved_available(false)
2135 * @brief Resets the distribution state.
2139 { _M_saved_available
= false; }
2142 * @brief Returns the mean of the distribution.
2146 { return _M_param
.mean(); }
2149 * @brief Returns the standard deviation of the distribution.
2153 { return _M_param
.stddev(); }
2156 * @brief Returns the parameter set of the distribution.
2160 { return _M_param
; }
2163 * @brief Sets the parameter set of the distribution.
2164 * @param __param The new parameter set of the distribution.
2167 param(const param_type
& __param
)
2168 { _M_param
= __param
; }
2171 * @brief Returns the greatest lower bound value of the distribution.
2175 { return std::numeric_limits
<result_type
>::min(); }
2178 * @brief Returns the least upper bound value of the distribution.
2182 { return std::numeric_limits
<result_type
>::max(); }
2185 * @brief Generating functions.
2187 template<typename _UniformRandomNumberGenerator
>
2189 operator()(_UniformRandomNumberGenerator
& __urng
)
2190 { return this->operator()(__urng
, this->param()); }
2192 template<typename _UniformRandomNumberGenerator
>
2194 operator()(_UniformRandomNumberGenerator
& __urng
,
2195 const param_type
& __p
);
2197 template<typename _ForwardIterator
,
2198 typename _UniformRandomNumberGenerator
>
2200 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2201 _UniformRandomNumberGenerator
& __urng
)
2202 { this->__generate(__f
, __t
, __urng
, this->param()); }
2204 template<typename _ForwardIterator
,
2205 typename _UniformRandomNumberGenerator
>
2207 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2208 _UniformRandomNumberGenerator
& __urng
,
2209 const param_type
& __p
)
2210 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2212 template<typename _UniformRandomNumberGenerator
>
2214 __generate(result_type
* __f
, result_type
* __t
,
2215 _UniformRandomNumberGenerator
& __urng
,
2216 const param_type
& __p
)
2217 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2220 * @brief Return true if two normal distributions have
2221 * the same parameters and the sequences that would
2222 * be generated are equal.
2224 template<typename _RealType1
>
2226 operator==(const std::normal_distribution
<_RealType1
>& __d1
,
2227 const std::normal_distribution
<_RealType1
>& __d2
);
2230 * @brief Inserts a %normal_distribution random number distribution
2231 * @p __x into the output stream @p __os.
2233 * @param __os An output stream.
2234 * @param __x A %normal_distribution random number distribution.
2236 * @returns The output stream with the state of @p __x inserted or in
2239 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2240 friend std::basic_ostream
<_CharT
, _Traits
>&
2241 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2242 const std::normal_distribution
<_RealType1
>& __x
);
2245 * @brief Extracts a %normal_distribution random number distribution
2246 * @p __x from the input stream @p __is.
2248 * @param __is An input stream.
2249 * @param __x A %normal_distribution random number generator engine.
2251 * @returns The input stream with @p __x extracted or in an error
2254 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2255 friend std::basic_istream
<_CharT
, _Traits
>&
2256 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2257 std::normal_distribution
<_RealType1
>& __x
);
2260 template<typename _ForwardIterator
,
2261 typename _UniformRandomNumberGenerator
>
2263 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2264 _UniformRandomNumberGenerator
& __urng
,
2265 const param_type
& __p
);
2267 param_type _M_param
;
2268 result_type _M_saved
;
2269 bool _M_saved_available
;
2273 * @brief Return true if two normal distributions are different.
2275 template<typename _RealType
>
2277 operator!=(const std::normal_distribution
<_RealType
>& __d1
,
2278 const std::normal_distribution
<_RealType
>& __d2
)
2279 { return !(__d1
== __d2
); }
2283 * @brief A lognormal_distribution random number distribution.
2285 * The formula for the normal probability mass function is
2287 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2288 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2291 template<typename _RealType
= double>
2292 class lognormal_distribution
2294 static_assert(std::is_floating_point
<_RealType
>::value
,
2295 "template argument not a floating point type");
2298 /** The type of the range of the distribution. */
2299 typedef _RealType result_type
;
2300 /** Parameter type. */
2303 typedef lognormal_distribution
<_RealType
> distribution_type
;
2306 param_type(_RealType __m
= _RealType(0),
2307 _RealType __s
= _RealType(1))
2308 : _M_m(__m
), _M_s(__s
)
2320 operator==(const param_type
& __p1
, const param_type
& __p2
)
2321 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_s
== __p2
._M_s
; }
2329 lognormal_distribution(_RealType __m
= _RealType(0),
2330 _RealType __s
= _RealType(1))
2331 : _M_param(__m
, __s
), _M_nd()
2335 lognormal_distribution(const param_type
& __p
)
2336 : _M_param(__p
), _M_nd()
2340 * Resets the distribution state.
2351 { return _M_param
.m(); }
2355 { return _M_param
.s(); }
2358 * @brief Returns the parameter set of the distribution.
2362 { return _M_param
; }
2365 * @brief Sets the parameter set of the distribution.
2366 * @param __param The new parameter set of the distribution.
2369 param(const param_type
& __param
)
2370 { _M_param
= __param
; }
2373 * @brief Returns the greatest lower bound value of the distribution.
2377 { return result_type(0); }
2380 * @brief Returns the least upper bound value of the distribution.
2384 { return std::numeric_limits
<result_type
>::max(); }
2387 * @brief Generating functions.
2389 template<typename _UniformRandomNumberGenerator
>
2391 operator()(_UniformRandomNumberGenerator
& __urng
)
2392 { return this->operator()(__urng
, this->param()); }
2394 template<typename _UniformRandomNumberGenerator
>
2396 operator()(_UniformRandomNumberGenerator
& __urng
,
2397 const param_type
& __p
)
2398 { return std::exp(__p
.s() * _M_nd(__urng
) + __p
.m()); }
2400 template<typename _ForwardIterator
,
2401 typename _UniformRandomNumberGenerator
>
2403 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2404 _UniformRandomNumberGenerator
& __urng
)
2405 { this->__generate(__f
, __t
, __urng
, this->param()); }
2407 template<typename _ForwardIterator
,
2408 typename _UniformRandomNumberGenerator
>
2410 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2411 _UniformRandomNumberGenerator
& __urng
,
2412 const param_type
& __p
)
2413 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2415 template<typename _UniformRandomNumberGenerator
>
2417 __generate(result_type
* __f
, result_type
* __t
,
2418 _UniformRandomNumberGenerator
& __urng
,
2419 const param_type
& __p
)
2420 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2423 * @brief Return true if two lognormal distributions have
2424 * the same parameters and the sequences that would
2425 * be generated are equal.
2428 operator==(const lognormal_distribution
& __d1
,
2429 const lognormal_distribution
& __d2
)
2430 { return (__d1
.param() == __d2
.param()
2431 && __d1
._M_nd
== __d2
._M_nd
); }
2434 * @brief Inserts a %lognormal_distribution random number distribution
2435 * @p __x into the output stream @p __os.
2437 * @param __os An output stream.
2438 * @param __x A %lognormal_distribution random number distribution.
2440 * @returns The output stream with the state of @p __x inserted or in
2443 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2444 friend std::basic_ostream
<_CharT
, _Traits
>&
2445 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2446 const std::lognormal_distribution
<_RealType1
>& __x
);
2449 * @brief Extracts a %lognormal_distribution random number distribution
2450 * @p __x from the input stream @p __is.
2452 * @param __is An input stream.
2453 * @param __x A %lognormal_distribution random number
2456 * @returns The input stream with @p __x extracted or in an error state.
2458 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2459 friend std::basic_istream
<_CharT
, _Traits
>&
2460 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2461 std::lognormal_distribution
<_RealType1
>& __x
);
2464 template<typename _ForwardIterator
,
2465 typename _UniformRandomNumberGenerator
>
2467 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2468 _UniformRandomNumberGenerator
& __urng
,
2469 const param_type
& __p
);
2471 param_type _M_param
;
2473 std::normal_distribution
<result_type
> _M_nd
;
2477 * @brief Return true if two lognormal distributions are different.
2479 template<typename _RealType
>
2481 operator!=(const std::lognormal_distribution
<_RealType
>& __d1
,
2482 const std::lognormal_distribution
<_RealType
>& __d2
)
2483 { return !(__d1
== __d2
); }
2487 * @brief A gamma continuous distribution for random numbers.
2489 * The formula for the gamma probability density function is:
2491 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2492 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2495 template<typename _RealType
= double>
2496 class gamma_distribution
2498 static_assert(std::is_floating_point
<_RealType
>::value
,
2499 "template argument not a floating point type");
2502 /** The type of the range of the distribution. */
2503 typedef _RealType result_type
;
2504 /** Parameter type. */
2507 typedef gamma_distribution
<_RealType
> distribution_type
;
2508 friend class gamma_distribution
<_RealType
>;
2511 param_type(_RealType __alpha_val
= _RealType(1),
2512 _RealType __beta_val
= _RealType(1))
2513 : _M_alpha(__alpha_val
), _M_beta(__beta_val
)
2515 _GLIBCXX_DEBUG_ASSERT(_M_alpha
> _RealType(0));
2521 { return _M_alpha
; }
2528 operator==(const param_type
& __p1
, const param_type
& __p2
)
2529 { return (__p1
._M_alpha
== __p2
._M_alpha
2530 && __p1
._M_beta
== __p2
._M_beta
); }
2539 _RealType _M_malpha
, _M_a2
;
2544 * @brief Constructs a gamma distribution with parameters
2545 * @f$\alpha@f$ and @f$\beta@f$.
2548 gamma_distribution(_RealType __alpha_val
= _RealType(1),
2549 _RealType __beta_val
= _RealType(1))
2550 : _M_param(__alpha_val
, __beta_val
), _M_nd()
2554 gamma_distribution(const param_type
& __p
)
2555 : _M_param(__p
), _M_nd()
2559 * @brief Resets the distribution state.
2566 * @brief Returns the @f$\alpha@f$ of the distribution.
2570 { return _M_param
.alpha(); }
2573 * @brief Returns the @f$\beta@f$ of the distribution.
2577 { return _M_param
.beta(); }
2580 * @brief Returns the parameter set of the distribution.
2584 { return _M_param
; }
2587 * @brief Sets the parameter set of the distribution.
2588 * @param __param The new parameter set of the distribution.
2591 param(const param_type
& __param
)
2592 { _M_param
= __param
; }
2595 * @brief Returns the greatest lower bound value of the distribution.
2599 { return result_type(0); }
2602 * @brief Returns the least upper bound value of the distribution.
2606 { return std::numeric_limits
<result_type
>::max(); }
2609 * @brief Generating functions.
2611 template<typename _UniformRandomNumberGenerator
>
2613 operator()(_UniformRandomNumberGenerator
& __urng
)
2614 { return this->operator()(__urng
, this->param()); }
2616 template<typename _UniformRandomNumberGenerator
>
2618 operator()(_UniformRandomNumberGenerator
& __urng
,
2619 const param_type
& __p
);
2621 template<typename _ForwardIterator
,
2622 typename _UniformRandomNumberGenerator
>
2624 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2625 _UniformRandomNumberGenerator
& __urng
)
2626 { this->__generate(__f
, __t
, __urng
, this->param()); }
2628 template<typename _ForwardIterator
,
2629 typename _UniformRandomNumberGenerator
>
2631 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2632 _UniformRandomNumberGenerator
& __urng
,
2633 const param_type
& __p
)
2634 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2636 template<typename _UniformRandomNumberGenerator
>
2638 __generate(result_type
* __f
, result_type
* __t
,
2639 _UniformRandomNumberGenerator
& __urng
,
2640 const param_type
& __p
)
2641 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2644 * @brief Return true if two gamma distributions have the same
2645 * parameters and the sequences that would be generated
2649 operator==(const gamma_distribution
& __d1
,
2650 const gamma_distribution
& __d2
)
2651 { return (__d1
.param() == __d2
.param()
2652 && __d1
._M_nd
== __d2
._M_nd
); }
2655 * @brief Inserts a %gamma_distribution random number distribution
2656 * @p __x into the output stream @p __os.
2658 * @param __os An output stream.
2659 * @param __x A %gamma_distribution random number distribution.
2661 * @returns The output stream with the state of @p __x inserted or in
2664 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2665 friend std::basic_ostream
<_CharT
, _Traits
>&
2666 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2667 const std::gamma_distribution
<_RealType1
>& __x
);
2670 * @brief Extracts a %gamma_distribution random number distribution
2671 * @p __x from the input stream @p __is.
2673 * @param __is An input stream.
2674 * @param __x A %gamma_distribution random number generator engine.
2676 * @returns The input stream with @p __x extracted or in an error state.
2678 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2679 friend std::basic_istream
<_CharT
, _Traits
>&
2680 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2681 std::gamma_distribution
<_RealType1
>& __x
);
2684 template<typename _ForwardIterator
,
2685 typename _UniformRandomNumberGenerator
>
2687 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2688 _UniformRandomNumberGenerator
& __urng
,
2689 const param_type
& __p
);
2691 param_type _M_param
;
2693 std::normal_distribution
<result_type
> _M_nd
;
2697 * @brief Return true if two gamma distributions are different.
2699 template<typename _RealType
>
2701 operator!=(const std::gamma_distribution
<_RealType
>& __d1
,
2702 const std::gamma_distribution
<_RealType
>& __d2
)
2703 { return !(__d1
== __d2
); }
2707 * @brief A chi_squared_distribution random number distribution.
2709 * The formula for the normal probability mass function is
2710 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2712 template<typename _RealType
= double>
2713 class chi_squared_distribution
2715 static_assert(std::is_floating_point
<_RealType
>::value
,
2716 "template argument not a floating point type");
2719 /** The type of the range of the distribution. */
2720 typedef _RealType result_type
;
2721 /** Parameter type. */
2724 typedef chi_squared_distribution
<_RealType
> distribution_type
;
2727 param_type(_RealType __n
= _RealType(1))
2736 operator==(const param_type
& __p1
, const param_type
& __p2
)
2737 { return __p1
._M_n
== __p2
._M_n
; }
2744 chi_squared_distribution(_RealType __n
= _RealType(1))
2745 : _M_param(__n
), _M_gd(__n
/ 2)
2749 chi_squared_distribution(const param_type
& __p
)
2750 : _M_param(__p
), _M_gd(__p
.n() / 2)
2754 * @brief Resets the distribution state.
2765 { return _M_param
.n(); }
2768 * @brief Returns the parameter set of the distribution.
2772 { return _M_param
; }
2775 * @brief Sets the parameter set of the distribution.
2776 * @param __param The new parameter set of the distribution.
2779 param(const param_type
& __param
)
2780 { _M_param
= __param
; }
2783 * @brief Returns the greatest lower bound value of the distribution.
2787 { return result_type(0); }
2790 * @brief Returns the least upper bound value of the distribution.
2794 { return std::numeric_limits
<result_type
>::max(); }
2797 * @brief Generating functions.
2799 template<typename _UniformRandomNumberGenerator
>
2801 operator()(_UniformRandomNumberGenerator
& __urng
)
2802 { return 2 * _M_gd(__urng
); }
2804 template<typename _UniformRandomNumberGenerator
>
2806 operator()(_UniformRandomNumberGenerator
& __urng
,
2807 const param_type
& __p
)
2809 typedef typename
std::gamma_distribution
<result_type
>::param_type
2811 return 2 * _M_gd(__urng
, param_type(__p
.n() / 2));
2814 template<typename _ForwardIterator
,
2815 typename _UniformRandomNumberGenerator
>
2817 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2818 _UniformRandomNumberGenerator
& __urng
)
2819 { this->__generate_impl(__f
, __t
, __urng
, _M_gd
.param()); }
2821 template<typename _ForwardIterator
,
2822 typename _UniformRandomNumberGenerator
>
2824 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2825 _UniformRandomNumberGenerator
& __urng
,
2826 const param_type
& __p
)
2827 { typename
std::gamma_distribution
<result_type
>::param_type
2829 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2831 template<typename _UniformRandomNumberGenerator
>
2833 __generate(result_type
* __f
, result_type
* __t
,
2834 _UniformRandomNumberGenerator
& __urng
)
2835 { typename
std::gamma_distribution
<result_type
>::param_type
2836 __p2(_M_gd
.param());
2837 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2839 template<typename _UniformRandomNumberGenerator
>
2841 __generate(result_type
* __f
, result_type
* __t
,
2842 _UniformRandomNumberGenerator
& __urng
,
2843 const param_type
& __p
)
2844 { typename
std::gamma_distribution
<result_type
>::param_type
2846 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2849 * @brief Return true if two Chi-squared distributions have
2850 * the same parameters and the sequences that would be
2851 * generated are equal.
2854 operator==(const chi_squared_distribution
& __d1
,
2855 const chi_squared_distribution
& __d2
)
2856 { return __d1
.param() == __d2
.param() && __d1
._M_gd
== __d2
._M_gd
; }
2859 * @brief Inserts a %chi_squared_distribution random number distribution
2860 * @p __x into the output stream @p __os.
2862 * @param __os An output stream.
2863 * @param __x A %chi_squared_distribution random number distribution.
2865 * @returns The output stream with the state of @p __x inserted or in
2868 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2869 friend std::basic_ostream
<_CharT
, _Traits
>&
2870 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2871 const std::chi_squared_distribution
<_RealType1
>& __x
);
2874 * @brief Extracts a %chi_squared_distribution random number distribution
2875 * @p __x from the input stream @p __is.
2877 * @param __is An input stream.
2878 * @param __x A %chi_squared_distribution random number
2881 * @returns The input stream with @p __x extracted or in an error state.
2883 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2884 friend std::basic_istream
<_CharT
, _Traits
>&
2885 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2886 std::chi_squared_distribution
<_RealType1
>& __x
);
2889 template<typename _ForwardIterator
,
2890 typename _UniformRandomNumberGenerator
>
2892 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2893 _UniformRandomNumberGenerator
& __urng
,
2894 typename
std::gamma_distribution
<result_type
>::param_type
&
2897 param_type _M_param
;
2899 std::gamma_distribution
<result_type
> _M_gd
;
2903 * @brief Return true if two Chi-squared distributions are different.
2905 template<typename _RealType
>
2907 operator!=(const std::chi_squared_distribution
<_RealType
>& __d1
,
2908 const std::chi_squared_distribution
<_RealType
>& __d2
)
2909 { return !(__d1
== __d2
); }
2913 * @brief A cauchy_distribution random number distribution.
2915 * The formula for the normal probability mass function is
2916 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2918 template<typename _RealType
= double>
2919 class cauchy_distribution
2921 static_assert(std::is_floating_point
<_RealType
>::value
,
2922 "template argument not a floating point type");
2925 /** The type of the range of the distribution. */
2926 typedef _RealType result_type
;
2927 /** Parameter type. */
2930 typedef cauchy_distribution
<_RealType
> distribution_type
;
2933 param_type(_RealType __a
= _RealType(0),
2934 _RealType __b
= _RealType(1))
2935 : _M_a(__a
), _M_b(__b
)
2947 operator==(const param_type
& __p1
, const param_type
& __p2
)
2948 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
2956 cauchy_distribution(_RealType __a
= _RealType(0),
2957 _RealType __b
= _RealType(1))
2958 : _M_param(__a
, __b
)
2962 cauchy_distribution(const param_type
& __p
)
2967 * @brief Resets the distribution state.
2978 { return _M_param
.a(); }
2982 { return _M_param
.b(); }
2985 * @brief Returns the parameter set of the distribution.
2989 { return _M_param
; }
2992 * @brief Sets the parameter set of the distribution.
2993 * @param __param The new parameter set of the distribution.
2996 param(const param_type
& __param
)
2997 { _M_param
= __param
; }
3000 * @brief Returns the greatest lower bound value of the distribution.
3004 { return std::numeric_limits
<result_type
>::min(); }
3007 * @brief Returns the least upper bound value of the distribution.
3011 { return std::numeric_limits
<result_type
>::max(); }
3014 * @brief Generating functions.
3016 template<typename _UniformRandomNumberGenerator
>
3018 operator()(_UniformRandomNumberGenerator
& __urng
)
3019 { return this->operator()(__urng
, this->param()); }
3021 template<typename _UniformRandomNumberGenerator
>
3023 operator()(_UniformRandomNumberGenerator
& __urng
,
3024 const param_type
& __p
);
3026 template<typename _ForwardIterator
,
3027 typename _UniformRandomNumberGenerator
>
3029 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3030 _UniformRandomNumberGenerator
& __urng
)
3031 { this->__generate(__f
, __t
, __urng
, this->param()); }
3033 template<typename _ForwardIterator
,
3034 typename _UniformRandomNumberGenerator
>
3036 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3037 _UniformRandomNumberGenerator
& __urng
,
3038 const param_type
& __p
)
3039 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3041 template<typename _UniformRandomNumberGenerator
>
3043 __generate(result_type
* __f
, result_type
* __t
,
3044 _UniformRandomNumberGenerator
& __urng
,
3045 const param_type
& __p
)
3046 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3049 template<typename _ForwardIterator
,
3050 typename _UniformRandomNumberGenerator
>
3052 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3053 _UniformRandomNumberGenerator
& __urng
,
3054 const param_type
& __p
);
3056 param_type _M_param
;
3060 * @brief Return true if two Cauchy distributions have
3061 * the same parameters.
3063 template<typename _RealType
>
3065 operator==(const std::cauchy_distribution
<_RealType
>& __d1
,
3066 const std::cauchy_distribution
<_RealType
>& __d2
)
3067 { return __d1
.param() == __d2
.param(); }
3070 * @brief Return true if two Cauchy distributions have
3071 * different parameters.
3073 template<typename _RealType
>
3075 operator!=(const std::cauchy_distribution
<_RealType
>& __d1
,
3076 const std::cauchy_distribution
<_RealType
>& __d2
)
3077 { return !(__d1
== __d2
); }
3080 * @brief Inserts a %cauchy_distribution random number distribution
3081 * @p __x into the output stream @p __os.
3083 * @param __os An output stream.
3084 * @param __x A %cauchy_distribution random number distribution.
3086 * @returns The output stream with the state of @p __x inserted or in
3089 template<typename _RealType
, typename _CharT
, typename _Traits
>
3090 std::basic_ostream
<_CharT
, _Traits
>&
3091 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3092 const std::cauchy_distribution
<_RealType
>& __x
);
3095 * @brief Extracts a %cauchy_distribution random number distribution
3096 * @p __x from the input stream @p __is.
3098 * @param __is An input stream.
3099 * @param __x A %cauchy_distribution random number
3102 * @returns The input stream with @p __x extracted or in an error state.
3104 template<typename _RealType
, typename _CharT
, typename _Traits
>
3105 std::basic_istream
<_CharT
, _Traits
>&
3106 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3107 std::cauchy_distribution
<_RealType
>& __x
);
3111 * @brief A fisher_f_distribution random number distribution.
3113 * The formula for the normal probability mass function is
3115 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3116 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3117 * (1 + \frac{mx}{n})^{-(m+n)/2}
3120 template<typename _RealType
= double>
3121 class fisher_f_distribution
3123 static_assert(std::is_floating_point
<_RealType
>::value
,
3124 "template argument not a floating point type");
3127 /** The type of the range of the distribution. */
3128 typedef _RealType result_type
;
3129 /** Parameter type. */
3132 typedef fisher_f_distribution
<_RealType
> distribution_type
;
3135 param_type(_RealType __m
= _RealType(1),
3136 _RealType __n
= _RealType(1))
3137 : _M_m(__m
), _M_n(__n
)
3149 operator==(const param_type
& __p1
, const param_type
& __p2
)
3150 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_n
== __p2
._M_n
; }
3158 fisher_f_distribution(_RealType __m
= _RealType(1),
3159 _RealType __n
= _RealType(1))
3160 : _M_param(__m
, __n
), _M_gd_x(__m
/ 2), _M_gd_y(__n
/ 2)
3164 fisher_f_distribution(const param_type
& __p
)
3165 : _M_param(__p
), _M_gd_x(__p
.m() / 2), _M_gd_y(__p
.n() / 2)
3169 * @brief Resets the distribution state.
3183 { return _M_param
.m(); }
3187 { return _M_param
.n(); }
3190 * @brief Returns the parameter set of the distribution.
3194 { return _M_param
; }
3197 * @brief Sets the parameter set of the distribution.
3198 * @param __param The new parameter set of the distribution.
3201 param(const param_type
& __param
)
3202 { _M_param
= __param
; }
3205 * @brief Returns the greatest lower bound value of the distribution.
3209 { return result_type(0); }
3212 * @brief Returns the least upper bound value of the distribution.
3216 { return std::numeric_limits
<result_type
>::max(); }
3219 * @brief Generating functions.
3221 template<typename _UniformRandomNumberGenerator
>
3223 operator()(_UniformRandomNumberGenerator
& __urng
)
3224 { return (_M_gd_x(__urng
) * n()) / (_M_gd_y(__urng
) * m()); }
3226 template<typename _UniformRandomNumberGenerator
>
3228 operator()(_UniformRandomNumberGenerator
& __urng
,
3229 const param_type
& __p
)
3231 typedef typename
std::gamma_distribution
<result_type
>::param_type
3233 return ((_M_gd_x(__urng
, param_type(__p
.m() / 2)) * n())
3234 / (_M_gd_y(__urng
, param_type(__p
.n() / 2)) * m()));
3237 template<typename _ForwardIterator
,
3238 typename _UniformRandomNumberGenerator
>
3240 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3241 _UniformRandomNumberGenerator
& __urng
)
3242 { this->__generate_impl(__f
, __t
, __urng
); }
3244 template<typename _ForwardIterator
,
3245 typename _UniformRandomNumberGenerator
>
3247 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3248 _UniformRandomNumberGenerator
& __urng
,
3249 const param_type
& __p
)
3250 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3252 template<typename _UniformRandomNumberGenerator
>
3254 __generate(result_type
* __f
, result_type
* __t
,
3255 _UniformRandomNumberGenerator
& __urng
)
3256 { this->__generate_impl(__f
, __t
, __urng
); }
3258 template<typename _UniformRandomNumberGenerator
>
3260 __generate(result_type
* __f
, result_type
* __t
,
3261 _UniformRandomNumberGenerator
& __urng
,
3262 const param_type
& __p
)
3263 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3266 * @brief Return true if two Fisher f distributions have
3267 * the same parameters and the sequences that would
3268 * be generated are equal.
3271 operator==(const fisher_f_distribution
& __d1
,
3272 const fisher_f_distribution
& __d2
)
3273 { return (__d1
.param() == __d2
.param()
3274 && __d1
._M_gd_x
== __d2
._M_gd_x
3275 && __d1
._M_gd_y
== __d2
._M_gd_y
); }
3278 * @brief Inserts a %fisher_f_distribution random number distribution
3279 * @p __x into the output stream @p __os.
3281 * @param __os An output stream.
3282 * @param __x A %fisher_f_distribution random number distribution.
3284 * @returns The output stream with the state of @p __x inserted or in
3287 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3288 friend std::basic_ostream
<_CharT
, _Traits
>&
3289 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3290 const std::fisher_f_distribution
<_RealType1
>& __x
);
3293 * @brief Extracts a %fisher_f_distribution random number distribution
3294 * @p __x from the input stream @p __is.
3296 * @param __is An input stream.
3297 * @param __x A %fisher_f_distribution random number
3300 * @returns The input stream with @p __x extracted or in an error state.
3302 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3303 friend std::basic_istream
<_CharT
, _Traits
>&
3304 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3305 std::fisher_f_distribution
<_RealType1
>& __x
);
3308 template<typename _ForwardIterator
,
3309 typename _UniformRandomNumberGenerator
>
3311 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3312 _UniformRandomNumberGenerator
& __urng
);
3314 template<typename _ForwardIterator
,
3315 typename _UniformRandomNumberGenerator
>
3317 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3318 _UniformRandomNumberGenerator
& __urng
,
3319 const param_type
& __p
);
3321 param_type _M_param
;
3323 std::gamma_distribution
<result_type
> _M_gd_x
, _M_gd_y
;
3327 * @brief Return true if two Fisher f distributions are diferent.
3329 template<typename _RealType
>
3331 operator!=(const std::fisher_f_distribution
<_RealType
>& __d1
,
3332 const std::fisher_f_distribution
<_RealType
>& __d2
)
3333 { return !(__d1
== __d2
); }
3336 * @brief A student_t_distribution random number distribution.
3338 * The formula for the normal probability mass function is:
3340 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3341 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3344 template<typename _RealType
= double>
3345 class student_t_distribution
3347 static_assert(std::is_floating_point
<_RealType
>::value
,
3348 "template argument not a floating point type");
3351 /** The type of the range of the distribution. */
3352 typedef _RealType result_type
;
3353 /** Parameter type. */
3356 typedef student_t_distribution
<_RealType
> distribution_type
;
3359 param_type(_RealType __n
= _RealType(1))
3368 operator==(const param_type
& __p1
, const param_type
& __p2
)
3369 { return __p1
._M_n
== __p2
._M_n
; }
3376 student_t_distribution(_RealType __n
= _RealType(1))
3377 : _M_param(__n
), _M_nd(), _M_gd(__n
/ 2, 2)
3381 student_t_distribution(const param_type
& __p
)
3382 : _M_param(__p
), _M_nd(), _M_gd(__p
.n() / 2, 2)
3386 * @brief Resets the distribution state.
3400 { return _M_param
.n(); }
3403 * @brief Returns the parameter set of the distribution.
3407 { return _M_param
; }
3410 * @brief Sets the parameter set of the distribution.
3411 * @param __param The new parameter set of the distribution.
3414 param(const param_type
& __param
)
3415 { _M_param
= __param
; }
3418 * @brief Returns the greatest lower bound value of the distribution.
3422 { return std::numeric_limits
<result_type
>::min(); }
3425 * @brief Returns the least upper bound value of the distribution.
3429 { return std::numeric_limits
<result_type
>::max(); }
3432 * @brief Generating functions.
3434 template<typename _UniformRandomNumberGenerator
>
3436 operator()(_UniformRandomNumberGenerator
& __urng
)
3437 { return _M_nd(__urng
) * std::sqrt(n() / _M_gd(__urng
)); }
3439 template<typename _UniformRandomNumberGenerator
>
3441 operator()(_UniformRandomNumberGenerator
& __urng
,
3442 const param_type
& __p
)
3444 typedef typename
std::gamma_distribution
<result_type
>::param_type
3447 const result_type __g
= _M_gd(__urng
, param_type(__p
.n() / 2, 2));
3448 return _M_nd(__urng
) * std::sqrt(__p
.n() / __g
);
3451 template<typename _ForwardIterator
,
3452 typename _UniformRandomNumberGenerator
>
3454 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3455 _UniformRandomNumberGenerator
& __urng
)
3456 { this->__generate_impl(__f
, __t
, __urng
); }
3458 template<typename _ForwardIterator
,
3459 typename _UniformRandomNumberGenerator
>
3461 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3462 _UniformRandomNumberGenerator
& __urng
,
3463 const param_type
& __p
)
3464 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3466 template<typename _UniformRandomNumberGenerator
>
3468 __generate(result_type
* __f
, result_type
* __t
,
3469 _UniformRandomNumberGenerator
& __urng
)
3470 { this->__generate_impl(__f
, __t
, __urng
); }
3472 template<typename _UniformRandomNumberGenerator
>
3474 __generate(result_type
* __f
, result_type
* __t
,
3475 _UniformRandomNumberGenerator
& __urng
,
3476 const param_type
& __p
)
3477 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3480 * @brief Return true if two Student t distributions have
3481 * the same parameters and the sequences that would
3482 * be generated are equal.
3485 operator==(const student_t_distribution
& __d1
,
3486 const student_t_distribution
& __d2
)
3487 { return (__d1
.param() == __d2
.param()
3488 && __d1
._M_nd
== __d2
._M_nd
&& __d1
._M_gd
== __d2
._M_gd
); }
3491 * @brief Inserts a %student_t_distribution random number distribution
3492 * @p __x into the output stream @p __os.
3494 * @param __os An output stream.
3495 * @param __x A %student_t_distribution random number distribution.
3497 * @returns The output stream with the state of @p __x inserted or in
3500 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3501 friend std::basic_ostream
<_CharT
, _Traits
>&
3502 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3503 const std::student_t_distribution
<_RealType1
>& __x
);
3506 * @brief Extracts a %student_t_distribution random number distribution
3507 * @p __x from the input stream @p __is.
3509 * @param __is An input stream.
3510 * @param __x A %student_t_distribution random number
3513 * @returns The input stream with @p __x extracted or in an error state.
3515 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3516 friend std::basic_istream
<_CharT
, _Traits
>&
3517 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3518 std::student_t_distribution
<_RealType1
>& __x
);
3521 template<typename _ForwardIterator
,
3522 typename _UniformRandomNumberGenerator
>
3524 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3525 _UniformRandomNumberGenerator
& __urng
);
3526 template<typename _ForwardIterator
,
3527 typename _UniformRandomNumberGenerator
>
3529 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3530 _UniformRandomNumberGenerator
& __urng
,
3531 const param_type
& __p
);
3533 param_type _M_param
;
3535 std::normal_distribution
<result_type
> _M_nd
;
3536 std::gamma_distribution
<result_type
> _M_gd
;
3540 * @brief Return true if two Student t distributions are different.
3542 template<typename _RealType
>
3544 operator!=(const std::student_t_distribution
<_RealType
>& __d1
,
3545 const std::student_t_distribution
<_RealType
>& __d2
)
3546 { return !(__d1
== __d2
); }
3549 /* @} */ // group random_distributions_normal
3552 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3553 * @ingroup random_distributions
3558 * @brief A Bernoulli random number distribution.
3560 * Generates a sequence of true and false values with likelihood @f$p@f$
3561 * that true will come up and @f$(1 - p)@f$ that false will appear.
3563 class bernoulli_distribution
3566 /** The type of the range of the distribution. */
3567 typedef bool result_type
;
3568 /** Parameter type. */
3571 typedef bernoulli_distribution distribution_type
;
3574 param_type(double __p
= 0.5)
3577 _GLIBCXX_DEBUG_ASSERT((_M_p
>= 0.0) && (_M_p
<= 1.0));
3585 operator==(const param_type
& __p1
, const param_type
& __p2
)
3586 { return __p1
._M_p
== __p2
._M_p
; }
3594 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3596 * @param __p [IN] The likelihood of a true result being returned.
3597 * Must be in the interval @f$[0, 1]@f$.
3600 bernoulli_distribution(double __p
= 0.5)
3605 bernoulli_distribution(const param_type
& __p
)
3610 * @brief Resets the distribution state.
3612 * Does nothing for a Bernoulli distribution.
3618 * @brief Returns the @p p parameter of the distribution.
3622 { return _M_param
.p(); }
3625 * @brief Returns the parameter set of the distribution.
3629 { return _M_param
; }
3632 * @brief Sets the parameter set of the distribution.
3633 * @param __param The new parameter set of the distribution.
3636 param(const param_type
& __param
)
3637 { _M_param
= __param
; }
3640 * @brief Returns the greatest lower bound value of the distribution.
3644 { return std::numeric_limits
<result_type
>::min(); }
3647 * @brief Returns the least upper bound value of the distribution.
3651 { return std::numeric_limits
<result_type
>::max(); }
3654 * @brief Generating functions.
3656 template<typename _UniformRandomNumberGenerator
>
3658 operator()(_UniformRandomNumberGenerator
& __urng
)
3659 { return this->operator()(__urng
, this->param()); }
3661 template<typename _UniformRandomNumberGenerator
>
3663 operator()(_UniformRandomNumberGenerator
& __urng
,
3664 const param_type
& __p
)
3666 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
3668 if ((__aurng() - __aurng
.min())
3669 < __p
.p() * (__aurng
.max() - __aurng
.min()))
3674 template<typename _ForwardIterator
,
3675 typename _UniformRandomNumberGenerator
>
3677 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3678 _UniformRandomNumberGenerator
& __urng
)
3679 { this->__generate(__f
, __t
, __urng
, this->param()); }
3681 template<typename _ForwardIterator
,
3682 typename _UniformRandomNumberGenerator
>
3684 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3685 _UniformRandomNumberGenerator
& __urng
, const param_type
& __p
)
3686 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3688 template<typename _UniformRandomNumberGenerator
>
3690 __generate(result_type
* __f
, result_type
* __t
,
3691 _UniformRandomNumberGenerator
& __urng
,
3692 const param_type
& __p
)
3693 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3696 template<typename _ForwardIterator
,
3697 typename _UniformRandomNumberGenerator
>
3699 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3700 _UniformRandomNumberGenerator
& __urng
,
3701 const param_type
& __p
);
3703 param_type _M_param
;
3707 * @brief Return true if two Bernoulli distributions have
3708 * the same parameters.
3711 operator==(const std::bernoulli_distribution
& __d1
,
3712 const std::bernoulli_distribution
& __d2
)
3713 { return __d1
.param() == __d2
.param(); }
3716 * @brief Return true if two Bernoulli distributions have
3717 * different parameters.
3720 operator!=(const std::bernoulli_distribution
& __d1
,
3721 const std::bernoulli_distribution
& __d2
)
3722 { return !(__d1
== __d2
); }
3725 * @brief Inserts a %bernoulli_distribution random number distribution
3726 * @p __x into the output stream @p __os.
3728 * @param __os An output stream.
3729 * @param __x A %bernoulli_distribution random number distribution.
3731 * @returns The output stream with the state of @p __x inserted or in
3734 template<typename _CharT
, typename _Traits
>
3735 std::basic_ostream
<_CharT
, _Traits
>&
3736 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3737 const std::bernoulli_distribution
& __x
);
3740 * @brief Extracts a %bernoulli_distribution random number distribution
3741 * @p __x from the input stream @p __is.
3743 * @param __is An input stream.
3744 * @param __x A %bernoulli_distribution random number generator engine.
3746 * @returns The input stream with @p __x extracted or in an error state.
3748 template<typename _CharT
, typename _Traits
>
3749 std::basic_istream
<_CharT
, _Traits
>&
3750 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3751 std::bernoulli_distribution
& __x
)
3755 __x
.param(bernoulli_distribution::param_type(__p
));
3761 * @brief A discrete binomial random number distribution.
3763 * The formula for the binomial probability density function is
3764 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3765 * and @f$p@f$ are the parameters of the distribution.
3767 template<typename _IntType
= int>
3768 class binomial_distribution
3770 static_assert(std::is_integral
<_IntType
>::value
,
3771 "template argument not an integral type");
3774 /** The type of the range of the distribution. */
3775 typedef _IntType result_type
;
3776 /** Parameter type. */
3779 typedef binomial_distribution
<_IntType
> distribution_type
;
3780 friend class binomial_distribution
<_IntType
>;
3783 param_type(_IntType __t
= _IntType(1), double __p
= 0.5)
3784 : _M_t(__t
), _M_p(__p
)
3786 _GLIBCXX_DEBUG_ASSERT((_M_t
>= _IntType(0))
3801 operator==(const param_type
& __p1
, const param_type
& __p2
)
3802 { return __p1
._M_t
== __p2
._M_t
&& __p1
._M_p
== __p2
._M_p
; }
3812 #if _GLIBCXX_USE_C99_MATH_TR1
3813 double _M_d1
, _M_d2
, _M_s1
, _M_s2
, _M_c
,
3814 _M_a1
, _M_a123
, _M_s
, _M_lf
, _M_lp1p
;
3819 // constructors and member function
3821 binomial_distribution(_IntType __t
= _IntType(1),
3823 : _M_param(__t
, __p
), _M_nd()
3827 binomial_distribution(const param_type
& __p
)
3828 : _M_param(__p
), _M_nd()
3832 * @brief Resets the distribution state.
3839 * @brief Returns the distribution @p t parameter.
3843 { return _M_param
.t(); }
3846 * @brief Returns the distribution @p p parameter.
3850 { return _M_param
.p(); }
3853 * @brief Returns the parameter set of the distribution.
3857 { return _M_param
; }
3860 * @brief Sets the parameter set of the distribution.
3861 * @param __param The new parameter set of the distribution.
3864 param(const param_type
& __param
)
3865 { _M_param
= __param
; }
3868 * @brief Returns the greatest lower bound value of the distribution.
3875 * @brief Returns the least upper bound value of the distribution.
3879 { return _M_param
.t(); }
3882 * @brief Generating functions.
3884 template<typename _UniformRandomNumberGenerator
>
3886 operator()(_UniformRandomNumberGenerator
& __urng
)
3887 { return this->operator()(__urng
, this->param()); }
3889 template<typename _UniformRandomNumberGenerator
>
3891 operator()(_UniformRandomNumberGenerator
& __urng
,
3892 const param_type
& __p
);
3894 template<typename _ForwardIterator
,
3895 typename _UniformRandomNumberGenerator
>
3897 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3898 _UniformRandomNumberGenerator
& __urng
)
3899 { this->__generate(__f
, __t
, __urng
, this->param()); }
3901 template<typename _ForwardIterator
,
3902 typename _UniformRandomNumberGenerator
>
3904 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3905 _UniformRandomNumberGenerator
& __urng
,
3906 const param_type
& __p
)
3907 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3909 template<typename _UniformRandomNumberGenerator
>
3911 __generate(result_type
* __f
, result_type
* __t
,
3912 _UniformRandomNumberGenerator
& __urng
,
3913 const param_type
& __p
)
3914 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3917 * @brief Return true if two binomial distributions have
3918 * the same parameters and the sequences that would
3919 * be generated are equal.
3922 operator==(const binomial_distribution
& __d1
,
3923 const binomial_distribution
& __d2
)
3924 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3925 { return __d1
.param() == __d2
.param() && __d1
._M_nd
== __d2
._M_nd
; }
3927 { return __d1
.param() == __d2
.param(); }
3931 * @brief Inserts a %binomial_distribution random number distribution
3932 * @p __x into the output stream @p __os.
3934 * @param __os An output stream.
3935 * @param __x A %binomial_distribution random number distribution.
3937 * @returns The output stream with the state of @p __x inserted or in
3940 template<typename _IntType1
,
3941 typename _CharT
, typename _Traits
>
3942 friend std::basic_ostream
<_CharT
, _Traits
>&
3943 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3944 const std::binomial_distribution
<_IntType1
>& __x
);
3947 * @brief Extracts a %binomial_distribution random number distribution
3948 * @p __x from the input stream @p __is.
3950 * @param __is An input stream.
3951 * @param __x A %binomial_distribution random number generator engine.
3953 * @returns The input stream with @p __x extracted or in an error
3956 template<typename _IntType1
,
3957 typename _CharT
, typename _Traits
>
3958 friend std::basic_istream
<_CharT
, _Traits
>&
3959 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3960 std::binomial_distribution
<_IntType1
>& __x
);
3963 template<typename _ForwardIterator
,
3964 typename _UniformRandomNumberGenerator
>
3966 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3967 _UniformRandomNumberGenerator
& __urng
,
3968 const param_type
& __p
);
3970 template<typename _UniformRandomNumberGenerator
>
3972 _M_waiting(_UniformRandomNumberGenerator
& __urng
, _IntType __t
);
3974 param_type _M_param
;
3976 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3977 std::normal_distribution
<double> _M_nd
;
3981 * @brief Return true if two binomial distributions are different.
3983 template<typename _IntType
>
3985 operator!=(const std::binomial_distribution
<_IntType
>& __d1
,
3986 const std::binomial_distribution
<_IntType
>& __d2
)
3987 { return !(__d1
== __d2
); }
3991 * @brief A discrete geometric random number distribution.
3993 * The formula for the geometric probability density function is
3994 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3997 template<typename _IntType
= int>
3998 class geometric_distribution
4000 static_assert(std::is_integral
<_IntType
>::value
,
4001 "template argument not an integral type");
4004 /** The type of the range of the distribution. */
4005 typedef _IntType result_type
;
4006 /** Parameter type. */
4009 typedef geometric_distribution
<_IntType
> distribution_type
;
4010 friend class geometric_distribution
<_IntType
>;
4013 param_type(double __p
= 0.5)
4016 _GLIBCXX_DEBUG_ASSERT((_M_p
> 0.0) && (_M_p
< 1.0));
4025 operator==(const param_type
& __p1
, const param_type
& __p2
)
4026 { return __p1
._M_p
== __p2
._M_p
; }
4031 { _M_log_1_p
= std::log(1.0 - _M_p
); }
4038 // constructors and member function
4040 geometric_distribution(double __p
= 0.5)
4045 geometric_distribution(const param_type
& __p
)
4050 * @brief Resets the distribution state.
4052 * Does nothing for the geometric distribution.
4058 * @brief Returns the distribution parameter @p p.
4062 { return _M_param
.p(); }
4065 * @brief Returns the parameter set of the distribution.
4069 { return _M_param
; }
4072 * @brief Sets the parameter set of the distribution.
4073 * @param __param The new parameter set of the distribution.
4076 param(const param_type
& __param
)
4077 { _M_param
= __param
; }
4080 * @brief Returns the greatest lower bound value of the distribution.
4087 * @brief Returns the least upper bound value of the distribution.
4091 { return std::numeric_limits
<result_type
>::max(); }
4094 * @brief Generating functions.
4096 template<typename _UniformRandomNumberGenerator
>
4098 operator()(_UniformRandomNumberGenerator
& __urng
)
4099 { return this->operator()(__urng
, this->param()); }
4101 template<typename _UniformRandomNumberGenerator
>
4103 operator()(_UniformRandomNumberGenerator
& __urng
,
4104 const param_type
& __p
);
4106 template<typename _ForwardIterator
,
4107 typename _UniformRandomNumberGenerator
>
4109 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4110 _UniformRandomNumberGenerator
& __urng
)
4111 { this->__generate(__f
, __t
, __urng
, this->param()); }
4113 template<typename _ForwardIterator
,
4114 typename _UniformRandomNumberGenerator
>
4116 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4117 _UniformRandomNumberGenerator
& __urng
,
4118 const param_type
& __p
)
4119 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4121 template<typename _UniformRandomNumberGenerator
>
4123 __generate(result_type
* __f
, result_type
* __t
,
4124 _UniformRandomNumberGenerator
& __urng
,
4125 const param_type
& __p
)
4126 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4129 template<typename _ForwardIterator
,
4130 typename _UniformRandomNumberGenerator
>
4132 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4133 _UniformRandomNumberGenerator
& __urng
,
4134 const param_type
& __p
);
4136 param_type _M_param
;
4140 * @brief Return true if two geometric distributions have
4141 * the same parameters.
4143 template<typename _IntType
>
4145 operator==(const std::geometric_distribution
<_IntType
>& __d1
,
4146 const std::geometric_distribution
<_IntType
>& __d2
)
4147 { return __d1
.param() == __d2
.param(); }
4150 * @brief Return true if two geometric distributions have
4151 * different parameters.
4153 template<typename _IntType
>
4155 operator!=(const std::geometric_distribution
<_IntType
>& __d1
,
4156 const std::geometric_distribution
<_IntType
>& __d2
)
4157 { return !(__d1
== __d2
); }
4160 * @brief Inserts a %geometric_distribution random number distribution
4161 * @p __x into the output stream @p __os.
4163 * @param __os An output stream.
4164 * @param __x A %geometric_distribution random number distribution.
4166 * @returns The output stream with the state of @p __x inserted or in
4169 template<typename _IntType
,
4170 typename _CharT
, typename _Traits
>
4171 std::basic_ostream
<_CharT
, _Traits
>&
4172 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4173 const std::geometric_distribution
<_IntType
>& __x
);
4176 * @brief Extracts a %geometric_distribution random number distribution
4177 * @p __x from the input stream @p __is.
4179 * @param __is An input stream.
4180 * @param __x A %geometric_distribution random number generator engine.
4182 * @returns The input stream with @p __x extracted or in an error state.
4184 template<typename _IntType
,
4185 typename _CharT
, typename _Traits
>
4186 std::basic_istream
<_CharT
, _Traits
>&
4187 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4188 std::geometric_distribution
<_IntType
>& __x
);
4192 * @brief A negative_binomial_distribution random number distribution.
4194 * The formula for the negative binomial probability mass function is
4195 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4196 * and @f$p@f$ are the parameters of the distribution.
4198 template<typename _IntType
= int>
4199 class negative_binomial_distribution
4201 static_assert(std::is_integral
<_IntType
>::value
,
4202 "template argument not an integral type");
4205 /** The type of the range of the distribution. */
4206 typedef _IntType result_type
;
4207 /** Parameter type. */
4210 typedef negative_binomial_distribution
<_IntType
> distribution_type
;
4213 param_type(_IntType __k
= 1, double __p
= 0.5)
4214 : _M_k(__k
), _M_p(__p
)
4216 _GLIBCXX_DEBUG_ASSERT((_M_k
> 0) && (_M_p
> 0.0) && (_M_p
<= 1.0));
4228 operator==(const param_type
& __p1
, const param_type
& __p2
)
4229 { return __p1
._M_k
== __p2
._M_k
&& __p1
._M_p
== __p2
._M_p
; }
4237 negative_binomial_distribution(_IntType __k
= 1, double __p
= 0.5)
4238 : _M_param(__k
, __p
), _M_gd(__k
, (1.0 - __p
) / __p
)
4242 negative_binomial_distribution(const param_type
& __p
)
4243 : _M_param(__p
), _M_gd(__p
.k(), (1.0 - __p
.p()) / __p
.p())
4247 * @brief Resets the distribution state.
4254 * @brief Return the @f$k@f$ parameter of the distribution.
4258 { return _M_param
.k(); }
4261 * @brief Return the @f$p@f$ parameter of the distribution.
4265 { return _M_param
.p(); }
4268 * @brief Returns the parameter set of the distribution.
4272 { return _M_param
; }
4275 * @brief Sets the parameter set of the distribution.
4276 * @param __param The new parameter set of the distribution.
4279 param(const param_type
& __param
)
4280 { _M_param
= __param
; }
4283 * @brief Returns the greatest lower bound value of the distribution.
4287 { return result_type(0); }
4290 * @brief Returns the least upper bound value of the distribution.
4294 { return std::numeric_limits
<result_type
>::max(); }
4297 * @brief Generating functions.
4299 template<typename _UniformRandomNumberGenerator
>
4301 operator()(_UniformRandomNumberGenerator
& __urng
);
4303 template<typename _UniformRandomNumberGenerator
>
4305 operator()(_UniformRandomNumberGenerator
& __urng
,
4306 const param_type
& __p
);
4308 template<typename _ForwardIterator
,
4309 typename _UniformRandomNumberGenerator
>
4311 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4312 _UniformRandomNumberGenerator
& __urng
)
4313 { this->__generate_impl(__f
, __t
, __urng
); }
4315 template<typename _ForwardIterator
,
4316 typename _UniformRandomNumberGenerator
>
4318 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4319 _UniformRandomNumberGenerator
& __urng
,
4320 const param_type
& __p
)
4321 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4323 template<typename _UniformRandomNumberGenerator
>
4325 __generate(result_type
* __f
, result_type
* __t
,
4326 _UniformRandomNumberGenerator
& __urng
)
4327 { this->__generate_impl(__f
, __t
, __urng
); }
4329 template<typename _UniformRandomNumberGenerator
>
4331 __generate(result_type
* __f
, result_type
* __t
,
4332 _UniformRandomNumberGenerator
& __urng
,
4333 const param_type
& __p
)
4334 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4337 * @brief Return true if two negative binomial distributions have
4338 * the same parameters and the sequences that would be
4339 * generated are equal.
4342 operator==(const negative_binomial_distribution
& __d1
,
4343 const negative_binomial_distribution
& __d2
)
4344 { return __d1
.param() == __d2
.param() && __d1
._M_gd
== __d2
._M_gd
; }
4347 * @brief Inserts a %negative_binomial_distribution random
4348 * number distribution @p __x into the output stream @p __os.
4350 * @param __os An output stream.
4351 * @param __x A %negative_binomial_distribution random number
4354 * @returns The output stream with the state of @p __x inserted or in
4357 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4358 friend std::basic_ostream
<_CharT
, _Traits
>&
4359 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4360 const std::negative_binomial_distribution
<_IntType1
>& __x
);
4363 * @brief Extracts a %negative_binomial_distribution random number
4364 * distribution @p __x from the input stream @p __is.
4366 * @param __is An input stream.
4367 * @param __x A %negative_binomial_distribution random number
4370 * @returns The input stream with @p __x extracted or in an error state.
4372 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4373 friend std::basic_istream
<_CharT
, _Traits
>&
4374 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4375 std::negative_binomial_distribution
<_IntType1
>& __x
);
4378 template<typename _ForwardIterator
,
4379 typename _UniformRandomNumberGenerator
>
4381 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4382 _UniformRandomNumberGenerator
& __urng
);
4383 template<typename _ForwardIterator
,
4384 typename _UniformRandomNumberGenerator
>
4386 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4387 _UniformRandomNumberGenerator
& __urng
,
4388 const param_type
& __p
);
4390 param_type _M_param
;
4392 std::gamma_distribution
<double> _M_gd
;
4396 * @brief Return true if two negative binomial distributions are different.
4398 template<typename _IntType
>
4400 operator!=(const std::negative_binomial_distribution
<_IntType
>& __d1
,
4401 const std::negative_binomial_distribution
<_IntType
>& __d2
)
4402 { return !(__d1
== __d2
); }
4405 /* @} */ // group random_distributions_bernoulli
4408 * @addtogroup random_distributions_poisson Poisson Distributions
4409 * @ingroup random_distributions
4414 * @brief A discrete Poisson random number distribution.
4416 * The formula for the Poisson probability density function is
4417 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4418 * parameter of the distribution.
4420 template<typename _IntType
= int>
4421 class poisson_distribution
4423 static_assert(std::is_integral
<_IntType
>::value
,
4424 "template argument not an integral type");
4427 /** The type of the range of the distribution. */
4428 typedef _IntType result_type
;
4429 /** Parameter type. */
4432 typedef poisson_distribution
<_IntType
> distribution_type
;
4433 friend class poisson_distribution
<_IntType
>;
4436 param_type(double __mean
= 1.0)
4439 _GLIBCXX_DEBUG_ASSERT(_M_mean
> 0.0);
4448 operator==(const param_type
& __p1
, const param_type
& __p2
)
4449 { return __p1
._M_mean
== __p2
._M_mean
; }
4452 // Hosts either log(mean) or the threshold of the simple method.
4459 #if _GLIBCXX_USE_C99_MATH_TR1
4460 double _M_lfm
, _M_sm
, _M_d
, _M_scx
, _M_1cx
, _M_c2b
, _M_cb
;
4464 // constructors and member function
4466 poisson_distribution(double __mean
= 1.0)
4467 : _M_param(__mean
), _M_nd()
4471 poisson_distribution(const param_type
& __p
)
4472 : _M_param(__p
), _M_nd()
4476 * @brief Resets the distribution state.
4483 * @brief Returns the distribution parameter @p mean.
4487 { return _M_param
.mean(); }
4490 * @brief Returns the parameter set of the distribution.
4494 { return _M_param
; }
4497 * @brief Sets the parameter set of the distribution.
4498 * @param __param The new parameter set of the distribution.
4501 param(const param_type
& __param
)
4502 { _M_param
= __param
; }
4505 * @brief Returns the greatest lower bound value of the distribution.
4512 * @brief Returns the least upper bound value of the distribution.
4516 { return std::numeric_limits
<result_type
>::max(); }
4519 * @brief Generating functions.
4521 template<typename _UniformRandomNumberGenerator
>
4523 operator()(_UniformRandomNumberGenerator
& __urng
)
4524 { return this->operator()(__urng
, this->param()); }
4526 template<typename _UniformRandomNumberGenerator
>
4528 operator()(_UniformRandomNumberGenerator
& __urng
,
4529 const param_type
& __p
);
4531 template<typename _ForwardIterator
,
4532 typename _UniformRandomNumberGenerator
>
4534 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4535 _UniformRandomNumberGenerator
& __urng
)
4536 { this->__generate(__f
, __t
, __urng
, this->param()); }
4538 template<typename _ForwardIterator
,
4539 typename _UniformRandomNumberGenerator
>
4541 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4542 _UniformRandomNumberGenerator
& __urng
,
4543 const param_type
& __p
)
4544 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4546 template<typename _UniformRandomNumberGenerator
>
4548 __generate(result_type
* __f
, result_type
* __t
,
4549 _UniformRandomNumberGenerator
& __urng
,
4550 const param_type
& __p
)
4551 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4554 * @brief Return true if two Poisson distributions have the same
4555 * parameters and the sequences that would be generated
4559 operator==(const poisson_distribution
& __d1
,
4560 const poisson_distribution
& __d2
)
4561 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4562 { return __d1
.param() == __d2
.param() && __d1
._M_nd
== __d2
._M_nd
; }
4564 { return __d1
.param() == __d2
.param(); }
4568 * @brief Inserts a %poisson_distribution random number distribution
4569 * @p __x into the output stream @p __os.
4571 * @param __os An output stream.
4572 * @param __x A %poisson_distribution random number distribution.
4574 * @returns The output stream with the state of @p __x inserted or in
4577 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4578 friend std::basic_ostream
<_CharT
, _Traits
>&
4579 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4580 const std::poisson_distribution
<_IntType1
>& __x
);
4583 * @brief Extracts a %poisson_distribution random number distribution
4584 * @p __x from the input stream @p __is.
4586 * @param __is An input stream.
4587 * @param __x A %poisson_distribution random number generator engine.
4589 * @returns The input stream with @p __x extracted or in an error
4592 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4593 friend std::basic_istream
<_CharT
, _Traits
>&
4594 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4595 std::poisson_distribution
<_IntType1
>& __x
);
4598 template<typename _ForwardIterator
,
4599 typename _UniformRandomNumberGenerator
>
4601 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4602 _UniformRandomNumberGenerator
& __urng
,
4603 const param_type
& __p
);
4605 param_type _M_param
;
4607 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4608 std::normal_distribution
<double> _M_nd
;
4612 * @brief Return true if two Poisson distributions are different.
4614 template<typename _IntType
>
4616 operator!=(const std::poisson_distribution
<_IntType
>& __d1
,
4617 const std::poisson_distribution
<_IntType
>& __d2
)
4618 { return !(__d1
== __d2
); }
4622 * @brief An exponential continuous distribution for random numbers.
4624 * The formula for the exponential probability density function is
4625 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4627 * <table border=1 cellpadding=10 cellspacing=0>
4628 * <caption align=top>Distribution Statistics</caption>
4629 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4630 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4631 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4632 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4633 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4636 template<typename _RealType
= double>
4637 class exponential_distribution
4639 static_assert(std::is_floating_point
<_RealType
>::value
,
4640 "template argument not a floating point type");
4643 /** The type of the range of the distribution. */
4644 typedef _RealType result_type
;
4645 /** Parameter type. */
4648 typedef exponential_distribution
<_RealType
> distribution_type
;
4651 param_type(_RealType __lambda
= _RealType(1))
4652 : _M_lambda(__lambda
)
4654 _GLIBCXX_DEBUG_ASSERT(_M_lambda
> _RealType(0));
4659 { return _M_lambda
; }
4662 operator==(const param_type
& __p1
, const param_type
& __p2
)
4663 { return __p1
._M_lambda
== __p2
._M_lambda
; }
4666 _RealType _M_lambda
;
4671 * @brief Constructs an exponential distribution with inverse scale
4672 * parameter @f$\lambda@f$.
4675 exponential_distribution(const result_type
& __lambda
= result_type(1))
4676 : _M_param(__lambda
)
4680 exponential_distribution(const param_type
& __p
)
4685 * @brief Resets the distribution state.
4687 * Has no effect on exponential distributions.
4693 * @brief Returns the inverse scale parameter of the distribution.
4697 { return _M_param
.lambda(); }
4700 * @brief Returns the parameter set of the distribution.
4704 { return _M_param
; }
4707 * @brief Sets the parameter set of the distribution.
4708 * @param __param The new parameter set of the distribution.
4711 param(const param_type
& __param
)
4712 { _M_param
= __param
; }
4715 * @brief Returns the greatest lower bound value of the distribution.
4719 { return result_type(0); }
4722 * @brief Returns the least upper bound value of the distribution.
4726 { return std::numeric_limits
<result_type
>::max(); }
4729 * @brief Generating functions.
4731 template<typename _UniformRandomNumberGenerator
>
4733 operator()(_UniformRandomNumberGenerator
& __urng
)
4734 { return this->operator()(__urng
, this->param()); }
4736 template<typename _UniformRandomNumberGenerator
>
4738 operator()(_UniformRandomNumberGenerator
& __urng
,
4739 const param_type
& __p
)
4741 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
4743 return -std::log(__aurng()) / __p
.lambda();
4746 template<typename _ForwardIterator
,
4747 typename _UniformRandomNumberGenerator
>
4749 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4750 _UniformRandomNumberGenerator
& __urng
)
4751 { this->__generate(__f
, __t
, __urng
, this->param()); }
4753 template<typename _ForwardIterator
,
4754 typename _UniformRandomNumberGenerator
>
4756 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4757 _UniformRandomNumberGenerator
& __urng
,
4758 const param_type
& __p
)
4759 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4761 template<typename _UniformRandomNumberGenerator
>
4763 __generate(result_type
* __f
, result_type
* __t
,
4764 _UniformRandomNumberGenerator
& __urng
,
4765 const param_type
& __p
)
4766 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4769 template<typename _ForwardIterator
,
4770 typename _UniformRandomNumberGenerator
>
4772 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4773 _UniformRandomNumberGenerator
& __urng
,
4774 const param_type
& __p
);
4776 param_type _M_param
;
4780 * @brief Return true if two exponential distributions have the same
4783 template<typename _RealType
>
4785 operator==(const std::exponential_distribution
<_RealType
>& __d1
,
4786 const std::exponential_distribution
<_RealType
>& __d2
)
4787 { return __d1
.param() == __d2
.param(); }
4790 * @brief Return true if two exponential distributions have different
4793 template<typename _RealType
>
4795 operator!=(const std::exponential_distribution
<_RealType
>& __d1
,
4796 const std::exponential_distribution
<_RealType
>& __d2
)
4797 { return !(__d1
== __d2
); }
4800 * @brief Inserts a %exponential_distribution random number distribution
4801 * @p __x into the output stream @p __os.
4803 * @param __os An output stream.
4804 * @param __x A %exponential_distribution random number distribution.
4806 * @returns The output stream with the state of @p __x inserted or in
4809 template<typename _RealType
, typename _CharT
, typename _Traits
>
4810 std::basic_ostream
<_CharT
, _Traits
>&
4811 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4812 const std::exponential_distribution
<_RealType
>& __x
);
4815 * @brief Extracts a %exponential_distribution random number distribution
4816 * @p __x from the input stream @p __is.
4818 * @param __is An input stream.
4819 * @param __x A %exponential_distribution random number
4822 * @returns The input stream with @p __x extracted or in an error state.
4824 template<typename _RealType
, typename _CharT
, typename _Traits
>
4825 std::basic_istream
<_CharT
, _Traits
>&
4826 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4827 std::exponential_distribution
<_RealType
>& __x
);
4831 * @brief A weibull_distribution random number distribution.
4833 * The formula for the normal probability density function is:
4835 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4836 * \exp{(-(\frac{x}{\beta})^\alpha)}
4839 template<typename _RealType
= double>
4840 class weibull_distribution
4842 static_assert(std::is_floating_point
<_RealType
>::value
,
4843 "template argument not a floating point type");
4846 /** The type of the range of the distribution. */
4847 typedef _RealType result_type
;
4848 /** Parameter type. */
4851 typedef weibull_distribution
<_RealType
> distribution_type
;
4854 param_type(_RealType __a
= _RealType(1),
4855 _RealType __b
= _RealType(1))
4856 : _M_a(__a
), _M_b(__b
)
4868 operator==(const param_type
& __p1
, const param_type
& __p2
)
4869 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
4877 weibull_distribution(_RealType __a
= _RealType(1),
4878 _RealType __b
= _RealType(1))
4879 : _M_param(__a
, __b
)
4883 weibull_distribution(const param_type
& __p
)
4888 * @brief Resets the distribution state.
4895 * @brief Return the @f$a@f$ parameter of the distribution.
4899 { return _M_param
.a(); }
4902 * @brief Return the @f$b@f$ parameter of the distribution.
4906 { return _M_param
.b(); }
4909 * @brief Returns the parameter set of the distribution.
4913 { return _M_param
; }
4916 * @brief Sets the parameter set of the distribution.
4917 * @param __param The new parameter set of the distribution.
4920 param(const param_type
& __param
)
4921 { _M_param
= __param
; }
4924 * @brief Returns the greatest lower bound value of the distribution.
4928 { return result_type(0); }
4931 * @brief Returns the least upper bound value of the distribution.
4935 { return std::numeric_limits
<result_type
>::max(); }
4938 * @brief Generating functions.
4940 template<typename _UniformRandomNumberGenerator
>
4942 operator()(_UniformRandomNumberGenerator
& __urng
)
4943 { return this->operator()(__urng
, this->param()); }
4945 template<typename _UniformRandomNumberGenerator
>
4947 operator()(_UniformRandomNumberGenerator
& __urng
,
4948 const param_type
& __p
);
4950 template<typename _ForwardIterator
,
4951 typename _UniformRandomNumberGenerator
>
4953 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4954 _UniformRandomNumberGenerator
& __urng
)
4955 { this->__generate(__f
, __t
, __urng
, this->param()); }
4957 template<typename _ForwardIterator
,
4958 typename _UniformRandomNumberGenerator
>
4960 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4961 _UniformRandomNumberGenerator
& __urng
,
4962 const param_type
& __p
)
4963 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4965 template<typename _UniformRandomNumberGenerator
>
4967 __generate(result_type
* __f
, result_type
* __t
,
4968 _UniformRandomNumberGenerator
& __urng
,
4969 const param_type
& __p
)
4970 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4973 template<typename _ForwardIterator
,
4974 typename _UniformRandomNumberGenerator
>
4976 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4977 _UniformRandomNumberGenerator
& __urng
,
4978 const param_type
& __p
);
4980 param_type _M_param
;
4984 * @brief Return true if two Weibull distributions have the same
4987 template<typename _RealType
>
4989 operator==(const std::weibull_distribution
<_RealType
>& __d1
,
4990 const std::weibull_distribution
<_RealType
>& __d2
)
4991 { return __d1
.param() == __d2
.param(); }
4994 * @brief Return true if two Weibull distributions have different
4997 template<typename _RealType
>
4999 operator!=(const std::weibull_distribution
<_RealType
>& __d1
,
5000 const std::weibull_distribution
<_RealType
>& __d2
)
5001 { return !(__d1
== __d2
); }
5004 * @brief Inserts a %weibull_distribution random number distribution
5005 * @p __x into the output stream @p __os.
5007 * @param __os An output stream.
5008 * @param __x A %weibull_distribution random number distribution.
5010 * @returns The output stream with the state of @p __x inserted or in
5013 template<typename _RealType
, typename _CharT
, typename _Traits
>
5014 std::basic_ostream
<_CharT
, _Traits
>&
5015 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5016 const std::weibull_distribution
<_RealType
>& __x
);
5019 * @brief Extracts a %weibull_distribution random number distribution
5020 * @p __x from the input stream @p __is.
5022 * @param __is An input stream.
5023 * @param __x A %weibull_distribution random number
5026 * @returns The input stream with @p __x extracted or in an error state.
5028 template<typename _RealType
, typename _CharT
, typename _Traits
>
5029 std::basic_istream
<_CharT
, _Traits
>&
5030 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5031 std::weibull_distribution
<_RealType
>& __x
);
5035 * @brief A extreme_value_distribution random number distribution.
5037 * The formula for the normal probability mass function is
5039 * p(x|a,b) = \frac{1}{b}
5040 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5043 template<typename _RealType
= double>
5044 class extreme_value_distribution
5046 static_assert(std::is_floating_point
<_RealType
>::value
,
5047 "template argument not a floating point type");
5050 /** The type of the range of the distribution. */
5051 typedef _RealType result_type
;
5052 /** Parameter type. */
5055 typedef extreme_value_distribution
<_RealType
> distribution_type
;
5058 param_type(_RealType __a
= _RealType(0),
5059 _RealType __b
= _RealType(1))
5060 : _M_a(__a
), _M_b(__b
)
5072 operator==(const param_type
& __p1
, const param_type
& __p2
)
5073 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
5081 extreme_value_distribution(_RealType __a
= _RealType(0),
5082 _RealType __b
= _RealType(1))
5083 : _M_param(__a
, __b
)
5087 extreme_value_distribution(const param_type
& __p
)
5092 * @brief Resets the distribution state.
5099 * @brief Return the @f$a@f$ parameter of the distribution.
5103 { return _M_param
.a(); }
5106 * @brief Return the @f$b@f$ parameter of the distribution.
5110 { return _M_param
.b(); }
5113 * @brief Returns the parameter set of the distribution.
5117 { return _M_param
; }
5120 * @brief Sets the parameter set of the distribution.
5121 * @param __param The new parameter set of the distribution.
5124 param(const param_type
& __param
)
5125 { _M_param
= __param
; }
5128 * @brief Returns the greatest lower bound value of the distribution.
5132 { return std::numeric_limits
<result_type
>::min(); }
5135 * @brief Returns the least upper bound value of the distribution.
5139 { return std::numeric_limits
<result_type
>::max(); }
5142 * @brief Generating functions.
5144 template<typename _UniformRandomNumberGenerator
>
5146 operator()(_UniformRandomNumberGenerator
& __urng
)
5147 { return this->operator()(__urng
, this->param()); }
5149 template<typename _UniformRandomNumberGenerator
>
5151 operator()(_UniformRandomNumberGenerator
& __urng
,
5152 const param_type
& __p
);
5154 template<typename _ForwardIterator
,
5155 typename _UniformRandomNumberGenerator
>
5157 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5158 _UniformRandomNumberGenerator
& __urng
)
5159 { this->__generate(__f
, __t
, __urng
, this->param()); }
5161 template<typename _ForwardIterator
,
5162 typename _UniformRandomNumberGenerator
>
5164 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5165 _UniformRandomNumberGenerator
& __urng
,
5166 const param_type
& __p
)
5167 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5169 template<typename _UniformRandomNumberGenerator
>
5171 __generate(result_type
* __f
, result_type
* __t
,
5172 _UniformRandomNumberGenerator
& __urng
,
5173 const param_type
& __p
)
5174 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5177 template<typename _ForwardIterator
,
5178 typename _UniformRandomNumberGenerator
>
5180 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5181 _UniformRandomNumberGenerator
& __urng
,
5182 const param_type
& __p
);
5184 param_type _M_param
;
5188 * @brief Return true if two extreme value distributions have the same
5191 template<typename _RealType
>
5193 operator==(const std::extreme_value_distribution
<_RealType
>& __d1
,
5194 const std::extreme_value_distribution
<_RealType
>& __d2
)
5195 { return __d1
.param() == __d2
.param(); }
5198 * @brief Return true if two extreme value distributions have different
5201 template<typename _RealType
>
5203 operator!=(const std::extreme_value_distribution
<_RealType
>& __d1
,
5204 const std::extreme_value_distribution
<_RealType
>& __d2
)
5205 { return !(__d1
== __d2
); }
5208 * @brief Inserts a %extreme_value_distribution random number distribution
5209 * @p __x into the output stream @p __os.
5211 * @param __os An output stream.
5212 * @param __x A %extreme_value_distribution random number distribution.
5214 * @returns The output stream with the state of @p __x inserted or in
5217 template<typename _RealType
, typename _CharT
, typename _Traits
>
5218 std::basic_ostream
<_CharT
, _Traits
>&
5219 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5220 const std::extreme_value_distribution
<_RealType
>& __x
);
5223 * @brief Extracts a %extreme_value_distribution random number
5224 * distribution @p __x from the input stream @p __is.
5226 * @param __is An input stream.
5227 * @param __x A %extreme_value_distribution random number
5230 * @returns The input stream with @p __x extracted or in an error state.
5232 template<typename _RealType
, typename _CharT
, typename _Traits
>
5233 std::basic_istream
<_CharT
, _Traits
>&
5234 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5235 std::extreme_value_distribution
<_RealType
>& __x
);
5239 * @brief A discrete_distribution random number distribution.
5241 * The formula for the discrete probability mass function is
5244 template<typename _IntType
= int>
5245 class discrete_distribution
5247 static_assert(std::is_integral
<_IntType
>::value
,
5248 "template argument not an integral type");
5251 /** The type of the range of the distribution. */
5252 typedef _IntType result_type
;
5253 /** Parameter type. */
5256 typedef discrete_distribution
<_IntType
> distribution_type
;
5257 friend class discrete_distribution
<_IntType
>;
5260 : _M_prob(), _M_cp()
5263 template<typename _InputIterator
>
5264 param_type(_InputIterator __wbegin
,
5265 _InputIterator __wend
)
5266 : _M_prob(__wbegin
, __wend
), _M_cp()
5267 { _M_initialize(); }
5269 param_type(initializer_list
<double> __wil
)
5270 : _M_prob(__wil
.begin(), __wil
.end()), _M_cp()
5271 { _M_initialize(); }
5273 template<typename _Func
>
5274 param_type(size_t __nw
, double __xmin
, double __xmax
,
5277 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5278 param_type(const param_type
&) = default;
5279 param_type
& operator=(const param_type
&) = default;
5282 probabilities() const
5283 { return _M_prob
.empty() ? std::vector
<double>(1, 1.0) : _M_prob
; }
5286 operator==(const param_type
& __p1
, const param_type
& __p2
)
5287 { return __p1
._M_prob
== __p2
._M_prob
; }
5293 std::vector
<double> _M_prob
;
5294 std::vector
<double> _M_cp
;
5297 discrete_distribution()
5301 template<typename _InputIterator
>
5302 discrete_distribution(_InputIterator __wbegin
,
5303 _InputIterator __wend
)
5304 : _M_param(__wbegin
, __wend
)
5307 discrete_distribution(initializer_list
<double> __wl
)
5311 template<typename _Func
>
5312 discrete_distribution(size_t __nw
, double __xmin
, double __xmax
,
5314 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5318 discrete_distribution(const param_type
& __p
)
5323 * @brief Resets the distribution state.
5330 * @brief Returns the probabilities of the distribution.
5333 probabilities() const
5335 return _M_param
._M_prob
.empty()
5336 ? std::vector
<double>(1, 1.0) : _M_param
._M_prob
;
5340 * @brief Returns the parameter set of the distribution.
5344 { return _M_param
; }
5347 * @brief Sets the parameter set of the distribution.
5348 * @param __param The new parameter set of the distribution.
5351 param(const param_type
& __param
)
5352 { _M_param
= __param
; }
5355 * @brief Returns the greatest lower bound value of the distribution.
5359 { return result_type(0); }
5362 * @brief Returns the least upper bound value of the distribution.
5367 return _M_param
._M_prob
.empty()
5368 ? result_type(0) : result_type(_M_param
._M_prob
.size() - 1);
5372 * @brief Generating functions.
5374 template<typename _UniformRandomNumberGenerator
>
5376 operator()(_UniformRandomNumberGenerator
& __urng
)
5377 { return this->operator()(__urng
, this->param()); }
5379 template<typename _UniformRandomNumberGenerator
>
5381 operator()(_UniformRandomNumberGenerator
& __urng
,
5382 const param_type
& __p
);
5384 template<typename _ForwardIterator
,
5385 typename _UniformRandomNumberGenerator
>
5387 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5388 _UniformRandomNumberGenerator
& __urng
)
5389 { this->__generate(__f
, __t
, __urng
, this->param()); }
5391 template<typename _ForwardIterator
,
5392 typename _UniformRandomNumberGenerator
>
5394 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5395 _UniformRandomNumberGenerator
& __urng
,
5396 const param_type
& __p
)
5397 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5399 template<typename _UniformRandomNumberGenerator
>
5401 __generate(result_type
* __f
, result_type
* __t
,
5402 _UniformRandomNumberGenerator
& __urng
,
5403 const param_type
& __p
)
5404 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5407 * @brief Inserts a %discrete_distribution random number distribution
5408 * @p __x into the output stream @p __os.
5410 * @param __os An output stream.
5411 * @param __x A %discrete_distribution random number distribution.
5413 * @returns The output stream with the state of @p __x inserted or in
5416 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5417 friend std::basic_ostream
<_CharT
, _Traits
>&
5418 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5419 const std::discrete_distribution
<_IntType1
>& __x
);
5422 * @brief Extracts a %discrete_distribution random number distribution
5423 * @p __x from the input stream @p __is.
5425 * @param __is An input stream.
5426 * @param __x A %discrete_distribution random number
5429 * @returns The input stream with @p __x extracted or in an error
5432 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5433 friend std::basic_istream
<_CharT
, _Traits
>&
5434 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5435 std::discrete_distribution
<_IntType1
>& __x
);
5438 template<typename _ForwardIterator
,
5439 typename _UniformRandomNumberGenerator
>
5441 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5442 _UniformRandomNumberGenerator
& __urng
,
5443 const param_type
& __p
);
5445 param_type _M_param
;
5449 * @brief Return true if two discrete distributions have the same
5452 template<typename _IntType
>
5454 operator==(const std::discrete_distribution
<_IntType
>& __d1
,
5455 const std::discrete_distribution
<_IntType
>& __d2
)
5456 { return __d1
.param() == __d2
.param(); }
5459 * @brief Return true if two discrete distributions have different
5462 template<typename _IntType
>
5464 operator!=(const std::discrete_distribution
<_IntType
>& __d1
,
5465 const std::discrete_distribution
<_IntType
>& __d2
)
5466 { return !(__d1
== __d2
); }
5470 * @brief A piecewise_constant_distribution random number distribution.
5472 * The formula for the piecewise constant probability mass function is
5475 template<typename _RealType
= double>
5476 class piecewise_constant_distribution
5478 static_assert(std::is_floating_point
<_RealType
>::value
,
5479 "template argument not a floating point type");
5482 /** The type of the range of the distribution. */
5483 typedef _RealType result_type
;
5484 /** Parameter type. */
5487 typedef piecewise_constant_distribution
<_RealType
> distribution_type
;
5488 friend class piecewise_constant_distribution
<_RealType
>;
5491 : _M_int(), _M_den(), _M_cp()
5494 template<typename _InputIteratorB
, typename _InputIteratorW
>
5495 param_type(_InputIteratorB __bfirst
,
5496 _InputIteratorB __bend
,
5497 _InputIteratorW __wbegin
);
5499 template<typename _Func
>
5500 param_type(initializer_list
<_RealType
> __bi
, _Func __fw
);
5502 template<typename _Func
>
5503 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5506 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5507 param_type(const param_type
&) = default;
5508 param_type
& operator=(const param_type
&) = default;
5510 std::vector
<_RealType
>
5515 std::vector
<_RealType
> __tmp(2);
5516 __tmp
[1] = _RealType(1);
5525 { return _M_den
.empty() ? std::vector
<double>(1, 1.0) : _M_den
; }
5528 operator==(const param_type
& __p1
, const param_type
& __p2
)
5529 { return __p1
._M_int
== __p2
._M_int
&& __p1
._M_den
== __p2
._M_den
; }
5535 std::vector
<_RealType
> _M_int
;
5536 std::vector
<double> _M_den
;
5537 std::vector
<double> _M_cp
;
5541 piecewise_constant_distribution()
5545 template<typename _InputIteratorB
, typename _InputIteratorW
>
5546 piecewise_constant_distribution(_InputIteratorB __bfirst
,
5547 _InputIteratorB __bend
,
5548 _InputIteratorW __wbegin
)
5549 : _M_param(__bfirst
, __bend
, __wbegin
)
5552 template<typename _Func
>
5553 piecewise_constant_distribution(initializer_list
<_RealType
> __bl
,
5555 : _M_param(__bl
, __fw
)
5558 template<typename _Func
>
5559 piecewise_constant_distribution(size_t __nw
,
5560 _RealType __xmin
, _RealType __xmax
,
5562 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5566 piecewise_constant_distribution(const param_type
& __p
)
5571 * @brief Resets the distribution state.
5578 * @brief Returns a vector of the intervals.
5580 std::vector
<_RealType
>
5583 if (_M_param
._M_int
.empty())
5585 std::vector
<_RealType
> __tmp(2);
5586 __tmp
[1] = _RealType(1);
5590 return _M_param
._M_int
;
5594 * @brief Returns a vector of the probability densities.
5599 return _M_param
._M_den
.empty()
5600 ? std::vector
<double>(1, 1.0) : _M_param
._M_den
;
5604 * @brief Returns the parameter set of the distribution.
5608 { return _M_param
; }
5611 * @brief Sets the parameter set of the distribution.
5612 * @param __param The new parameter set of the distribution.
5615 param(const param_type
& __param
)
5616 { _M_param
= __param
; }
5619 * @brief Returns the greatest lower bound value of the distribution.
5624 return _M_param
._M_int
.empty()
5625 ? result_type(0) : _M_param
._M_int
.front();
5629 * @brief Returns the least upper bound value of the distribution.
5634 return _M_param
._M_int
.empty()
5635 ? result_type(1) : _M_param
._M_int
.back();
5639 * @brief Generating functions.
5641 template<typename _UniformRandomNumberGenerator
>
5643 operator()(_UniformRandomNumberGenerator
& __urng
)
5644 { return this->operator()(__urng
, this->param()); }
5646 template<typename _UniformRandomNumberGenerator
>
5648 operator()(_UniformRandomNumberGenerator
& __urng
,
5649 const param_type
& __p
);
5651 template<typename _ForwardIterator
,
5652 typename _UniformRandomNumberGenerator
>
5654 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5655 _UniformRandomNumberGenerator
& __urng
)
5656 { this->__generate(__f
, __t
, __urng
, this->param()); }
5658 template<typename _ForwardIterator
,
5659 typename _UniformRandomNumberGenerator
>
5661 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5662 _UniformRandomNumberGenerator
& __urng
,
5663 const param_type
& __p
)
5664 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5666 template<typename _UniformRandomNumberGenerator
>
5668 __generate(result_type
* __f
, result_type
* __t
,
5669 _UniformRandomNumberGenerator
& __urng
,
5670 const param_type
& __p
)
5671 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5674 * @brief Inserts a %piecewise_constan_distribution random
5675 * number distribution @p __x into the output stream @p __os.
5677 * @param __os An output stream.
5678 * @param __x A %piecewise_constan_distribution random number
5681 * @returns The output stream with the state of @p __x inserted or in
5684 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5685 friend std::basic_ostream
<_CharT
, _Traits
>&
5686 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5687 const std::piecewise_constant_distribution
<_RealType1
>& __x
);
5690 * @brief Extracts a %piecewise_constan_distribution random
5691 * number distribution @p __x from the input stream @p __is.
5693 * @param __is An input stream.
5694 * @param __x A %piecewise_constan_distribution random number
5697 * @returns The input stream with @p __x extracted or in an error
5700 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5701 friend std::basic_istream
<_CharT
, _Traits
>&
5702 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5703 std::piecewise_constant_distribution
<_RealType1
>& __x
);
5706 template<typename _ForwardIterator
,
5707 typename _UniformRandomNumberGenerator
>
5709 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5710 _UniformRandomNumberGenerator
& __urng
,
5711 const param_type
& __p
);
5713 param_type _M_param
;
5717 * @brief Return true if two piecewise constant distributions have the
5720 template<typename _RealType
>
5722 operator==(const std::piecewise_constant_distribution
<_RealType
>& __d1
,
5723 const std::piecewise_constant_distribution
<_RealType
>& __d2
)
5724 { return __d1
.param() == __d2
.param(); }
5727 * @brief Return true if two piecewise constant distributions have
5728 * different parameters.
5730 template<typename _RealType
>
5732 operator!=(const std::piecewise_constant_distribution
<_RealType
>& __d1
,
5733 const std::piecewise_constant_distribution
<_RealType
>& __d2
)
5734 { return !(__d1
== __d2
); }
5738 * @brief A piecewise_linear_distribution random number distribution.
5740 * The formula for the piecewise linear probability mass function is
5743 template<typename _RealType
= double>
5744 class piecewise_linear_distribution
5746 static_assert(std::is_floating_point
<_RealType
>::value
,
5747 "template argument not a floating point type");
5750 /** The type of the range of the distribution. */
5751 typedef _RealType result_type
;
5752 /** Parameter type. */
5755 typedef piecewise_linear_distribution
<_RealType
> distribution_type
;
5756 friend class piecewise_linear_distribution
<_RealType
>;
5759 : _M_int(), _M_den(), _M_cp(), _M_m()
5762 template<typename _InputIteratorB
, typename _InputIteratorW
>
5763 param_type(_InputIteratorB __bfirst
,
5764 _InputIteratorB __bend
,
5765 _InputIteratorW __wbegin
);
5767 template<typename _Func
>
5768 param_type(initializer_list
<_RealType
> __bl
, _Func __fw
);
5770 template<typename _Func
>
5771 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5774 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5775 param_type(const param_type
&) = default;
5776 param_type
& operator=(const param_type
&) = default;
5778 std::vector
<_RealType
>
5783 std::vector
<_RealType
> __tmp(2);
5784 __tmp
[1] = _RealType(1);
5793 { return _M_den
.empty() ? std::vector
<double>(2, 1.0) : _M_den
; }
5796 operator==(const param_type
& __p1
, const param_type
& __p2
)
5797 { return (__p1
._M_int
== __p2
._M_int
5798 && __p1
._M_den
== __p2
._M_den
); }
5804 std::vector
<_RealType
> _M_int
;
5805 std::vector
<double> _M_den
;
5806 std::vector
<double> _M_cp
;
5807 std::vector
<double> _M_m
;
5811 piecewise_linear_distribution()
5815 template<typename _InputIteratorB
, typename _InputIteratorW
>
5816 piecewise_linear_distribution(_InputIteratorB __bfirst
,
5817 _InputIteratorB __bend
,
5818 _InputIteratorW __wbegin
)
5819 : _M_param(__bfirst
, __bend
, __wbegin
)
5822 template<typename _Func
>
5823 piecewise_linear_distribution(initializer_list
<_RealType
> __bl
,
5825 : _M_param(__bl
, __fw
)
5828 template<typename _Func
>
5829 piecewise_linear_distribution(size_t __nw
,
5830 _RealType __xmin
, _RealType __xmax
,
5832 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5836 piecewise_linear_distribution(const param_type
& __p
)
5841 * Resets the distribution state.
5848 * @brief Return the intervals of the distribution.
5850 std::vector
<_RealType
>
5853 if (_M_param
._M_int
.empty())
5855 std::vector
<_RealType
> __tmp(2);
5856 __tmp
[1] = _RealType(1);
5860 return _M_param
._M_int
;
5864 * @brief Return a vector of the probability densities of the
5870 return _M_param
._M_den
.empty()
5871 ? std::vector
<double>(2, 1.0) : _M_param
._M_den
;
5875 * @brief Returns the parameter set of the distribution.
5879 { return _M_param
; }
5882 * @brief Sets the parameter set of the distribution.
5883 * @param __param The new parameter set of the distribution.
5886 param(const param_type
& __param
)
5887 { _M_param
= __param
; }
5890 * @brief Returns the greatest lower bound value of the distribution.
5895 return _M_param
._M_int
.empty()
5896 ? result_type(0) : _M_param
._M_int
.front();
5900 * @brief Returns the least upper bound value of the distribution.
5905 return _M_param
._M_int
.empty()
5906 ? result_type(1) : _M_param
._M_int
.back();
5910 * @brief Generating functions.
5912 template<typename _UniformRandomNumberGenerator
>
5914 operator()(_UniformRandomNumberGenerator
& __urng
)
5915 { return this->operator()(__urng
, this->param()); }
5917 template<typename _UniformRandomNumberGenerator
>
5919 operator()(_UniformRandomNumberGenerator
& __urng
,
5920 const param_type
& __p
);
5922 template<typename _ForwardIterator
,
5923 typename _UniformRandomNumberGenerator
>
5925 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5926 _UniformRandomNumberGenerator
& __urng
)
5927 { this->__generate(__f
, __t
, __urng
, this->param()); }
5929 template<typename _ForwardIterator
,
5930 typename _UniformRandomNumberGenerator
>
5932 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5933 _UniformRandomNumberGenerator
& __urng
,
5934 const param_type
& __p
)
5935 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5937 template<typename _UniformRandomNumberGenerator
>
5939 __generate(result_type
* __f
, result_type
* __t
,
5940 _UniformRandomNumberGenerator
& __urng
,
5941 const param_type
& __p
)
5942 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5945 * @brief Inserts a %piecewise_linear_distribution random number
5946 * distribution @p __x into the output stream @p __os.
5948 * @param __os An output stream.
5949 * @param __x A %piecewise_linear_distribution random number
5952 * @returns The output stream with the state of @p __x inserted or in
5955 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5956 friend std::basic_ostream
<_CharT
, _Traits
>&
5957 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5958 const std::piecewise_linear_distribution
<_RealType1
>& __x
);
5961 * @brief Extracts a %piecewise_linear_distribution random number
5962 * distribution @p __x from the input stream @p __is.
5964 * @param __is An input stream.
5965 * @param __x A %piecewise_linear_distribution random number
5968 * @returns The input stream with @p __x extracted or in an error
5971 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5972 friend std::basic_istream
<_CharT
, _Traits
>&
5973 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5974 std::piecewise_linear_distribution
<_RealType1
>& __x
);
5977 template<typename _ForwardIterator
,
5978 typename _UniformRandomNumberGenerator
>
5980 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5981 _UniformRandomNumberGenerator
& __urng
,
5982 const param_type
& __p
);
5984 param_type _M_param
;
5988 * @brief Return true if two piecewise linear distributions have the
5991 template<typename _RealType
>
5993 operator==(const std::piecewise_linear_distribution
<_RealType
>& __d1
,
5994 const std::piecewise_linear_distribution
<_RealType
>& __d2
)
5995 { return __d1
.param() == __d2
.param(); }
5998 * @brief Return true if two piecewise linear distributions have
5999 * different parameters.
6001 template<typename _RealType
>
6003 operator!=(const std::piecewise_linear_distribution
<_RealType
>& __d1
,
6004 const std::piecewise_linear_distribution
<_RealType
>& __d2
)
6005 { return !(__d1
== __d2
); }
6008 /* @} */ // group random_distributions_poisson
6010 /* @} */ // group random_distributions
6013 * @addtogroup random_utilities Random Number Utilities
6019 * @brief The seed_seq class generates sequences of seeds for random
6020 * number generators.
6026 /** The type of the seed vales. */
6027 typedef uint_least32_t result_type
;
6029 /** Default constructor. */
6034 template<typename _IntType
>
6035 seed_seq(std::initializer_list
<_IntType
> il
);
6037 template<typename _InputIterator
>
6038 seed_seq(_InputIterator __begin
, _InputIterator __end
);
6040 // generating functions
6041 template<typename _RandomAccessIterator
>
6043 generate(_RandomAccessIterator __begin
, _RandomAccessIterator __end
);
6045 // property functions
6047 { return _M_v
.size(); }
6049 template<typename OutputIterator
>
6051 param(OutputIterator __dest
) const
6052 { std::copy(_M_v
.begin(), _M_v
.end(), __dest
); }
6056 std::vector
<result_type
> _M_v
;
6059 /* @} */ // group random_utilities
6061 /* @} */ // group random
6063 _GLIBCXX_END_NAMESPACE_VERSION