1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2014 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
); }
152 /* Determine whether number is a power of 2. */
153 template<typename _Tp
>
157 return ((__x
- 1) & __x
) == 0;
161 * An adaptor class for converting the output of any Generator into
162 * the input for a specific Distribution.
164 template<typename _Engine
, typename _DInputType
>
169 _Adaptor(_Engine
& __g
)
174 { return _DInputType(0); }
178 { return _DInputType(1); }
181 * Converts a value generated by the adapted random number generator
182 * into a value in the input domain for the dependent random number
188 return std::generate_canonical
<_DInputType
,
189 std::numeric_limits
<_DInputType
>::digits
,
197 _GLIBCXX_END_NAMESPACE_VERSION
198 } // namespace __detail
200 _GLIBCXX_BEGIN_NAMESPACE_VERSION
203 * @addtogroup random_generators Random Number Generators
206 * These classes define objects which provide random or pseudorandom
207 * numbers, either from a discrete or a continuous interval. The
208 * random number generator supplied as a part of this library are
209 * all uniform random number generators which provide a sequence of
210 * random number uniformly distributed over their range.
212 * A number generator is a function object with an operator() that
213 * takes zero arguments and returns a number.
215 * A compliant random number generator must satisfy the following
216 * requirements. <table border=1 cellpadding=10 cellspacing=0>
217 * <caption align=top>Random Number Generator Requirements</caption>
218 * <tr><td>To be documented.</td></tr> </table>
224 * @brief A model of a linear congruential random number generator.
226 * A random number generator that produces pseudorandom numbers via
229 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
232 * The template parameter @p _UIntType must be an unsigned integral type
233 * large enough to store values up to (__m-1). If the template parameter
234 * @p __m is 0, the modulus @p __m used is
235 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
236 * parameters @p __a and @p __c must be less than @p __m.
238 * The size of the state is @f$1@f$.
240 template<typename _UIntType
, _UIntType __a
, _UIntType __c
, _UIntType __m
>
241 class linear_congruential_engine
243 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
244 "substituting _UIntType not an unsigned integral type");
245 static_assert(__m
== 0u || (__a
< __m
&& __c
< __m
),
246 "template argument substituting __m out of bounds");
249 /** The type of the generated random value. */
250 typedef _UIntType result_type
;
252 /** The multiplier. */
253 static constexpr result_type multiplier
= __a
;
255 static constexpr result_type increment
= __c
;
257 static constexpr result_type modulus
= __m
;
258 static constexpr result_type default_seed
= 1u;
261 * @brief Constructs a %linear_congruential_engine random number
262 * generator engine with seed @p __s. The default seed value
265 * @param __s The initial seed value.
268 linear_congruential_engine(result_type __s
= default_seed
)
272 * @brief Constructs a %linear_congruential_engine random number
273 * generator engine seeded from the seed sequence @p __q.
275 * @param __q the seed sequence.
277 template<typename _Sseq
, typename
= typename
278 std::enable_if
<!std::is_same
<_Sseq
, linear_congruential_engine
>::value
>
281 linear_congruential_engine(_Sseq
& __q
)
285 * @brief Reseeds the %linear_congruential_engine random number generator
286 * engine sequence to the seed @p __s.
288 * @param __s The new seed.
291 seed(result_type __s
= default_seed
);
294 * @brief Reseeds the %linear_congruential_engine random number generator
296 * sequence using values from the seed sequence @p __q.
298 * @param __q the seed sequence.
300 template<typename _Sseq
>
301 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
305 * @brief Gets the smallest possible value in the output range.
307 * The minimum depends on the @p __c parameter: if it is zero, the
308 * minimum generated must be > 0, otherwise 0 is allowed.
310 static constexpr result_type
312 { return __c
== 0u ? 1u : 0u; }
315 * @brief Gets the largest possible value in the output range.
317 static constexpr result_type
322 * @brief Discard a sequence of random numbers.
325 discard(unsigned long long __z
)
327 for (; __z
!= 0ULL; --__z
)
332 * @brief Gets the next random number in the sequence.
337 _M_x
= __detail::__mod
<_UIntType
, __m
, __a
, __c
>(_M_x
);
342 * @brief Compares two linear congruential random number generator
343 * objects of the same type for equality.
345 * @param __lhs A linear congruential random number generator object.
346 * @param __rhs Another linear congruential random number generator
349 * @returns true if the infinite sequences of generated values
350 * would be equal, false otherwise.
353 operator==(const linear_congruential_engine
& __lhs
,
354 const linear_congruential_engine
& __rhs
)
355 { return __lhs
._M_x
== __rhs
._M_x
; }
358 * @brief Writes the textual representation of the state x(i) of x to
361 * @param __os The output stream.
362 * @param __lcr A % linear_congruential_engine random number generator.
365 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
366 _UIntType1 __m1
, typename _CharT
, typename _Traits
>
367 friend std::basic_ostream
<_CharT
, _Traits
>&
368 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
369 const std::linear_congruential_engine
<_UIntType1
,
370 __a1
, __c1
, __m1
>& __lcr
);
373 * @brief Sets the state of the engine by reading its textual
374 * representation from @p __is.
376 * The textual representation must have been previously written using
377 * an output stream whose imbued locale and whose type's template
378 * specialization arguments _CharT and _Traits were the same as those
381 * @param __is The input stream.
382 * @param __lcr A % linear_congruential_engine random number generator.
385 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
386 _UIntType1 __m1
, typename _CharT
, typename _Traits
>
387 friend std::basic_istream
<_CharT
, _Traits
>&
388 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
389 std::linear_congruential_engine
<_UIntType1
, __a1
,
397 * @brief Compares two linear congruential random number generator
398 * objects of the same type for inequality.
400 * @param __lhs A linear congruential random number generator object.
401 * @param __rhs Another linear congruential random number generator
404 * @returns true if the infinite sequences of generated values
405 * would be different, false otherwise.
407 template<typename _UIntType
, _UIntType __a
, _UIntType __c
, _UIntType __m
>
409 operator!=(const std::linear_congruential_engine
<_UIntType
, __a
,
411 const std::linear_congruential_engine
<_UIntType
, __a
,
413 { return !(__lhs
== __rhs
); }
417 * A generalized feedback shift register discrete random number generator.
419 * This algorithm avoids multiplication and division and is designed to be
420 * friendly to a pipelined architecture. If the parameters are chosen
421 * correctly, this generator will produce numbers with a very long period and
422 * fairly good apparent entropy, although still not cryptographically strong.
424 * The best way to use this generator is with the predefined mt19937 class.
426 * This algorithm was originally invented by Makoto Matsumoto and
429 * @tparam __w Word size, the number of bits in each element of
431 * @tparam __n The degree of recursion.
432 * @tparam __m The period parameter.
433 * @tparam __r The separation point bit index.
434 * @tparam __a The last row of the twist matrix.
435 * @tparam __u The first right-shift tempering matrix parameter.
436 * @tparam __d The first right-shift tempering matrix mask.
437 * @tparam __s The first left-shift tempering matrix parameter.
438 * @tparam __b The first left-shift tempering matrix mask.
439 * @tparam __t The second left-shift tempering matrix parameter.
440 * @tparam __c The second left-shift tempering matrix mask.
441 * @tparam __l The second right-shift tempering matrix parameter.
442 * @tparam __f Initialization multiplier.
444 template<typename _UIntType
, size_t __w
,
445 size_t __n
, size_t __m
, size_t __r
,
446 _UIntType __a
, size_t __u
, _UIntType __d
, size_t __s
,
447 _UIntType __b
, size_t __t
,
448 _UIntType __c
, size_t __l
, _UIntType __f
>
449 class mersenne_twister_engine
451 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
452 "substituting _UIntType not an unsigned integral type");
453 static_assert(1u <= __m
&& __m
<= __n
,
454 "template argument substituting __m out of bounds");
455 static_assert(__r
<= __w
, "template argument substituting "
457 static_assert(__u
<= __w
, "template argument substituting "
459 static_assert(__s
<= __w
, "template argument substituting "
461 static_assert(__t
<= __w
, "template argument substituting "
463 static_assert(__l
<= __w
, "template argument substituting "
465 static_assert(__w
<= std::numeric_limits
<_UIntType
>::digits
,
466 "template argument substituting __w out of bound");
467 static_assert(__a
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
468 "template argument substituting __a out of bound");
469 static_assert(__b
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
470 "template argument substituting __b out of bound");
471 static_assert(__c
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
472 "template argument substituting __c out of bound");
473 static_assert(__d
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
474 "template argument substituting __d out of bound");
475 static_assert(__f
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
476 "template argument substituting __f out of bound");
479 /** The type of the generated random value. */
480 typedef _UIntType result_type
;
483 static constexpr size_t word_size
= __w
;
484 static constexpr size_t state_size
= __n
;
485 static constexpr size_t shift_size
= __m
;
486 static constexpr size_t mask_bits
= __r
;
487 static constexpr result_type xor_mask
= __a
;
488 static constexpr size_t tempering_u
= __u
;
489 static constexpr result_type tempering_d
= __d
;
490 static constexpr size_t tempering_s
= __s
;
491 static constexpr result_type tempering_b
= __b
;
492 static constexpr size_t tempering_t
= __t
;
493 static constexpr result_type tempering_c
= __c
;
494 static constexpr size_t tempering_l
= __l
;
495 static constexpr result_type initialization_multiplier
= __f
;
496 static constexpr result_type default_seed
= 5489u;
498 // constructors and member function
500 mersenne_twister_engine(result_type __sd
= default_seed
)
504 * @brief Constructs a %mersenne_twister_engine random number generator
505 * engine seeded from the seed sequence @p __q.
507 * @param __q the seed sequence.
509 template<typename _Sseq
, typename
= typename
510 std::enable_if
<!std::is_same
<_Sseq
, mersenne_twister_engine
>::value
>
513 mersenne_twister_engine(_Sseq
& __q
)
517 seed(result_type __sd
= default_seed
);
519 template<typename _Sseq
>
520 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
524 * @brief Gets the smallest possible value in the output range.
526 static constexpr result_type
531 * @brief Gets the largest possible value in the output range.
533 static constexpr result_type
535 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
538 * @brief Discard a sequence of random numbers.
541 discard(unsigned long long __z
);
547 * @brief Compares two % mersenne_twister_engine random number generator
548 * objects of the same type for equality.
550 * @param __lhs A % mersenne_twister_engine random number generator
552 * @param __rhs Another % mersenne_twister_engine random number
555 * @returns true if the infinite sequences of generated values
556 * would be equal, false otherwise.
559 operator==(const mersenne_twister_engine
& __lhs
,
560 const mersenne_twister_engine
& __rhs
)
561 { return (std::equal(__lhs
._M_x
, __lhs
._M_x
+ state_size
, __rhs
._M_x
)
562 && __lhs
._M_p
== __rhs
._M_p
); }
565 * @brief Inserts the current state of a % mersenne_twister_engine
566 * random number generator engine @p __x into the output stream
569 * @param __os An output stream.
570 * @param __x A % mersenne_twister_engine random number generator
573 * @returns The output stream with the state of @p __x inserted or in
576 template<typename _UIntType1
,
577 size_t __w1
, size_t __n1
,
578 size_t __m1
, size_t __r1
,
579 _UIntType1 __a1
, size_t __u1
,
580 _UIntType1 __d1
, size_t __s1
,
581 _UIntType1 __b1
, size_t __t1
,
582 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
583 typename _CharT
, typename _Traits
>
584 friend std::basic_ostream
<_CharT
, _Traits
>&
585 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
586 const std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
,
587 __m1
, __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
591 * @brief Extracts the current state of a % mersenne_twister_engine
592 * random number generator engine @p __x from the input stream
595 * @param __is An input stream.
596 * @param __x A % mersenne_twister_engine random number generator
599 * @returns The input stream with the state of @p __x extracted or in
602 template<typename _UIntType1
,
603 size_t __w1
, size_t __n1
,
604 size_t __m1
, size_t __r1
,
605 _UIntType1 __a1
, size_t __u1
,
606 _UIntType1 __d1
, size_t __s1
,
607 _UIntType1 __b1
, size_t __t1
,
608 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
609 typename _CharT
, typename _Traits
>
610 friend std::basic_istream
<_CharT
, _Traits
>&
611 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
612 std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
, __m1
,
613 __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
619 _UIntType _M_x
[state_size
];
624 * @brief Compares two % mersenne_twister_engine random number generator
625 * objects of the same type for inequality.
627 * @param __lhs A % mersenne_twister_engine random number generator
629 * @param __rhs Another % mersenne_twister_engine random number
632 * @returns true if the infinite sequences of generated values
633 * would be different, false otherwise.
635 template<typename _UIntType
, size_t __w
,
636 size_t __n
, size_t __m
, size_t __r
,
637 _UIntType __a
, size_t __u
, _UIntType __d
, size_t __s
,
638 _UIntType __b
, size_t __t
,
639 _UIntType __c
, size_t __l
, _UIntType __f
>
641 operator!=(const std::mersenne_twister_engine
<_UIntType
, __w
, __n
, __m
,
642 __r
, __a
, __u
, __d
, __s
, __b
, __t
, __c
, __l
, __f
>& __lhs
,
643 const std::mersenne_twister_engine
<_UIntType
, __w
, __n
, __m
,
644 __r
, __a
, __u
, __d
, __s
, __b
, __t
, __c
, __l
, __f
>& __rhs
)
645 { return !(__lhs
== __rhs
); }
649 * @brief The Marsaglia-Zaman generator.
651 * This is a model of a Generalized Fibonacci discrete random number
652 * generator, sometimes referred to as the SWC generator.
654 * A discrete random number generator that produces pseudorandom
657 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
660 * The size of the state is @f$r@f$
661 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
663 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
664 class subtract_with_carry_engine
666 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
667 "substituting _UIntType not an unsigned integral type");
668 static_assert(0u < __s
&& __s
< __r
,
669 "template argument substituting __s out of bounds");
670 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
671 "template argument substituting __w out of bounds");
674 /** The type of the generated random value. */
675 typedef _UIntType result_type
;
678 static constexpr size_t word_size
= __w
;
679 static constexpr size_t short_lag
= __s
;
680 static constexpr size_t long_lag
= __r
;
681 static constexpr result_type default_seed
= 19780503u;
684 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
685 * random number generator.
688 subtract_with_carry_engine(result_type __sd
= default_seed
)
692 * @brief Constructs a %subtract_with_carry_engine random number engine
693 * seeded from the seed sequence @p __q.
695 * @param __q the seed sequence.
697 template<typename _Sseq
, typename
= typename
698 std::enable_if
<!std::is_same
<_Sseq
, subtract_with_carry_engine
>::value
>
701 subtract_with_carry_engine(_Sseq
& __q
)
705 * @brief Seeds the initial state @f$x_0@f$ of the random number
708 * N1688[4.19] modifies this as follows. If @p __value == 0,
709 * sets value to 19780503. In any case, with a linear
710 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
711 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
712 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
713 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
714 * set carry to 1, otherwise sets carry to 0.
717 seed(result_type __sd
= default_seed
);
720 * @brief Seeds the initial state @f$x_0@f$ of the
721 * % subtract_with_carry_engine random number generator.
723 template<typename _Sseq
>
724 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
728 * @brief Gets the inclusive minimum value of the range of random
729 * integers returned by this generator.
731 static constexpr result_type
736 * @brief Gets the inclusive maximum value of the range of random
737 * integers returned by this generator.
739 static constexpr result_type
741 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
744 * @brief Discard a sequence of random numbers.
747 discard(unsigned long long __z
)
749 for (; __z
!= 0ULL; --__z
)
754 * @brief Gets the next random number in the sequence.
760 * @brief Compares two % subtract_with_carry_engine random number
761 * generator objects of the same type for equality.
763 * @param __lhs A % subtract_with_carry_engine random number generator
765 * @param __rhs Another % subtract_with_carry_engine random number
768 * @returns true if the infinite sequences of generated values
769 * would be equal, false otherwise.
772 operator==(const subtract_with_carry_engine
& __lhs
,
773 const subtract_with_carry_engine
& __rhs
)
774 { return (std::equal(__lhs
._M_x
, __lhs
._M_x
+ long_lag
, __rhs
._M_x
)
775 && __lhs
._M_carry
== __rhs
._M_carry
776 && __lhs
._M_p
== __rhs
._M_p
); }
779 * @brief Inserts the current state of a % subtract_with_carry_engine
780 * random number generator engine @p __x into the output stream
783 * @param __os An output stream.
784 * @param __x A % subtract_with_carry_engine random number generator
787 * @returns The output stream with the state of @p __x inserted or in
790 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
791 typename _CharT
, typename _Traits
>
792 friend std::basic_ostream
<_CharT
, _Traits
>&
793 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
794 const std::subtract_with_carry_engine
<_UIntType1
, __w1
,
798 * @brief Extracts the current state of a % subtract_with_carry_engine
799 * random number generator engine @p __x from the input stream
802 * @param __is An input stream.
803 * @param __x A % subtract_with_carry_engine random number generator
806 * @returns The input stream with the state of @p __x extracted or in
809 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
810 typename _CharT
, typename _Traits
>
811 friend std::basic_istream
<_CharT
, _Traits
>&
812 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
813 std::subtract_with_carry_engine
<_UIntType1
, __w1
,
817 /// The state of the generator. This is a ring buffer.
818 _UIntType _M_x
[long_lag
];
819 _UIntType _M_carry
; ///< The carry
820 size_t _M_p
; ///< Current index of x(i - r).
824 * @brief Compares two % subtract_with_carry_engine random number
825 * generator objects of the same type for inequality.
827 * @param __lhs A % subtract_with_carry_engine random number generator
829 * @param __rhs Another % subtract_with_carry_engine random number
832 * @returns true if the infinite sequences of generated values
833 * would be different, false otherwise.
835 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
837 operator!=(const std::subtract_with_carry_engine
<_UIntType
, __w
,
839 const std::subtract_with_carry_engine
<_UIntType
, __w
,
841 { return !(__lhs
== __rhs
); }
845 * Produces random numbers from some base engine by discarding blocks of
848 * 0 <= @p __r <= @p __p
850 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
851 class discard_block_engine
853 static_assert(1 <= __r
&& __r
<= __p
,
854 "template argument substituting __r out of bounds");
857 /** The type of the generated random value. */
858 typedef typename
_RandomNumberEngine::result_type result_type
;
861 static constexpr size_t block_size
= __p
;
862 static constexpr size_t used_block
= __r
;
865 * @brief Constructs a default %discard_block_engine engine.
867 * The underlying engine is default constructed as well.
869 discard_block_engine()
870 : _M_b(), _M_n(0) { }
873 * @brief Copy constructs a %discard_block_engine engine.
875 * Copies an existing base class random number generator.
876 * @param __rng An existing (base class) engine object.
879 discard_block_engine(const _RandomNumberEngine
& __rng
)
880 : _M_b(__rng
), _M_n(0) { }
883 * @brief Move constructs a %discard_block_engine engine.
885 * Copies an existing base class random number generator.
886 * @param __rng An existing (base class) engine object.
889 discard_block_engine(_RandomNumberEngine
&& __rng
)
890 : _M_b(std::move(__rng
)), _M_n(0) { }
893 * @brief Seed constructs a %discard_block_engine engine.
895 * Constructs the underlying generator engine seeded with @p __s.
896 * @param __s A seed value for the base class engine.
899 discard_block_engine(result_type __s
)
900 : _M_b(__s
), _M_n(0) { }
903 * @brief Generator construct a %discard_block_engine engine.
905 * @param __q A seed sequence.
907 template<typename _Sseq
, typename
= typename
908 std::enable_if
<!std::is_same
<_Sseq
, discard_block_engine
>::value
909 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
912 discard_block_engine(_Sseq
& __q
)
917 * @brief Reseeds the %discard_block_engine object with the default
918 * seed for the underlying base class generator engine.
928 * @brief Reseeds the %discard_block_engine object with the default
929 * seed for the underlying base class generator engine.
932 seed(result_type __s
)
939 * @brief Reseeds the %discard_block_engine object with the given seed
941 * @param __q A seed generator function.
943 template<typename _Sseq
>
952 * @brief Gets a const reference to the underlying generator engine
955 const _RandomNumberEngine
&
956 base() const noexcept
960 * @brief Gets the minimum value in the generated random number range.
962 static constexpr result_type
964 { return _RandomNumberEngine::min(); }
967 * @brief Gets the maximum value in the generated random number range.
969 static constexpr result_type
971 { return _RandomNumberEngine::max(); }
974 * @brief Discard a sequence of random numbers.
977 discard(unsigned long long __z
)
979 for (; __z
!= 0ULL; --__z
)
984 * @brief Gets the next value in the generated random number sequence.
990 * @brief Compares two %discard_block_engine random number generator
991 * objects of the same type for equality.
993 * @param __lhs A %discard_block_engine random number generator object.
994 * @param __rhs Another %discard_block_engine random number generator
997 * @returns true if the infinite sequences of generated values
998 * would be equal, false otherwise.
1001 operator==(const discard_block_engine
& __lhs
,
1002 const discard_block_engine
& __rhs
)
1003 { return __lhs
._M_b
== __rhs
._M_b
&& __lhs
._M_n
== __rhs
._M_n
; }
1006 * @brief Inserts the current state of a %discard_block_engine random
1007 * number generator engine @p __x into the output stream
1010 * @param __os An output stream.
1011 * @param __x A %discard_block_engine random number generator engine.
1013 * @returns The output stream with the state of @p __x inserted or in
1016 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1017 typename _CharT
, typename _Traits
>
1018 friend std::basic_ostream
<_CharT
, _Traits
>&
1019 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1020 const std::discard_block_engine
<_RandomNumberEngine1
,
1024 * @brief Extracts the current state of a % subtract_with_carry_engine
1025 * random number generator engine @p __x from the input stream
1028 * @param __is An input stream.
1029 * @param __x A %discard_block_engine random number generator engine.
1031 * @returns The input stream with the state of @p __x extracted or in
1034 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1035 typename _CharT
, typename _Traits
>
1036 friend std::basic_istream
<_CharT
, _Traits
>&
1037 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1038 std::discard_block_engine
<_RandomNumberEngine1
,
1042 _RandomNumberEngine _M_b
;
1047 * @brief Compares two %discard_block_engine random number generator
1048 * objects of the same type for inequality.
1050 * @param __lhs A %discard_block_engine random number generator object.
1051 * @param __rhs Another %discard_block_engine random number generator
1054 * @returns true if the infinite sequences of generated values
1055 * would be different, false otherwise.
1057 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
1059 operator!=(const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1061 const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1063 { return !(__lhs
== __rhs
); }
1067 * Produces random numbers by combining random numbers from some base
1068 * engine to produce random numbers with a specifies number of bits @p __w.
1070 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1071 class independent_bits_engine
1073 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
1074 "substituting _UIntType not an unsigned integral type");
1075 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
1076 "template argument substituting __w out of bounds");
1079 /** The type of the generated random value. */
1080 typedef _UIntType result_type
;
1083 * @brief Constructs a default %independent_bits_engine engine.
1085 * The underlying engine is default constructed as well.
1087 independent_bits_engine()
1091 * @brief Copy constructs a %independent_bits_engine engine.
1093 * Copies an existing base class random number generator.
1094 * @param __rng An existing (base class) engine object.
1097 independent_bits_engine(const _RandomNumberEngine
& __rng
)
1101 * @brief Move constructs a %independent_bits_engine engine.
1103 * Copies an existing base class random number generator.
1104 * @param __rng An existing (base class) engine object.
1107 independent_bits_engine(_RandomNumberEngine
&& __rng
)
1108 : _M_b(std::move(__rng
)) { }
1111 * @brief Seed constructs a %independent_bits_engine engine.
1113 * Constructs the underlying generator engine seeded with @p __s.
1114 * @param __s A seed value for the base class engine.
1117 independent_bits_engine(result_type __s
)
1121 * @brief Generator construct a %independent_bits_engine engine.
1123 * @param __q A seed sequence.
1125 template<typename _Sseq
, typename
= typename
1126 std::enable_if
<!std::is_same
<_Sseq
, independent_bits_engine
>::value
1127 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1130 independent_bits_engine(_Sseq
& __q
)
1135 * @brief Reseeds the %independent_bits_engine object with the default
1136 * seed for the underlying base class generator engine.
1143 * @brief Reseeds the %independent_bits_engine object with the default
1144 * seed for the underlying base class generator engine.
1147 seed(result_type __s
)
1151 * @brief Reseeds the %independent_bits_engine object with the given
1153 * @param __q A seed generator function.
1155 template<typename _Sseq
>
1161 * @brief Gets a const reference to the underlying generator engine
1164 const _RandomNumberEngine
&
1165 base() const noexcept
1169 * @brief Gets the minimum value in the generated random number range.
1171 static constexpr result_type
1176 * @brief Gets the maximum value in the generated random number range.
1178 static constexpr result_type
1180 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
1183 * @brief Discard a sequence of random numbers.
1186 discard(unsigned long long __z
)
1188 for (; __z
!= 0ULL; --__z
)
1193 * @brief Gets the next value in the generated random number sequence.
1199 * @brief Compares two %independent_bits_engine random number generator
1200 * objects of the same type for equality.
1202 * @param __lhs A %independent_bits_engine random number generator
1204 * @param __rhs Another %independent_bits_engine random number generator
1207 * @returns true if the infinite sequences of generated values
1208 * would be equal, false otherwise.
1211 operator==(const independent_bits_engine
& __lhs
,
1212 const independent_bits_engine
& __rhs
)
1213 { return __lhs
._M_b
== __rhs
._M_b
; }
1216 * @brief Extracts the current state of a % subtract_with_carry_engine
1217 * random number generator engine @p __x from the input stream
1220 * @param __is An input stream.
1221 * @param __x A %independent_bits_engine random number generator
1224 * @returns The input stream with the state of @p __x extracted or in
1227 template<typename _CharT
, typename _Traits
>
1228 friend std::basic_istream
<_CharT
, _Traits
>&
1229 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1230 std::independent_bits_engine
<_RandomNumberEngine
,
1231 __w
, _UIntType
>& __x
)
1238 _RandomNumberEngine _M_b
;
1242 * @brief Compares two %independent_bits_engine random number generator
1243 * objects of the same type for inequality.
1245 * @param __lhs A %independent_bits_engine random number generator
1247 * @param __rhs Another %independent_bits_engine random number generator
1250 * @returns true if the infinite sequences of generated values
1251 * would be different, false otherwise.
1253 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1255 operator!=(const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1257 const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1259 { return !(__lhs
== __rhs
); }
1262 * @brief Inserts the current state of a %independent_bits_engine random
1263 * number generator engine @p __x into the output stream @p __os.
1265 * @param __os An output stream.
1266 * @param __x A %independent_bits_engine random number generator engine.
1268 * @returns The output stream with the state of @p __x inserted or in
1271 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
,
1272 typename _CharT
, typename _Traits
>
1273 std::basic_ostream
<_CharT
, _Traits
>&
1274 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1275 const std::independent_bits_engine
<_RandomNumberEngine
,
1276 __w
, _UIntType
>& __x
)
1284 * @brief Produces random numbers by combining random numbers from some
1285 * base engine to produce random numbers with a specifies number of bits
1288 template<typename _RandomNumberEngine
, size_t __k
>
1289 class shuffle_order_engine
1291 static_assert(1u <= __k
, "template argument substituting "
1292 "__k out of bound");
1295 /** The type of the generated random value. */
1296 typedef typename
_RandomNumberEngine::result_type result_type
;
1298 static constexpr size_t table_size
= __k
;
1301 * @brief Constructs a default %shuffle_order_engine engine.
1303 * The underlying engine is default constructed as well.
1305 shuffle_order_engine()
1307 { _M_initialize(); }
1310 * @brief Copy constructs a %shuffle_order_engine engine.
1312 * Copies an existing base class random number generator.
1313 * @param __rng An existing (base class) engine object.
1316 shuffle_order_engine(const _RandomNumberEngine
& __rng
)
1318 { _M_initialize(); }
1321 * @brief Move constructs a %shuffle_order_engine engine.
1323 * Copies an existing base class random number generator.
1324 * @param __rng An existing (base class) engine object.
1327 shuffle_order_engine(_RandomNumberEngine
&& __rng
)
1328 : _M_b(std::move(__rng
))
1329 { _M_initialize(); }
1332 * @brief Seed constructs a %shuffle_order_engine engine.
1334 * Constructs the underlying generator engine seeded with @p __s.
1335 * @param __s A seed value for the base class engine.
1338 shuffle_order_engine(result_type __s
)
1340 { _M_initialize(); }
1343 * @brief Generator construct a %shuffle_order_engine engine.
1345 * @param __q A seed sequence.
1347 template<typename _Sseq
, typename
= typename
1348 std::enable_if
<!std::is_same
<_Sseq
, shuffle_order_engine
>::value
1349 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1352 shuffle_order_engine(_Sseq
& __q
)
1354 { _M_initialize(); }
1357 * @brief Reseeds the %shuffle_order_engine object with the default seed
1358 for the underlying base class generator engine.
1368 * @brief Reseeds the %shuffle_order_engine object with the default seed
1369 * for the underlying base class generator engine.
1372 seed(result_type __s
)
1379 * @brief Reseeds the %shuffle_order_engine object with the given seed
1381 * @param __q A seed generator function.
1383 template<typename _Sseq
>
1392 * Gets a const reference to the underlying generator engine object.
1394 const _RandomNumberEngine
&
1395 base() const noexcept
1399 * Gets the minimum value in the generated random number range.
1401 static constexpr result_type
1403 { return _RandomNumberEngine::min(); }
1406 * Gets the maximum value in the generated random number range.
1408 static constexpr result_type
1410 { return _RandomNumberEngine::max(); }
1413 * Discard a sequence of random numbers.
1416 discard(unsigned long long __z
)
1418 for (; __z
!= 0ULL; --__z
)
1423 * Gets the next value in the generated random number sequence.
1429 * Compares two %shuffle_order_engine random number generator objects
1430 * of the same type for equality.
1432 * @param __lhs A %shuffle_order_engine random number generator object.
1433 * @param __rhs Another %shuffle_order_engine random number generator
1436 * @returns true if the infinite sequences of generated values
1437 * would be equal, false otherwise.
1440 operator==(const shuffle_order_engine
& __lhs
,
1441 const shuffle_order_engine
& __rhs
)
1442 { return (__lhs
._M_b
== __rhs
._M_b
1443 && std::equal(__lhs
._M_v
, __lhs
._M_v
+ __k
, __rhs
._M_v
)
1444 && __lhs
._M_y
== __rhs
._M_y
); }
1447 * @brief Inserts the current state of a %shuffle_order_engine random
1448 * number generator engine @p __x into the output stream
1451 * @param __os An output stream.
1452 * @param __x A %shuffle_order_engine random number generator engine.
1454 * @returns The output stream with the state of @p __x inserted or in
1457 template<typename _RandomNumberEngine1
, size_t __k1
,
1458 typename _CharT
, typename _Traits
>
1459 friend std::basic_ostream
<_CharT
, _Traits
>&
1460 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1461 const std::shuffle_order_engine
<_RandomNumberEngine1
,
1465 * @brief Extracts the current state of a % subtract_with_carry_engine
1466 * random number generator engine @p __x from the input stream
1469 * @param __is An input stream.
1470 * @param __x A %shuffle_order_engine random number generator engine.
1472 * @returns The input stream with the state of @p __x extracted or in
1475 template<typename _RandomNumberEngine1
, size_t __k1
,
1476 typename _CharT
, typename _Traits
>
1477 friend std::basic_istream
<_CharT
, _Traits
>&
1478 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1479 std::shuffle_order_engine
<_RandomNumberEngine1
, __k1
>& __x
);
1482 void _M_initialize()
1484 for (size_t __i
= 0; __i
< __k
; ++__i
)
1489 _RandomNumberEngine _M_b
;
1490 result_type _M_v
[__k
];
1495 * Compares two %shuffle_order_engine random number generator objects
1496 * of the same type for inequality.
1498 * @param __lhs A %shuffle_order_engine random number generator object.
1499 * @param __rhs Another %shuffle_order_engine random number generator
1502 * @returns true if the infinite sequences of generated values
1503 * would be different, false otherwise.
1505 template<typename _RandomNumberEngine
, size_t __k
>
1507 operator!=(const std::shuffle_order_engine
<_RandomNumberEngine
,
1509 const std::shuffle_order_engine
<_RandomNumberEngine
,
1511 { return !(__lhs
== __rhs
); }
1515 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1517 typedef linear_congruential_engine
<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1521 * An alternative LCR (Lehmer Generator function).
1523 typedef linear_congruential_engine
<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1527 * The classic Mersenne Twister.
1530 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1531 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1532 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1534 typedef mersenne_twister_engine
<
1540 0xefc60000UL
, 18, 1812433253UL> mt19937
;
1543 * An alternative Mersenne Twister.
1545 typedef mersenne_twister_engine
<
1548 0xb5026f5aa96619e9ULL
, 29,
1549 0x5555555555555555ULL
, 17,
1550 0x71d67fffeda60000ULL
, 37,
1551 0xfff7eee000000000ULL
, 43,
1552 6364136223846793005ULL> mt19937_64
;
1554 typedef subtract_with_carry_engine
<uint_fast32_t, 24, 10, 24>
1557 typedef subtract_with_carry_engine
<uint_fast64_t, 48, 5, 12>
1560 typedef discard_block_engine
<ranlux24_base
, 223, 23> ranlux24
;
1562 typedef discard_block_engine
<ranlux48_base
, 389, 11> ranlux48
;
1564 typedef shuffle_order_engine
<minstd_rand0
, 256> knuth_b
;
1566 typedef minstd_rand0 default_random_engine
;
1569 * A standard interface to a platform-specific non-deterministic
1570 * random number generator (if any are available).
1575 /** The type of the generated random value. */
1576 typedef unsigned int result_type
;
1578 // constructors, destructors and member functions
1580 #ifdef _GLIBCXX_USE_RANDOM_TR1
1583 random_device(const std::string
& __token
= "default")
1594 random_device(const std::string
& __token
= "mt19937")
1595 { _M_init_pretr1(__token
); }
1601 static constexpr result_type
1603 { return std::numeric_limits
<result_type
>::min(); }
1605 static constexpr result_type
1607 { return std::numeric_limits
<result_type
>::max(); }
1610 entropy() const noexcept
1616 #ifdef _GLIBCXX_USE_RANDOM_TR1
1617 return this->_M_getval();
1619 return this->_M_getval_pretr1();
1623 // No copy functions.
1624 random_device(const random_device
&) = delete;
1625 void operator=(const random_device
&) = delete;
1629 void _M_init(const std::string
& __token
);
1630 void _M_init_pretr1(const std::string
& __token
);
1633 result_type
_M_getval();
1634 result_type
_M_getval_pretr1();
1643 /* @} */ // group random_generators
1646 * @addtogroup random_distributions Random Number Distributions
1652 * @addtogroup random_distributions_uniform Uniform Distributions
1653 * @ingroup random_distributions
1658 * @brief Uniform discrete distribution for random numbers.
1659 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1660 * probability throughout the range.
1662 template<typename _IntType
= int>
1663 class uniform_int_distribution
1665 static_assert(std::is_integral
<_IntType
>::value
,
1666 "template argument not an integral type");
1669 /** The type of the range of the distribution. */
1670 typedef _IntType result_type
;
1671 /** Parameter type. */
1674 typedef uniform_int_distribution
<_IntType
> distribution_type
;
1677 param_type(_IntType __a
= 0,
1678 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1679 : _M_a(__a
), _M_b(__b
)
1681 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1693 operator==(const param_type
& __p1
, const param_type
& __p2
)
1694 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1703 * @brief Constructs a uniform distribution object.
1706 uniform_int_distribution(_IntType __a
= 0,
1707 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1708 : _M_param(__a
, __b
)
1712 uniform_int_distribution(const param_type
& __p
)
1717 * @brief Resets the distribution state.
1719 * Does nothing for the uniform integer distribution.
1726 { return _M_param
.a(); }
1730 { return _M_param
.b(); }
1733 * @brief Returns the parameter set of the distribution.
1737 { return _M_param
; }
1740 * @brief Sets the parameter set of the distribution.
1741 * @param __param The new parameter set of the distribution.
1744 param(const param_type
& __param
)
1745 { _M_param
= __param
; }
1748 * @brief Returns the inclusive lower bound of the distribution range.
1752 { return this->a(); }
1755 * @brief Returns the inclusive upper bound of the distribution range.
1759 { return this->b(); }
1762 * @brief Generating functions.
1764 template<typename _UniformRandomNumberGenerator
>
1766 operator()(_UniformRandomNumberGenerator
& __urng
)
1767 { return this->operator()(__urng
, _M_param
); }
1769 template<typename _UniformRandomNumberGenerator
>
1771 operator()(_UniformRandomNumberGenerator
& __urng
,
1772 const param_type
& __p
);
1774 template<typename _ForwardIterator
,
1775 typename _UniformRandomNumberGenerator
>
1777 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1778 _UniformRandomNumberGenerator
& __urng
)
1779 { this->__generate(__f
, __t
, __urng
, _M_param
); }
1781 template<typename _ForwardIterator
,
1782 typename _UniformRandomNumberGenerator
>
1784 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1785 _UniformRandomNumberGenerator
& __urng
,
1786 const param_type
& __p
)
1787 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1789 template<typename _UniformRandomNumberGenerator
>
1791 __generate(result_type
* __f
, result_type
* __t
,
1792 _UniformRandomNumberGenerator
& __urng
,
1793 const param_type
& __p
)
1794 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1797 * @brief Return true if two uniform integer distributions have
1798 * the same parameters.
1801 operator==(const uniform_int_distribution
& __d1
,
1802 const uniform_int_distribution
& __d2
)
1803 { return __d1
._M_param
== __d2
._M_param
; }
1806 template<typename _ForwardIterator
,
1807 typename _UniformRandomNumberGenerator
>
1809 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
1810 _UniformRandomNumberGenerator
& __urng
,
1811 const param_type
& __p
);
1813 param_type _M_param
;
1817 * @brief Return true if two uniform integer distributions have
1818 * different parameters.
1820 template<typename _IntType
>
1822 operator!=(const std::uniform_int_distribution
<_IntType
>& __d1
,
1823 const std::uniform_int_distribution
<_IntType
>& __d2
)
1824 { return !(__d1
== __d2
); }
1827 * @brief Inserts a %uniform_int_distribution random number
1828 * distribution @p __x into the output stream @p os.
1830 * @param __os An output stream.
1831 * @param __x A %uniform_int_distribution random number distribution.
1833 * @returns The output stream with the state of @p __x inserted or in
1836 template<typename _IntType
, typename _CharT
, typename _Traits
>
1837 std::basic_ostream
<_CharT
, _Traits
>&
1838 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1839 const std::uniform_int_distribution
<_IntType
>&);
1842 * @brief Extracts a %uniform_int_distribution random number distribution
1843 * @p __x from the input stream @p __is.
1845 * @param __is An input stream.
1846 * @param __x A %uniform_int_distribution random number generator engine.
1848 * @returns The input stream with @p __x extracted or in an error state.
1850 template<typename _IntType
, typename _CharT
, typename _Traits
>
1851 std::basic_istream
<_CharT
, _Traits
>&
1852 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1853 std::uniform_int_distribution
<_IntType
>&);
1857 * @brief Uniform continuous distribution for random numbers.
1859 * A continuous random distribution on the range [min, max) with equal
1860 * probability throughout the range. The URNG should be real-valued and
1861 * deliver number in the range [0, 1).
1863 template<typename _RealType
= double>
1864 class uniform_real_distribution
1866 static_assert(std::is_floating_point
<_RealType
>::value
,
1867 "template argument not a floating point type");
1870 /** The type of the range of the distribution. */
1871 typedef _RealType result_type
;
1872 /** Parameter type. */
1875 typedef uniform_real_distribution
<_RealType
> distribution_type
;
1878 param_type(_RealType __a
= _RealType(0),
1879 _RealType __b
= _RealType(1))
1880 : _M_a(__a
), _M_b(__b
)
1882 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1894 operator==(const param_type
& __p1
, const param_type
& __p2
)
1895 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1904 * @brief Constructs a uniform_real_distribution object.
1906 * @param __a [IN] The lower bound of the distribution.
1907 * @param __b [IN] The upper bound of the distribution.
1910 uniform_real_distribution(_RealType __a
= _RealType(0),
1911 _RealType __b
= _RealType(1))
1912 : _M_param(__a
, __b
)
1916 uniform_real_distribution(const param_type
& __p
)
1921 * @brief Resets the distribution state.
1923 * Does nothing for the uniform real distribution.
1930 { return _M_param
.a(); }
1934 { return _M_param
.b(); }
1937 * @brief Returns the parameter set of the distribution.
1941 { return _M_param
; }
1944 * @brief Sets the parameter set of the distribution.
1945 * @param __param The new parameter set of the distribution.
1948 param(const param_type
& __param
)
1949 { _M_param
= __param
; }
1952 * @brief Returns the inclusive lower bound of the distribution range.
1956 { return this->a(); }
1959 * @brief Returns the inclusive upper bound of the distribution range.
1963 { return this->b(); }
1966 * @brief Generating functions.
1968 template<typename _UniformRandomNumberGenerator
>
1970 operator()(_UniformRandomNumberGenerator
& __urng
)
1971 { return this->operator()(__urng
, _M_param
); }
1973 template<typename _UniformRandomNumberGenerator
>
1975 operator()(_UniformRandomNumberGenerator
& __urng
,
1976 const param_type
& __p
)
1978 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1980 return (__aurng() * (__p
.b() - __p
.a())) + __p
.a();
1983 template<typename _ForwardIterator
,
1984 typename _UniformRandomNumberGenerator
>
1986 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1987 _UniformRandomNumberGenerator
& __urng
)
1988 { this->__generate(__f
, __t
, __urng
, _M_param
); }
1990 template<typename _ForwardIterator
,
1991 typename _UniformRandomNumberGenerator
>
1993 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1994 _UniformRandomNumberGenerator
& __urng
,
1995 const param_type
& __p
)
1996 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1998 template<typename _UniformRandomNumberGenerator
>
2000 __generate(result_type
* __f
, result_type
* __t
,
2001 _UniformRandomNumberGenerator
& __urng
,
2002 const param_type
& __p
)
2003 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2006 * @brief Return true if two uniform real distributions have
2007 * the same parameters.
2010 operator==(const uniform_real_distribution
& __d1
,
2011 const uniform_real_distribution
& __d2
)
2012 { return __d1
._M_param
== __d2
._M_param
; }
2015 template<typename _ForwardIterator
,
2016 typename _UniformRandomNumberGenerator
>
2018 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2019 _UniformRandomNumberGenerator
& __urng
,
2020 const param_type
& __p
);
2022 param_type _M_param
;
2026 * @brief Return true if two uniform real distributions have
2027 * different parameters.
2029 template<typename _IntType
>
2031 operator!=(const std::uniform_real_distribution
<_IntType
>& __d1
,
2032 const std::uniform_real_distribution
<_IntType
>& __d2
)
2033 { return !(__d1
== __d2
); }
2036 * @brief Inserts a %uniform_real_distribution random number
2037 * distribution @p __x into the output stream @p __os.
2039 * @param __os An output stream.
2040 * @param __x A %uniform_real_distribution random number distribution.
2042 * @returns The output stream with the state of @p __x inserted or in
2045 template<typename _RealType
, typename _CharT
, typename _Traits
>
2046 std::basic_ostream
<_CharT
, _Traits
>&
2047 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2048 const std::uniform_real_distribution
<_RealType
>&);
2051 * @brief Extracts a %uniform_real_distribution random number distribution
2052 * @p __x from the input stream @p __is.
2054 * @param __is An input stream.
2055 * @param __x A %uniform_real_distribution random number generator engine.
2057 * @returns The input stream with @p __x extracted or in an error state.
2059 template<typename _RealType
, typename _CharT
, typename _Traits
>
2060 std::basic_istream
<_CharT
, _Traits
>&
2061 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2062 std::uniform_real_distribution
<_RealType
>&);
2064 /* @} */ // group random_distributions_uniform
2067 * @addtogroup random_distributions_normal Normal Distributions
2068 * @ingroup random_distributions
2073 * @brief A normal continuous distribution for random numbers.
2075 * The formula for the normal probability density function is
2077 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
2078 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
2081 template<typename _RealType
= double>
2082 class normal_distribution
2084 static_assert(std::is_floating_point
<_RealType
>::value
,
2085 "template argument not a floating point type");
2088 /** The type of the range of the distribution. */
2089 typedef _RealType result_type
;
2090 /** Parameter type. */
2093 typedef normal_distribution
<_RealType
> distribution_type
;
2096 param_type(_RealType __mean
= _RealType(0),
2097 _RealType __stddev
= _RealType(1))
2098 : _M_mean(__mean
), _M_stddev(__stddev
)
2100 _GLIBCXX_DEBUG_ASSERT(_M_stddev
> _RealType(0));
2109 { return _M_stddev
; }
2112 operator==(const param_type
& __p1
, const param_type
& __p2
)
2113 { return (__p1
._M_mean
== __p2
._M_mean
2114 && __p1
._M_stddev
== __p2
._M_stddev
); }
2118 _RealType _M_stddev
;
2123 * Constructs a normal distribution with parameters @f$mean@f$ and
2124 * standard deviation.
2127 normal_distribution(result_type __mean
= result_type(0),
2128 result_type __stddev
= result_type(1))
2129 : _M_param(__mean
, __stddev
), _M_saved_available(false)
2133 normal_distribution(const param_type
& __p
)
2134 : _M_param(__p
), _M_saved_available(false)
2138 * @brief Resets the distribution state.
2142 { _M_saved_available
= false; }
2145 * @brief Returns the mean of the distribution.
2149 { return _M_param
.mean(); }
2152 * @brief Returns the standard deviation of the distribution.
2156 { return _M_param
.stddev(); }
2159 * @brief Returns the parameter set of the distribution.
2163 { return _M_param
; }
2166 * @brief Sets the parameter set of the distribution.
2167 * @param __param The new parameter set of the distribution.
2170 param(const param_type
& __param
)
2171 { _M_param
= __param
; }
2174 * @brief Returns the greatest lower bound value of the distribution.
2178 { return std::numeric_limits
<result_type
>::lowest(); }
2181 * @brief Returns the least upper bound value of the distribution.
2185 { return std::numeric_limits
<result_type
>::max(); }
2188 * @brief Generating functions.
2190 template<typename _UniformRandomNumberGenerator
>
2192 operator()(_UniformRandomNumberGenerator
& __urng
)
2193 { return this->operator()(__urng
, _M_param
); }
2195 template<typename _UniformRandomNumberGenerator
>
2197 operator()(_UniformRandomNumberGenerator
& __urng
,
2198 const param_type
& __p
);
2200 template<typename _ForwardIterator
,
2201 typename _UniformRandomNumberGenerator
>
2203 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2204 _UniformRandomNumberGenerator
& __urng
)
2205 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2207 template<typename _ForwardIterator
,
2208 typename _UniformRandomNumberGenerator
>
2210 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2211 _UniformRandomNumberGenerator
& __urng
,
2212 const param_type
& __p
)
2213 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2215 template<typename _UniformRandomNumberGenerator
>
2217 __generate(result_type
* __f
, result_type
* __t
,
2218 _UniformRandomNumberGenerator
& __urng
,
2219 const param_type
& __p
)
2220 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2223 * @brief Return true if two normal distributions have
2224 * the same parameters and the sequences that would
2225 * be generated are equal.
2227 template<typename _RealType1
>
2229 operator==(const std::normal_distribution
<_RealType1
>& __d1
,
2230 const std::normal_distribution
<_RealType1
>& __d2
);
2233 * @brief Inserts a %normal_distribution random number distribution
2234 * @p __x into the output stream @p __os.
2236 * @param __os An output stream.
2237 * @param __x A %normal_distribution random number distribution.
2239 * @returns The output stream with the state of @p __x inserted or in
2242 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2243 friend std::basic_ostream
<_CharT
, _Traits
>&
2244 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2245 const std::normal_distribution
<_RealType1
>& __x
);
2248 * @brief Extracts a %normal_distribution random number distribution
2249 * @p __x from the input stream @p __is.
2251 * @param __is An input stream.
2252 * @param __x A %normal_distribution random number generator engine.
2254 * @returns The input stream with @p __x extracted or in an error
2257 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2258 friend std::basic_istream
<_CharT
, _Traits
>&
2259 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2260 std::normal_distribution
<_RealType1
>& __x
);
2263 template<typename _ForwardIterator
,
2264 typename _UniformRandomNumberGenerator
>
2266 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2267 _UniformRandomNumberGenerator
& __urng
,
2268 const param_type
& __p
);
2270 param_type _M_param
;
2271 result_type _M_saved
;
2272 bool _M_saved_available
;
2276 * @brief Return true if two normal distributions are different.
2278 template<typename _RealType
>
2280 operator!=(const std::normal_distribution
<_RealType
>& __d1
,
2281 const std::normal_distribution
<_RealType
>& __d2
)
2282 { return !(__d1
== __d2
); }
2286 * @brief A lognormal_distribution random number distribution.
2288 * The formula for the normal probability mass function is
2290 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2291 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2294 template<typename _RealType
= double>
2295 class lognormal_distribution
2297 static_assert(std::is_floating_point
<_RealType
>::value
,
2298 "template argument not a floating point type");
2301 /** The type of the range of the distribution. */
2302 typedef _RealType result_type
;
2303 /** Parameter type. */
2306 typedef lognormal_distribution
<_RealType
> distribution_type
;
2309 param_type(_RealType __m
= _RealType(0),
2310 _RealType __s
= _RealType(1))
2311 : _M_m(__m
), _M_s(__s
)
2323 operator==(const param_type
& __p1
, const param_type
& __p2
)
2324 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_s
== __p2
._M_s
; }
2332 lognormal_distribution(_RealType __m
= _RealType(0),
2333 _RealType __s
= _RealType(1))
2334 : _M_param(__m
, __s
), _M_nd()
2338 lognormal_distribution(const param_type
& __p
)
2339 : _M_param(__p
), _M_nd()
2343 * Resets the distribution state.
2354 { return _M_param
.m(); }
2358 { return _M_param
.s(); }
2361 * @brief Returns the parameter set of the distribution.
2365 { return _M_param
; }
2368 * @brief Sets the parameter set of the distribution.
2369 * @param __param The new parameter set of the distribution.
2372 param(const param_type
& __param
)
2373 { _M_param
= __param
; }
2376 * @brief Returns the greatest lower bound value of the distribution.
2380 { return result_type(0); }
2383 * @brief Returns the least upper bound value of the distribution.
2387 { return std::numeric_limits
<result_type
>::max(); }
2390 * @brief Generating functions.
2392 template<typename _UniformRandomNumberGenerator
>
2394 operator()(_UniformRandomNumberGenerator
& __urng
)
2395 { return this->operator()(__urng
, _M_param
); }
2397 template<typename _UniformRandomNumberGenerator
>
2399 operator()(_UniformRandomNumberGenerator
& __urng
,
2400 const param_type
& __p
)
2401 { return std::exp(__p
.s() * _M_nd(__urng
) + __p
.m()); }
2403 template<typename _ForwardIterator
,
2404 typename _UniformRandomNumberGenerator
>
2406 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2407 _UniformRandomNumberGenerator
& __urng
)
2408 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2410 template<typename _ForwardIterator
,
2411 typename _UniformRandomNumberGenerator
>
2413 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2414 _UniformRandomNumberGenerator
& __urng
,
2415 const param_type
& __p
)
2416 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2418 template<typename _UniformRandomNumberGenerator
>
2420 __generate(result_type
* __f
, result_type
* __t
,
2421 _UniformRandomNumberGenerator
& __urng
,
2422 const param_type
& __p
)
2423 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2426 * @brief Return true if two lognormal distributions have
2427 * the same parameters and the sequences that would
2428 * be generated are equal.
2431 operator==(const lognormal_distribution
& __d1
,
2432 const lognormal_distribution
& __d2
)
2433 { return (__d1
._M_param
== __d2
._M_param
2434 && __d1
._M_nd
== __d2
._M_nd
); }
2437 * @brief Inserts a %lognormal_distribution random number distribution
2438 * @p __x into the output stream @p __os.
2440 * @param __os An output stream.
2441 * @param __x A %lognormal_distribution random number distribution.
2443 * @returns The output stream with the state of @p __x inserted or in
2446 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2447 friend std::basic_ostream
<_CharT
, _Traits
>&
2448 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2449 const std::lognormal_distribution
<_RealType1
>& __x
);
2452 * @brief Extracts a %lognormal_distribution random number distribution
2453 * @p __x from the input stream @p __is.
2455 * @param __is An input stream.
2456 * @param __x A %lognormal_distribution random number
2459 * @returns The input stream with @p __x extracted or in an error state.
2461 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2462 friend std::basic_istream
<_CharT
, _Traits
>&
2463 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2464 std::lognormal_distribution
<_RealType1
>& __x
);
2467 template<typename _ForwardIterator
,
2468 typename _UniformRandomNumberGenerator
>
2470 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2471 _UniformRandomNumberGenerator
& __urng
,
2472 const param_type
& __p
);
2474 param_type _M_param
;
2476 std::normal_distribution
<result_type
> _M_nd
;
2480 * @brief Return true if two lognormal distributions are different.
2482 template<typename _RealType
>
2484 operator!=(const std::lognormal_distribution
<_RealType
>& __d1
,
2485 const std::lognormal_distribution
<_RealType
>& __d2
)
2486 { return !(__d1
== __d2
); }
2490 * @brief A gamma continuous distribution for random numbers.
2492 * The formula for the gamma probability density function is:
2494 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2495 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2498 template<typename _RealType
= double>
2499 class gamma_distribution
2501 static_assert(std::is_floating_point
<_RealType
>::value
,
2502 "template argument not a floating point type");
2505 /** The type of the range of the distribution. */
2506 typedef _RealType result_type
;
2507 /** Parameter type. */
2510 typedef gamma_distribution
<_RealType
> distribution_type
;
2511 friend class gamma_distribution
<_RealType
>;
2514 param_type(_RealType __alpha_val
= _RealType(1),
2515 _RealType __beta_val
= _RealType(1))
2516 : _M_alpha(__alpha_val
), _M_beta(__beta_val
)
2518 _GLIBCXX_DEBUG_ASSERT(_M_alpha
> _RealType(0));
2524 { return _M_alpha
; }
2531 operator==(const param_type
& __p1
, const param_type
& __p2
)
2532 { return (__p1
._M_alpha
== __p2
._M_alpha
2533 && __p1
._M_beta
== __p2
._M_beta
); }
2542 _RealType _M_malpha
, _M_a2
;
2547 * @brief Constructs a gamma distribution with parameters
2548 * @f$\alpha@f$ and @f$\beta@f$.
2551 gamma_distribution(_RealType __alpha_val
= _RealType(1),
2552 _RealType __beta_val
= _RealType(1))
2553 : _M_param(__alpha_val
, __beta_val
), _M_nd()
2557 gamma_distribution(const param_type
& __p
)
2558 : _M_param(__p
), _M_nd()
2562 * @brief Resets the distribution state.
2569 * @brief Returns the @f$\alpha@f$ of the distribution.
2573 { return _M_param
.alpha(); }
2576 * @brief Returns the @f$\beta@f$ of the distribution.
2580 { return _M_param
.beta(); }
2583 * @brief Returns the parameter set of the distribution.
2587 { return _M_param
; }
2590 * @brief Sets the parameter set of the distribution.
2591 * @param __param The new parameter set of the distribution.
2594 param(const param_type
& __param
)
2595 { _M_param
= __param
; }
2598 * @brief Returns the greatest lower bound value of the distribution.
2602 { return result_type(0); }
2605 * @brief Returns the least upper bound value of the distribution.
2609 { return std::numeric_limits
<result_type
>::max(); }
2612 * @brief Generating functions.
2614 template<typename _UniformRandomNumberGenerator
>
2616 operator()(_UniformRandomNumberGenerator
& __urng
)
2617 { return this->operator()(__urng
, _M_param
); }
2619 template<typename _UniformRandomNumberGenerator
>
2621 operator()(_UniformRandomNumberGenerator
& __urng
,
2622 const param_type
& __p
);
2624 template<typename _ForwardIterator
,
2625 typename _UniformRandomNumberGenerator
>
2627 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2628 _UniformRandomNumberGenerator
& __urng
)
2629 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2631 template<typename _ForwardIterator
,
2632 typename _UniformRandomNumberGenerator
>
2634 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2635 _UniformRandomNumberGenerator
& __urng
,
2636 const param_type
& __p
)
2637 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2639 template<typename _UniformRandomNumberGenerator
>
2641 __generate(result_type
* __f
, result_type
* __t
,
2642 _UniformRandomNumberGenerator
& __urng
,
2643 const param_type
& __p
)
2644 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2647 * @brief Return true if two gamma distributions have the same
2648 * parameters and the sequences that would be generated
2652 operator==(const gamma_distribution
& __d1
,
2653 const gamma_distribution
& __d2
)
2654 { return (__d1
._M_param
== __d2
._M_param
2655 && __d1
._M_nd
== __d2
._M_nd
); }
2658 * @brief Inserts a %gamma_distribution random number distribution
2659 * @p __x into the output stream @p __os.
2661 * @param __os An output stream.
2662 * @param __x A %gamma_distribution random number distribution.
2664 * @returns The output stream with the state of @p __x inserted or in
2667 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2668 friend std::basic_ostream
<_CharT
, _Traits
>&
2669 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2670 const std::gamma_distribution
<_RealType1
>& __x
);
2673 * @brief Extracts a %gamma_distribution random number distribution
2674 * @p __x from the input stream @p __is.
2676 * @param __is An input stream.
2677 * @param __x A %gamma_distribution random number generator engine.
2679 * @returns The input stream with @p __x extracted or in an error state.
2681 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2682 friend std::basic_istream
<_CharT
, _Traits
>&
2683 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2684 std::gamma_distribution
<_RealType1
>& __x
);
2687 template<typename _ForwardIterator
,
2688 typename _UniformRandomNumberGenerator
>
2690 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2691 _UniformRandomNumberGenerator
& __urng
,
2692 const param_type
& __p
);
2694 param_type _M_param
;
2696 std::normal_distribution
<result_type
> _M_nd
;
2700 * @brief Return true if two gamma distributions are different.
2702 template<typename _RealType
>
2704 operator!=(const std::gamma_distribution
<_RealType
>& __d1
,
2705 const std::gamma_distribution
<_RealType
>& __d2
)
2706 { return !(__d1
== __d2
); }
2710 * @brief A chi_squared_distribution random number distribution.
2712 * The formula for the normal probability mass function is
2713 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2715 template<typename _RealType
= double>
2716 class chi_squared_distribution
2718 static_assert(std::is_floating_point
<_RealType
>::value
,
2719 "template argument not a floating point type");
2722 /** The type of the range of the distribution. */
2723 typedef _RealType result_type
;
2724 /** Parameter type. */
2727 typedef chi_squared_distribution
<_RealType
> distribution_type
;
2730 param_type(_RealType __n
= _RealType(1))
2739 operator==(const param_type
& __p1
, const param_type
& __p2
)
2740 { return __p1
._M_n
== __p2
._M_n
; }
2747 chi_squared_distribution(_RealType __n
= _RealType(1))
2748 : _M_param(__n
), _M_gd(__n
/ 2)
2752 chi_squared_distribution(const param_type
& __p
)
2753 : _M_param(__p
), _M_gd(__p
.n() / 2)
2757 * @brief Resets the distribution state.
2768 { return _M_param
.n(); }
2771 * @brief Returns the parameter set of the distribution.
2775 { return _M_param
; }
2778 * @brief Sets the parameter set of the distribution.
2779 * @param __param The new parameter set of the distribution.
2782 param(const param_type
& __param
)
2783 { _M_param
= __param
; }
2786 * @brief Returns the greatest lower bound value of the distribution.
2790 { return result_type(0); }
2793 * @brief Returns the least upper bound value of the distribution.
2797 { return std::numeric_limits
<result_type
>::max(); }
2800 * @brief Generating functions.
2802 template<typename _UniformRandomNumberGenerator
>
2804 operator()(_UniformRandomNumberGenerator
& __urng
)
2805 { return 2 * _M_gd(__urng
); }
2807 template<typename _UniformRandomNumberGenerator
>
2809 operator()(_UniformRandomNumberGenerator
& __urng
,
2810 const param_type
& __p
)
2812 typedef typename
std::gamma_distribution
<result_type
>::param_type
2814 return 2 * _M_gd(__urng
, param_type(__p
.n() / 2));
2817 template<typename _ForwardIterator
,
2818 typename _UniformRandomNumberGenerator
>
2820 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2821 _UniformRandomNumberGenerator
& __urng
)
2822 { this->__generate_impl(__f
, __t
, __urng
); }
2824 template<typename _ForwardIterator
,
2825 typename _UniformRandomNumberGenerator
>
2827 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2828 _UniformRandomNumberGenerator
& __urng
,
2829 const param_type
& __p
)
2830 { typename
std::gamma_distribution
<result_type
>::param_type
2832 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2834 template<typename _UniformRandomNumberGenerator
>
2836 __generate(result_type
* __f
, result_type
* __t
,
2837 _UniformRandomNumberGenerator
& __urng
)
2838 { this->__generate_impl(__f
, __t
, __urng
); }
2840 template<typename _UniformRandomNumberGenerator
>
2842 __generate(result_type
* __f
, result_type
* __t
,
2843 _UniformRandomNumberGenerator
& __urng
,
2844 const param_type
& __p
)
2845 { typename
std::gamma_distribution
<result_type
>::param_type
2847 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2850 * @brief Return true if two Chi-squared distributions have
2851 * the same parameters and the sequences that would be
2852 * generated are equal.
2855 operator==(const chi_squared_distribution
& __d1
,
2856 const chi_squared_distribution
& __d2
)
2857 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
2860 * @brief Inserts a %chi_squared_distribution random number distribution
2861 * @p __x into the output stream @p __os.
2863 * @param __os An output stream.
2864 * @param __x A %chi_squared_distribution random number distribution.
2866 * @returns The output stream with the state of @p __x inserted or in
2869 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2870 friend std::basic_ostream
<_CharT
, _Traits
>&
2871 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2872 const std::chi_squared_distribution
<_RealType1
>& __x
);
2875 * @brief Extracts a %chi_squared_distribution random number distribution
2876 * @p __x from the input stream @p __is.
2878 * @param __is An input stream.
2879 * @param __x A %chi_squared_distribution random number
2882 * @returns The input stream with @p __x extracted or in an error state.
2884 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2885 friend std::basic_istream
<_CharT
, _Traits
>&
2886 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2887 std::chi_squared_distribution
<_RealType1
>& __x
);
2890 template<typename _ForwardIterator
,
2891 typename _UniformRandomNumberGenerator
>
2893 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2894 _UniformRandomNumberGenerator
& __urng
);
2896 template<typename _ForwardIterator
,
2897 typename _UniformRandomNumberGenerator
>
2899 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2900 _UniformRandomNumberGenerator
& __urng
,
2902 std::gamma_distribution
<result_type
>::param_type
& __p
);
2904 param_type _M_param
;
2906 std::gamma_distribution
<result_type
> _M_gd
;
2910 * @brief Return true if two Chi-squared distributions are different.
2912 template<typename _RealType
>
2914 operator!=(const std::chi_squared_distribution
<_RealType
>& __d1
,
2915 const std::chi_squared_distribution
<_RealType
>& __d2
)
2916 { return !(__d1
== __d2
); }
2920 * @brief A cauchy_distribution random number distribution.
2922 * The formula for the normal probability mass function is
2923 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2925 template<typename _RealType
= double>
2926 class cauchy_distribution
2928 static_assert(std::is_floating_point
<_RealType
>::value
,
2929 "template argument not a floating point type");
2932 /** The type of the range of the distribution. */
2933 typedef _RealType result_type
;
2934 /** Parameter type. */
2937 typedef cauchy_distribution
<_RealType
> distribution_type
;
2940 param_type(_RealType __a
= _RealType(0),
2941 _RealType __b
= _RealType(1))
2942 : _M_a(__a
), _M_b(__b
)
2954 operator==(const param_type
& __p1
, const param_type
& __p2
)
2955 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
2963 cauchy_distribution(_RealType __a
= _RealType(0),
2964 _RealType __b
= _RealType(1))
2965 : _M_param(__a
, __b
)
2969 cauchy_distribution(const param_type
& __p
)
2974 * @brief Resets the distribution state.
2985 { return _M_param
.a(); }
2989 { return _M_param
.b(); }
2992 * @brief Returns the parameter set of the distribution.
2996 { return _M_param
; }
2999 * @brief Sets the parameter set of the distribution.
3000 * @param __param The new parameter set of the distribution.
3003 param(const param_type
& __param
)
3004 { _M_param
= __param
; }
3007 * @brief Returns the greatest lower bound value of the distribution.
3011 { return std::numeric_limits
<result_type
>::lowest(); }
3014 * @brief Returns the least upper bound value of the distribution.
3018 { return std::numeric_limits
<result_type
>::max(); }
3021 * @brief Generating functions.
3023 template<typename _UniformRandomNumberGenerator
>
3025 operator()(_UniformRandomNumberGenerator
& __urng
)
3026 { return this->operator()(__urng
, _M_param
); }
3028 template<typename _UniformRandomNumberGenerator
>
3030 operator()(_UniformRandomNumberGenerator
& __urng
,
3031 const param_type
& __p
);
3033 template<typename _ForwardIterator
,
3034 typename _UniformRandomNumberGenerator
>
3036 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3037 _UniformRandomNumberGenerator
& __urng
)
3038 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3040 template<typename _ForwardIterator
,
3041 typename _UniformRandomNumberGenerator
>
3043 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3044 _UniformRandomNumberGenerator
& __urng
,
3045 const param_type
& __p
)
3046 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3048 template<typename _UniformRandomNumberGenerator
>
3050 __generate(result_type
* __f
, result_type
* __t
,
3051 _UniformRandomNumberGenerator
& __urng
,
3052 const param_type
& __p
)
3053 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3056 * @brief Return true if two Cauchy distributions have
3057 * the same parameters.
3060 operator==(const cauchy_distribution
& __d1
,
3061 const cauchy_distribution
& __d2
)
3062 { return __d1
._M_param
== __d2
._M_param
; }
3065 template<typename _ForwardIterator
,
3066 typename _UniformRandomNumberGenerator
>
3068 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3069 _UniformRandomNumberGenerator
& __urng
,
3070 const param_type
& __p
);
3072 param_type _M_param
;
3076 * @brief Return true if two Cauchy distributions have
3077 * different parameters.
3079 template<typename _RealType
>
3081 operator!=(const std::cauchy_distribution
<_RealType
>& __d1
,
3082 const std::cauchy_distribution
<_RealType
>& __d2
)
3083 { return !(__d1
== __d2
); }
3086 * @brief Inserts a %cauchy_distribution random number distribution
3087 * @p __x into the output stream @p __os.
3089 * @param __os An output stream.
3090 * @param __x A %cauchy_distribution random number distribution.
3092 * @returns The output stream with the state of @p __x inserted or in
3095 template<typename _RealType
, typename _CharT
, typename _Traits
>
3096 std::basic_ostream
<_CharT
, _Traits
>&
3097 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3098 const std::cauchy_distribution
<_RealType
>& __x
);
3101 * @brief Extracts a %cauchy_distribution random number distribution
3102 * @p __x from the input stream @p __is.
3104 * @param __is An input stream.
3105 * @param __x A %cauchy_distribution random number
3108 * @returns The input stream with @p __x extracted or in an error state.
3110 template<typename _RealType
, typename _CharT
, typename _Traits
>
3111 std::basic_istream
<_CharT
, _Traits
>&
3112 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3113 std::cauchy_distribution
<_RealType
>& __x
);
3117 * @brief A fisher_f_distribution random number distribution.
3119 * The formula for the normal probability mass function is
3121 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3122 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3123 * (1 + \frac{mx}{n})^{-(m+n)/2}
3126 template<typename _RealType
= double>
3127 class fisher_f_distribution
3129 static_assert(std::is_floating_point
<_RealType
>::value
,
3130 "template argument not a floating point type");
3133 /** The type of the range of the distribution. */
3134 typedef _RealType result_type
;
3135 /** Parameter type. */
3138 typedef fisher_f_distribution
<_RealType
> distribution_type
;
3141 param_type(_RealType __m
= _RealType(1),
3142 _RealType __n
= _RealType(1))
3143 : _M_m(__m
), _M_n(__n
)
3155 operator==(const param_type
& __p1
, const param_type
& __p2
)
3156 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_n
== __p2
._M_n
; }
3164 fisher_f_distribution(_RealType __m
= _RealType(1),
3165 _RealType __n
= _RealType(1))
3166 : _M_param(__m
, __n
), _M_gd_x(__m
/ 2), _M_gd_y(__n
/ 2)
3170 fisher_f_distribution(const param_type
& __p
)
3171 : _M_param(__p
), _M_gd_x(__p
.m() / 2), _M_gd_y(__p
.n() / 2)
3175 * @brief Resets the distribution state.
3189 { return _M_param
.m(); }
3193 { return _M_param
.n(); }
3196 * @brief Returns the parameter set of the distribution.
3200 { return _M_param
; }
3203 * @brief Sets the parameter set of the distribution.
3204 * @param __param The new parameter set of the distribution.
3207 param(const param_type
& __param
)
3208 { _M_param
= __param
; }
3211 * @brief Returns the greatest lower bound value of the distribution.
3215 { return result_type(0); }
3218 * @brief Returns the least upper bound value of the distribution.
3222 { return std::numeric_limits
<result_type
>::max(); }
3225 * @brief Generating functions.
3227 template<typename _UniformRandomNumberGenerator
>
3229 operator()(_UniformRandomNumberGenerator
& __urng
)
3230 { return (_M_gd_x(__urng
) * n()) / (_M_gd_y(__urng
) * m()); }
3232 template<typename _UniformRandomNumberGenerator
>
3234 operator()(_UniformRandomNumberGenerator
& __urng
,
3235 const param_type
& __p
)
3237 typedef typename
std::gamma_distribution
<result_type
>::param_type
3239 return ((_M_gd_x(__urng
, param_type(__p
.m() / 2)) * n())
3240 / (_M_gd_y(__urng
, param_type(__p
.n() / 2)) * m()));
3243 template<typename _ForwardIterator
,
3244 typename _UniformRandomNumberGenerator
>
3246 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3247 _UniformRandomNumberGenerator
& __urng
)
3248 { this->__generate_impl(__f
, __t
, __urng
); }
3250 template<typename _ForwardIterator
,
3251 typename _UniformRandomNumberGenerator
>
3253 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3254 _UniformRandomNumberGenerator
& __urng
,
3255 const param_type
& __p
)
3256 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3258 template<typename _UniformRandomNumberGenerator
>
3260 __generate(result_type
* __f
, result_type
* __t
,
3261 _UniformRandomNumberGenerator
& __urng
)
3262 { this->__generate_impl(__f
, __t
, __urng
); }
3264 template<typename _UniformRandomNumberGenerator
>
3266 __generate(result_type
* __f
, result_type
* __t
,
3267 _UniformRandomNumberGenerator
& __urng
,
3268 const param_type
& __p
)
3269 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3272 * @brief Return true if two Fisher f distributions have
3273 * the same parameters and the sequences that would
3274 * be generated are equal.
3277 operator==(const fisher_f_distribution
& __d1
,
3278 const fisher_f_distribution
& __d2
)
3279 { return (__d1
._M_param
== __d2
._M_param
3280 && __d1
._M_gd_x
== __d2
._M_gd_x
3281 && __d1
._M_gd_y
== __d2
._M_gd_y
); }
3284 * @brief Inserts a %fisher_f_distribution random number distribution
3285 * @p __x into the output stream @p __os.
3287 * @param __os An output stream.
3288 * @param __x A %fisher_f_distribution random number distribution.
3290 * @returns The output stream with the state of @p __x inserted or in
3293 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3294 friend std::basic_ostream
<_CharT
, _Traits
>&
3295 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3296 const std::fisher_f_distribution
<_RealType1
>& __x
);
3299 * @brief Extracts a %fisher_f_distribution random number distribution
3300 * @p __x from the input stream @p __is.
3302 * @param __is An input stream.
3303 * @param __x A %fisher_f_distribution random number
3306 * @returns The input stream with @p __x extracted or in an error state.
3308 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3309 friend std::basic_istream
<_CharT
, _Traits
>&
3310 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3311 std::fisher_f_distribution
<_RealType1
>& __x
);
3314 template<typename _ForwardIterator
,
3315 typename _UniformRandomNumberGenerator
>
3317 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3318 _UniformRandomNumberGenerator
& __urng
);
3320 template<typename _ForwardIterator
,
3321 typename _UniformRandomNumberGenerator
>
3323 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3324 _UniformRandomNumberGenerator
& __urng
,
3325 const param_type
& __p
);
3327 param_type _M_param
;
3329 std::gamma_distribution
<result_type
> _M_gd_x
, _M_gd_y
;
3333 * @brief Return true if two Fisher f distributions are different.
3335 template<typename _RealType
>
3337 operator!=(const std::fisher_f_distribution
<_RealType
>& __d1
,
3338 const std::fisher_f_distribution
<_RealType
>& __d2
)
3339 { return !(__d1
== __d2
); }
3342 * @brief A student_t_distribution random number distribution.
3344 * The formula for the normal probability mass function is:
3346 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3347 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3350 template<typename _RealType
= double>
3351 class student_t_distribution
3353 static_assert(std::is_floating_point
<_RealType
>::value
,
3354 "template argument not a floating point type");
3357 /** The type of the range of the distribution. */
3358 typedef _RealType result_type
;
3359 /** Parameter type. */
3362 typedef student_t_distribution
<_RealType
> distribution_type
;
3365 param_type(_RealType __n
= _RealType(1))
3374 operator==(const param_type
& __p1
, const param_type
& __p2
)
3375 { return __p1
._M_n
== __p2
._M_n
; }
3382 student_t_distribution(_RealType __n
= _RealType(1))
3383 : _M_param(__n
), _M_nd(), _M_gd(__n
/ 2, 2)
3387 student_t_distribution(const param_type
& __p
)
3388 : _M_param(__p
), _M_nd(), _M_gd(__p
.n() / 2, 2)
3392 * @brief Resets the distribution state.
3406 { return _M_param
.n(); }
3409 * @brief Returns the parameter set of the distribution.
3413 { return _M_param
; }
3416 * @brief Sets the parameter set of the distribution.
3417 * @param __param The new parameter set of the distribution.
3420 param(const param_type
& __param
)
3421 { _M_param
= __param
; }
3424 * @brief Returns the greatest lower bound value of the distribution.
3428 { return std::numeric_limits
<result_type
>::lowest(); }
3431 * @brief Returns the least upper bound value of the distribution.
3435 { return std::numeric_limits
<result_type
>::max(); }
3438 * @brief Generating functions.
3440 template<typename _UniformRandomNumberGenerator
>
3442 operator()(_UniformRandomNumberGenerator
& __urng
)
3443 { return _M_nd(__urng
) * std::sqrt(n() / _M_gd(__urng
)); }
3445 template<typename _UniformRandomNumberGenerator
>
3447 operator()(_UniformRandomNumberGenerator
& __urng
,
3448 const param_type
& __p
)
3450 typedef typename
std::gamma_distribution
<result_type
>::param_type
3453 const result_type __g
= _M_gd(__urng
, param_type(__p
.n() / 2, 2));
3454 return _M_nd(__urng
) * std::sqrt(__p
.n() / __g
);
3457 template<typename _ForwardIterator
,
3458 typename _UniformRandomNumberGenerator
>
3460 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3461 _UniformRandomNumberGenerator
& __urng
)
3462 { this->__generate_impl(__f
, __t
, __urng
); }
3464 template<typename _ForwardIterator
,
3465 typename _UniformRandomNumberGenerator
>
3467 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3468 _UniformRandomNumberGenerator
& __urng
,
3469 const param_type
& __p
)
3470 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3472 template<typename _UniformRandomNumberGenerator
>
3474 __generate(result_type
* __f
, result_type
* __t
,
3475 _UniformRandomNumberGenerator
& __urng
)
3476 { this->__generate_impl(__f
, __t
, __urng
); }
3478 template<typename _UniformRandomNumberGenerator
>
3480 __generate(result_type
* __f
, result_type
* __t
,
3481 _UniformRandomNumberGenerator
& __urng
,
3482 const param_type
& __p
)
3483 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3486 * @brief Return true if two Student t distributions have
3487 * the same parameters and the sequences that would
3488 * be generated are equal.
3491 operator==(const student_t_distribution
& __d1
,
3492 const student_t_distribution
& __d2
)
3493 { return (__d1
._M_param
== __d2
._M_param
3494 && __d1
._M_nd
== __d2
._M_nd
&& __d1
._M_gd
== __d2
._M_gd
); }
3497 * @brief Inserts a %student_t_distribution random number distribution
3498 * @p __x into the output stream @p __os.
3500 * @param __os An output stream.
3501 * @param __x A %student_t_distribution random number distribution.
3503 * @returns The output stream with the state of @p __x inserted or in
3506 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3507 friend std::basic_ostream
<_CharT
, _Traits
>&
3508 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3509 const std::student_t_distribution
<_RealType1
>& __x
);
3512 * @brief Extracts a %student_t_distribution random number distribution
3513 * @p __x from the input stream @p __is.
3515 * @param __is An input stream.
3516 * @param __x A %student_t_distribution random number
3519 * @returns The input stream with @p __x extracted or in an error state.
3521 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3522 friend std::basic_istream
<_CharT
, _Traits
>&
3523 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3524 std::student_t_distribution
<_RealType1
>& __x
);
3527 template<typename _ForwardIterator
,
3528 typename _UniformRandomNumberGenerator
>
3530 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3531 _UniformRandomNumberGenerator
& __urng
);
3532 template<typename _ForwardIterator
,
3533 typename _UniformRandomNumberGenerator
>
3535 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3536 _UniformRandomNumberGenerator
& __urng
,
3537 const param_type
& __p
);
3539 param_type _M_param
;
3541 std::normal_distribution
<result_type
> _M_nd
;
3542 std::gamma_distribution
<result_type
> _M_gd
;
3546 * @brief Return true if two Student t distributions are different.
3548 template<typename _RealType
>
3550 operator!=(const std::student_t_distribution
<_RealType
>& __d1
,
3551 const std::student_t_distribution
<_RealType
>& __d2
)
3552 { return !(__d1
== __d2
); }
3555 /* @} */ // group random_distributions_normal
3558 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3559 * @ingroup random_distributions
3564 * @brief A Bernoulli random number distribution.
3566 * Generates a sequence of true and false values with likelihood @f$p@f$
3567 * that true will come up and @f$(1 - p)@f$ that false will appear.
3569 class bernoulli_distribution
3572 /** The type of the range of the distribution. */
3573 typedef bool result_type
;
3574 /** Parameter type. */
3577 typedef bernoulli_distribution distribution_type
;
3580 param_type(double __p
= 0.5)
3583 _GLIBCXX_DEBUG_ASSERT((_M_p
>= 0.0) && (_M_p
<= 1.0));
3591 operator==(const param_type
& __p1
, const param_type
& __p2
)
3592 { return __p1
._M_p
== __p2
._M_p
; }
3600 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3602 * @param __p [IN] The likelihood of a true result being returned.
3603 * Must be in the interval @f$[0, 1]@f$.
3606 bernoulli_distribution(double __p
= 0.5)
3611 bernoulli_distribution(const param_type
& __p
)
3616 * @brief Resets the distribution state.
3618 * Does nothing for a Bernoulli distribution.
3624 * @brief Returns the @p p parameter of the distribution.
3628 { return _M_param
.p(); }
3631 * @brief Returns the parameter set of the distribution.
3635 { return _M_param
; }
3638 * @brief Sets the parameter set of the distribution.
3639 * @param __param The new parameter set of the distribution.
3642 param(const param_type
& __param
)
3643 { _M_param
= __param
; }
3646 * @brief Returns the greatest lower bound value of the distribution.
3650 { return std::numeric_limits
<result_type
>::min(); }
3653 * @brief Returns the least upper bound value of the distribution.
3657 { return std::numeric_limits
<result_type
>::max(); }
3660 * @brief Generating functions.
3662 template<typename _UniformRandomNumberGenerator
>
3664 operator()(_UniformRandomNumberGenerator
& __urng
)
3665 { return this->operator()(__urng
, _M_param
); }
3667 template<typename _UniformRandomNumberGenerator
>
3669 operator()(_UniformRandomNumberGenerator
& __urng
,
3670 const param_type
& __p
)
3672 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
3674 if ((__aurng() - __aurng
.min())
3675 < __p
.p() * (__aurng
.max() - __aurng
.min()))
3680 template<typename _ForwardIterator
,
3681 typename _UniformRandomNumberGenerator
>
3683 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3684 _UniformRandomNumberGenerator
& __urng
)
3685 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3687 template<typename _ForwardIterator
,
3688 typename _UniformRandomNumberGenerator
>
3690 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3691 _UniformRandomNumberGenerator
& __urng
, const param_type
& __p
)
3692 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3694 template<typename _UniformRandomNumberGenerator
>
3696 __generate(result_type
* __f
, result_type
* __t
,
3697 _UniformRandomNumberGenerator
& __urng
,
3698 const param_type
& __p
)
3699 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3702 * @brief Return true if two Bernoulli distributions have
3703 * the same parameters.
3706 operator==(const bernoulli_distribution
& __d1
,
3707 const bernoulli_distribution
& __d2
)
3708 { return __d1
._M_param
== __d2
._M_param
; }
3711 template<typename _ForwardIterator
,
3712 typename _UniformRandomNumberGenerator
>
3714 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3715 _UniformRandomNumberGenerator
& __urng
,
3716 const param_type
& __p
);
3718 param_type _M_param
;
3722 * @brief Return true if two Bernoulli distributions have
3723 * different parameters.
3726 operator!=(const std::bernoulli_distribution
& __d1
,
3727 const std::bernoulli_distribution
& __d2
)
3728 { return !(__d1
== __d2
); }
3731 * @brief Inserts a %bernoulli_distribution random number distribution
3732 * @p __x into the output stream @p __os.
3734 * @param __os An output stream.
3735 * @param __x A %bernoulli_distribution random number distribution.
3737 * @returns The output stream with the state of @p __x inserted or in
3740 template<typename _CharT
, typename _Traits
>
3741 std::basic_ostream
<_CharT
, _Traits
>&
3742 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3743 const std::bernoulli_distribution
& __x
);
3746 * @brief Extracts a %bernoulli_distribution random number distribution
3747 * @p __x from the input stream @p __is.
3749 * @param __is An input stream.
3750 * @param __x A %bernoulli_distribution random number generator engine.
3752 * @returns The input stream with @p __x extracted or in an error state.
3754 template<typename _CharT
, typename _Traits
>
3755 std::basic_istream
<_CharT
, _Traits
>&
3756 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3757 std::bernoulli_distribution
& __x
)
3761 __x
.param(bernoulli_distribution::param_type(__p
));
3767 * @brief A discrete binomial random number distribution.
3769 * The formula for the binomial probability density function is
3770 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3771 * and @f$p@f$ are the parameters of the distribution.
3773 template<typename _IntType
= int>
3774 class binomial_distribution
3776 static_assert(std::is_integral
<_IntType
>::value
,
3777 "template argument not an integral type");
3780 /** The type of the range of the distribution. */
3781 typedef _IntType result_type
;
3782 /** Parameter type. */
3785 typedef binomial_distribution
<_IntType
> distribution_type
;
3786 friend class binomial_distribution
<_IntType
>;
3789 param_type(_IntType __t
= _IntType(1), double __p
= 0.5)
3790 : _M_t(__t
), _M_p(__p
)
3792 _GLIBCXX_DEBUG_ASSERT((_M_t
>= _IntType(0))
3807 operator==(const param_type
& __p1
, const param_type
& __p2
)
3808 { return __p1
._M_t
== __p2
._M_t
&& __p1
._M_p
== __p2
._M_p
; }
3818 #if _GLIBCXX_USE_C99_MATH_TR1
3819 double _M_d1
, _M_d2
, _M_s1
, _M_s2
, _M_c
,
3820 _M_a1
, _M_a123
, _M_s
, _M_lf
, _M_lp1p
;
3825 // constructors and member function
3827 binomial_distribution(_IntType __t
= _IntType(1),
3829 : _M_param(__t
, __p
), _M_nd()
3833 binomial_distribution(const param_type
& __p
)
3834 : _M_param(__p
), _M_nd()
3838 * @brief Resets the distribution state.
3845 * @brief Returns the distribution @p t parameter.
3849 { return _M_param
.t(); }
3852 * @brief Returns the distribution @p p parameter.
3856 { return _M_param
.p(); }
3859 * @brief Returns the parameter set of the distribution.
3863 { return _M_param
; }
3866 * @brief Sets the parameter set of the distribution.
3867 * @param __param The new parameter set of the distribution.
3870 param(const param_type
& __param
)
3871 { _M_param
= __param
; }
3874 * @brief Returns the greatest lower bound value of the distribution.
3881 * @brief Returns the least upper bound value of the distribution.
3885 { return _M_param
.t(); }
3888 * @brief Generating functions.
3890 template<typename _UniformRandomNumberGenerator
>
3892 operator()(_UniformRandomNumberGenerator
& __urng
)
3893 { return this->operator()(__urng
, _M_param
); }
3895 template<typename _UniformRandomNumberGenerator
>
3897 operator()(_UniformRandomNumberGenerator
& __urng
,
3898 const param_type
& __p
);
3900 template<typename _ForwardIterator
,
3901 typename _UniformRandomNumberGenerator
>
3903 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3904 _UniformRandomNumberGenerator
& __urng
)
3905 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3907 template<typename _ForwardIterator
,
3908 typename _UniformRandomNumberGenerator
>
3910 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3911 _UniformRandomNumberGenerator
& __urng
,
3912 const param_type
& __p
)
3913 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3915 template<typename _UniformRandomNumberGenerator
>
3917 __generate(result_type
* __f
, result_type
* __t
,
3918 _UniformRandomNumberGenerator
& __urng
,
3919 const param_type
& __p
)
3920 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3923 * @brief Return true if two binomial distributions have
3924 * the same parameters and the sequences that would
3925 * be generated are equal.
3928 operator==(const binomial_distribution
& __d1
,
3929 const binomial_distribution
& __d2
)
3930 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3931 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
3933 { return __d1
._M_param
== __d2
._M_param
; }
3937 * @brief Inserts a %binomial_distribution random number distribution
3938 * @p __x into the output stream @p __os.
3940 * @param __os An output stream.
3941 * @param __x A %binomial_distribution random number distribution.
3943 * @returns The output stream with the state of @p __x inserted or in
3946 template<typename _IntType1
,
3947 typename _CharT
, typename _Traits
>
3948 friend std::basic_ostream
<_CharT
, _Traits
>&
3949 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3950 const std::binomial_distribution
<_IntType1
>& __x
);
3953 * @brief Extracts a %binomial_distribution random number distribution
3954 * @p __x from the input stream @p __is.
3956 * @param __is An input stream.
3957 * @param __x A %binomial_distribution random number generator engine.
3959 * @returns The input stream with @p __x extracted or in an error
3962 template<typename _IntType1
,
3963 typename _CharT
, typename _Traits
>
3964 friend std::basic_istream
<_CharT
, _Traits
>&
3965 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3966 std::binomial_distribution
<_IntType1
>& __x
);
3969 template<typename _ForwardIterator
,
3970 typename _UniformRandomNumberGenerator
>
3972 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3973 _UniformRandomNumberGenerator
& __urng
,
3974 const param_type
& __p
);
3976 template<typename _UniformRandomNumberGenerator
>
3978 _M_waiting(_UniformRandomNumberGenerator
& __urng
,
3979 _IntType __t
, double __q
);
3981 param_type _M_param
;
3983 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3984 std::normal_distribution
<double> _M_nd
;
3988 * @brief Return true if two binomial distributions are different.
3990 template<typename _IntType
>
3992 operator!=(const std::binomial_distribution
<_IntType
>& __d1
,
3993 const std::binomial_distribution
<_IntType
>& __d2
)
3994 { return !(__d1
== __d2
); }
3998 * @brief A discrete geometric random number distribution.
4000 * The formula for the geometric probability density function is
4001 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
4004 template<typename _IntType
= int>
4005 class geometric_distribution
4007 static_assert(std::is_integral
<_IntType
>::value
,
4008 "template argument not an integral type");
4011 /** The type of the range of the distribution. */
4012 typedef _IntType result_type
;
4013 /** Parameter type. */
4016 typedef geometric_distribution
<_IntType
> distribution_type
;
4017 friend class geometric_distribution
<_IntType
>;
4020 param_type(double __p
= 0.5)
4023 _GLIBCXX_DEBUG_ASSERT((_M_p
> 0.0) && (_M_p
< 1.0));
4032 operator==(const param_type
& __p1
, const param_type
& __p2
)
4033 { return __p1
._M_p
== __p2
._M_p
; }
4038 { _M_log_1_p
= std::log(1.0 - _M_p
); }
4045 // constructors and member function
4047 geometric_distribution(double __p
= 0.5)
4052 geometric_distribution(const param_type
& __p
)
4057 * @brief Resets the distribution state.
4059 * Does nothing for the geometric distribution.
4065 * @brief Returns the distribution parameter @p p.
4069 { return _M_param
.p(); }
4072 * @brief Returns the parameter set of the distribution.
4076 { return _M_param
; }
4079 * @brief Sets the parameter set of the distribution.
4080 * @param __param The new parameter set of the distribution.
4083 param(const param_type
& __param
)
4084 { _M_param
= __param
; }
4087 * @brief Returns the greatest lower bound value of the distribution.
4094 * @brief Returns the least upper bound value of the distribution.
4098 { return std::numeric_limits
<result_type
>::max(); }
4101 * @brief Generating functions.
4103 template<typename _UniformRandomNumberGenerator
>
4105 operator()(_UniformRandomNumberGenerator
& __urng
)
4106 { return this->operator()(__urng
, _M_param
); }
4108 template<typename _UniformRandomNumberGenerator
>
4110 operator()(_UniformRandomNumberGenerator
& __urng
,
4111 const param_type
& __p
);
4113 template<typename _ForwardIterator
,
4114 typename _UniformRandomNumberGenerator
>
4116 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4117 _UniformRandomNumberGenerator
& __urng
)
4118 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4120 template<typename _ForwardIterator
,
4121 typename _UniformRandomNumberGenerator
>
4123 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4124 _UniformRandomNumberGenerator
& __urng
,
4125 const param_type
& __p
)
4126 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4128 template<typename _UniformRandomNumberGenerator
>
4130 __generate(result_type
* __f
, result_type
* __t
,
4131 _UniformRandomNumberGenerator
& __urng
,
4132 const param_type
& __p
)
4133 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4136 * @brief Return true if two geometric distributions have
4137 * the same parameters.
4140 operator==(const geometric_distribution
& __d1
,
4141 const geometric_distribution
& __d2
)
4142 { return __d1
._M_param
== __d2
._M_param
; }
4145 template<typename _ForwardIterator
,
4146 typename _UniformRandomNumberGenerator
>
4148 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4149 _UniformRandomNumberGenerator
& __urng
,
4150 const param_type
& __p
);
4152 param_type _M_param
;
4156 * @brief Return true if two geometric distributions have
4157 * different parameters.
4159 template<typename _IntType
>
4161 operator!=(const std::geometric_distribution
<_IntType
>& __d1
,
4162 const std::geometric_distribution
<_IntType
>& __d2
)
4163 { return !(__d1
== __d2
); }
4166 * @brief Inserts a %geometric_distribution random number distribution
4167 * @p __x into the output stream @p __os.
4169 * @param __os An output stream.
4170 * @param __x A %geometric_distribution random number distribution.
4172 * @returns The output stream with the state of @p __x inserted or in
4175 template<typename _IntType
,
4176 typename _CharT
, typename _Traits
>
4177 std::basic_ostream
<_CharT
, _Traits
>&
4178 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4179 const std::geometric_distribution
<_IntType
>& __x
);
4182 * @brief Extracts a %geometric_distribution random number distribution
4183 * @p __x from the input stream @p __is.
4185 * @param __is An input stream.
4186 * @param __x A %geometric_distribution random number generator engine.
4188 * @returns The input stream with @p __x extracted or in an error state.
4190 template<typename _IntType
,
4191 typename _CharT
, typename _Traits
>
4192 std::basic_istream
<_CharT
, _Traits
>&
4193 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4194 std::geometric_distribution
<_IntType
>& __x
);
4198 * @brief A negative_binomial_distribution random number distribution.
4200 * The formula for the negative binomial probability mass function is
4201 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4202 * and @f$p@f$ are the parameters of the distribution.
4204 template<typename _IntType
= int>
4205 class negative_binomial_distribution
4207 static_assert(std::is_integral
<_IntType
>::value
,
4208 "template argument not an integral type");
4211 /** The type of the range of the distribution. */
4212 typedef _IntType result_type
;
4213 /** Parameter type. */
4216 typedef negative_binomial_distribution
<_IntType
> distribution_type
;
4219 param_type(_IntType __k
= 1, double __p
= 0.5)
4220 : _M_k(__k
), _M_p(__p
)
4222 _GLIBCXX_DEBUG_ASSERT((_M_k
> 0) && (_M_p
> 0.0) && (_M_p
<= 1.0));
4234 operator==(const param_type
& __p1
, const param_type
& __p2
)
4235 { return __p1
._M_k
== __p2
._M_k
&& __p1
._M_p
== __p2
._M_p
; }
4243 negative_binomial_distribution(_IntType __k
= 1, double __p
= 0.5)
4244 : _M_param(__k
, __p
), _M_gd(__k
, (1.0 - __p
) / __p
)
4248 negative_binomial_distribution(const param_type
& __p
)
4249 : _M_param(__p
), _M_gd(__p
.k(), (1.0 - __p
.p()) / __p
.p())
4253 * @brief Resets the distribution state.
4260 * @brief Return the @f$k@f$ parameter of the distribution.
4264 { return _M_param
.k(); }
4267 * @brief Return the @f$p@f$ parameter of the distribution.
4271 { return _M_param
.p(); }
4274 * @brief Returns the parameter set of the distribution.
4278 { return _M_param
; }
4281 * @brief Sets the parameter set of the distribution.
4282 * @param __param The new parameter set of the distribution.
4285 param(const param_type
& __param
)
4286 { _M_param
= __param
; }
4289 * @brief Returns the greatest lower bound value of the distribution.
4293 { return result_type(0); }
4296 * @brief Returns the least upper bound value of the distribution.
4300 { return std::numeric_limits
<result_type
>::max(); }
4303 * @brief Generating functions.
4305 template<typename _UniformRandomNumberGenerator
>
4307 operator()(_UniformRandomNumberGenerator
& __urng
);
4309 template<typename _UniformRandomNumberGenerator
>
4311 operator()(_UniformRandomNumberGenerator
& __urng
,
4312 const param_type
& __p
);
4314 template<typename _ForwardIterator
,
4315 typename _UniformRandomNumberGenerator
>
4317 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4318 _UniformRandomNumberGenerator
& __urng
)
4319 { this->__generate_impl(__f
, __t
, __urng
); }
4321 template<typename _ForwardIterator
,
4322 typename _UniformRandomNumberGenerator
>
4324 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4325 _UniformRandomNumberGenerator
& __urng
,
4326 const param_type
& __p
)
4327 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4329 template<typename _UniformRandomNumberGenerator
>
4331 __generate(result_type
* __f
, result_type
* __t
,
4332 _UniformRandomNumberGenerator
& __urng
)
4333 { this->__generate_impl(__f
, __t
, __urng
); }
4335 template<typename _UniformRandomNumberGenerator
>
4337 __generate(result_type
* __f
, result_type
* __t
,
4338 _UniformRandomNumberGenerator
& __urng
,
4339 const param_type
& __p
)
4340 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4343 * @brief Return true if two negative binomial distributions have
4344 * the same parameters and the sequences that would be
4345 * generated are equal.
4348 operator==(const negative_binomial_distribution
& __d1
,
4349 const negative_binomial_distribution
& __d2
)
4350 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
4353 * @brief Inserts a %negative_binomial_distribution random
4354 * number distribution @p __x into the output stream @p __os.
4356 * @param __os An output stream.
4357 * @param __x A %negative_binomial_distribution random number
4360 * @returns The output stream with the state of @p __x inserted or in
4363 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4364 friend std::basic_ostream
<_CharT
, _Traits
>&
4365 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4366 const std::negative_binomial_distribution
<_IntType1
>& __x
);
4369 * @brief Extracts a %negative_binomial_distribution random number
4370 * distribution @p __x from the input stream @p __is.
4372 * @param __is An input stream.
4373 * @param __x A %negative_binomial_distribution random number
4376 * @returns The input stream with @p __x extracted or in an error state.
4378 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4379 friend std::basic_istream
<_CharT
, _Traits
>&
4380 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4381 std::negative_binomial_distribution
<_IntType1
>& __x
);
4384 template<typename _ForwardIterator
,
4385 typename _UniformRandomNumberGenerator
>
4387 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4388 _UniformRandomNumberGenerator
& __urng
);
4389 template<typename _ForwardIterator
,
4390 typename _UniformRandomNumberGenerator
>
4392 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4393 _UniformRandomNumberGenerator
& __urng
,
4394 const param_type
& __p
);
4396 param_type _M_param
;
4398 std::gamma_distribution
<double> _M_gd
;
4402 * @brief Return true if two negative binomial distributions are different.
4404 template<typename _IntType
>
4406 operator!=(const std::negative_binomial_distribution
<_IntType
>& __d1
,
4407 const std::negative_binomial_distribution
<_IntType
>& __d2
)
4408 { return !(__d1
== __d2
); }
4411 /* @} */ // group random_distributions_bernoulli
4414 * @addtogroup random_distributions_poisson Poisson Distributions
4415 * @ingroup random_distributions
4420 * @brief A discrete Poisson random number distribution.
4422 * The formula for the Poisson probability density function is
4423 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4424 * parameter of the distribution.
4426 template<typename _IntType
= int>
4427 class poisson_distribution
4429 static_assert(std::is_integral
<_IntType
>::value
,
4430 "template argument not an integral type");
4433 /** The type of the range of the distribution. */
4434 typedef _IntType result_type
;
4435 /** Parameter type. */
4438 typedef poisson_distribution
<_IntType
> distribution_type
;
4439 friend class poisson_distribution
<_IntType
>;
4442 param_type(double __mean
= 1.0)
4445 _GLIBCXX_DEBUG_ASSERT(_M_mean
> 0.0);
4454 operator==(const param_type
& __p1
, const param_type
& __p2
)
4455 { return __p1
._M_mean
== __p2
._M_mean
; }
4458 // Hosts either log(mean) or the threshold of the simple method.
4465 #if _GLIBCXX_USE_C99_MATH_TR1
4466 double _M_lfm
, _M_sm
, _M_d
, _M_scx
, _M_1cx
, _M_c2b
, _M_cb
;
4470 // constructors and member function
4472 poisson_distribution(double __mean
= 1.0)
4473 : _M_param(__mean
), _M_nd()
4477 poisson_distribution(const param_type
& __p
)
4478 : _M_param(__p
), _M_nd()
4482 * @brief Resets the distribution state.
4489 * @brief Returns the distribution parameter @p mean.
4493 { return _M_param
.mean(); }
4496 * @brief Returns the parameter set of the distribution.
4500 { return _M_param
; }
4503 * @brief Sets the parameter set of the distribution.
4504 * @param __param The new parameter set of the distribution.
4507 param(const param_type
& __param
)
4508 { _M_param
= __param
; }
4511 * @brief Returns the greatest lower bound value of the distribution.
4518 * @brief Returns the least upper bound value of the distribution.
4522 { return std::numeric_limits
<result_type
>::max(); }
4525 * @brief Generating functions.
4527 template<typename _UniformRandomNumberGenerator
>
4529 operator()(_UniformRandomNumberGenerator
& __urng
)
4530 { return this->operator()(__urng
, _M_param
); }
4532 template<typename _UniformRandomNumberGenerator
>
4534 operator()(_UniformRandomNumberGenerator
& __urng
,
4535 const param_type
& __p
);
4537 template<typename _ForwardIterator
,
4538 typename _UniformRandomNumberGenerator
>
4540 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4541 _UniformRandomNumberGenerator
& __urng
)
4542 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4544 template<typename _ForwardIterator
,
4545 typename _UniformRandomNumberGenerator
>
4547 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4548 _UniformRandomNumberGenerator
& __urng
,
4549 const param_type
& __p
)
4550 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4552 template<typename _UniformRandomNumberGenerator
>
4554 __generate(result_type
* __f
, result_type
* __t
,
4555 _UniformRandomNumberGenerator
& __urng
,
4556 const param_type
& __p
)
4557 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4560 * @brief Return true if two Poisson distributions have the same
4561 * parameters and the sequences that would be generated
4565 operator==(const poisson_distribution
& __d1
,
4566 const poisson_distribution
& __d2
)
4567 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4568 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
4570 { return __d1
._M_param
== __d2
._M_param
; }
4574 * @brief Inserts a %poisson_distribution random number distribution
4575 * @p __x into the output stream @p __os.
4577 * @param __os An output stream.
4578 * @param __x A %poisson_distribution random number distribution.
4580 * @returns The output stream with the state of @p __x inserted or in
4583 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4584 friend std::basic_ostream
<_CharT
, _Traits
>&
4585 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4586 const std::poisson_distribution
<_IntType1
>& __x
);
4589 * @brief Extracts a %poisson_distribution random number distribution
4590 * @p __x from the input stream @p __is.
4592 * @param __is An input stream.
4593 * @param __x A %poisson_distribution random number generator engine.
4595 * @returns The input stream with @p __x extracted or in an error
4598 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4599 friend std::basic_istream
<_CharT
, _Traits
>&
4600 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4601 std::poisson_distribution
<_IntType1
>& __x
);
4604 template<typename _ForwardIterator
,
4605 typename _UniformRandomNumberGenerator
>
4607 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4608 _UniformRandomNumberGenerator
& __urng
,
4609 const param_type
& __p
);
4611 param_type _M_param
;
4613 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4614 std::normal_distribution
<double> _M_nd
;
4618 * @brief Return true if two Poisson distributions are different.
4620 template<typename _IntType
>
4622 operator!=(const std::poisson_distribution
<_IntType
>& __d1
,
4623 const std::poisson_distribution
<_IntType
>& __d2
)
4624 { return !(__d1
== __d2
); }
4628 * @brief An exponential continuous distribution for random numbers.
4630 * The formula for the exponential probability density function is
4631 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4633 * <table border=1 cellpadding=10 cellspacing=0>
4634 * <caption align=top>Distribution Statistics</caption>
4635 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4636 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4637 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4638 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4639 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4642 template<typename _RealType
= double>
4643 class exponential_distribution
4645 static_assert(std::is_floating_point
<_RealType
>::value
,
4646 "template argument not a floating point type");
4649 /** The type of the range of the distribution. */
4650 typedef _RealType result_type
;
4651 /** Parameter type. */
4654 typedef exponential_distribution
<_RealType
> distribution_type
;
4657 param_type(_RealType __lambda
= _RealType(1))
4658 : _M_lambda(__lambda
)
4660 _GLIBCXX_DEBUG_ASSERT(_M_lambda
> _RealType(0));
4665 { return _M_lambda
; }
4668 operator==(const param_type
& __p1
, const param_type
& __p2
)
4669 { return __p1
._M_lambda
== __p2
._M_lambda
; }
4672 _RealType _M_lambda
;
4677 * @brief Constructs an exponential distribution with inverse scale
4678 * parameter @f$\lambda@f$.
4681 exponential_distribution(const result_type
& __lambda
= result_type(1))
4682 : _M_param(__lambda
)
4686 exponential_distribution(const param_type
& __p
)
4691 * @brief Resets the distribution state.
4693 * Has no effect on exponential distributions.
4699 * @brief Returns the inverse scale parameter of the distribution.
4703 { return _M_param
.lambda(); }
4706 * @brief Returns the parameter set of the distribution.
4710 { return _M_param
; }
4713 * @brief Sets the parameter set of the distribution.
4714 * @param __param The new parameter set of the distribution.
4717 param(const param_type
& __param
)
4718 { _M_param
= __param
; }
4721 * @brief Returns the greatest lower bound value of the distribution.
4725 { return result_type(0); }
4728 * @brief Returns the least upper bound value of the distribution.
4732 { return std::numeric_limits
<result_type
>::max(); }
4735 * @brief Generating functions.
4737 template<typename _UniformRandomNumberGenerator
>
4739 operator()(_UniformRandomNumberGenerator
& __urng
)
4740 { return this->operator()(__urng
, _M_param
); }
4742 template<typename _UniformRandomNumberGenerator
>
4744 operator()(_UniformRandomNumberGenerator
& __urng
,
4745 const param_type
& __p
)
4747 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
4749 return -std::log(result_type(1) - __aurng()) / __p
.lambda();
4752 template<typename _ForwardIterator
,
4753 typename _UniformRandomNumberGenerator
>
4755 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4756 _UniformRandomNumberGenerator
& __urng
)
4757 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4759 template<typename _ForwardIterator
,
4760 typename _UniformRandomNumberGenerator
>
4762 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4763 _UniformRandomNumberGenerator
& __urng
,
4764 const param_type
& __p
)
4765 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4767 template<typename _UniformRandomNumberGenerator
>
4769 __generate(result_type
* __f
, result_type
* __t
,
4770 _UniformRandomNumberGenerator
& __urng
,
4771 const param_type
& __p
)
4772 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4775 * @brief Return true if two exponential distributions have the same
4779 operator==(const exponential_distribution
& __d1
,
4780 const exponential_distribution
& __d2
)
4781 { return __d1
._M_param
== __d2
._M_param
; }
4784 template<typename _ForwardIterator
,
4785 typename _UniformRandomNumberGenerator
>
4787 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4788 _UniformRandomNumberGenerator
& __urng
,
4789 const param_type
& __p
);
4791 param_type _M_param
;
4795 * @brief Return true if two exponential distributions have different
4798 template<typename _RealType
>
4800 operator!=(const std::exponential_distribution
<_RealType
>& __d1
,
4801 const std::exponential_distribution
<_RealType
>& __d2
)
4802 { return !(__d1
== __d2
); }
4805 * @brief Inserts a %exponential_distribution random number distribution
4806 * @p __x into the output stream @p __os.
4808 * @param __os An output stream.
4809 * @param __x A %exponential_distribution random number distribution.
4811 * @returns The output stream with the state of @p __x inserted or in
4814 template<typename _RealType
, typename _CharT
, typename _Traits
>
4815 std::basic_ostream
<_CharT
, _Traits
>&
4816 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4817 const std::exponential_distribution
<_RealType
>& __x
);
4820 * @brief Extracts a %exponential_distribution random number distribution
4821 * @p __x from the input stream @p __is.
4823 * @param __is An input stream.
4824 * @param __x A %exponential_distribution random number
4827 * @returns The input stream with @p __x extracted or in an error state.
4829 template<typename _RealType
, typename _CharT
, typename _Traits
>
4830 std::basic_istream
<_CharT
, _Traits
>&
4831 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4832 std::exponential_distribution
<_RealType
>& __x
);
4836 * @brief A weibull_distribution random number distribution.
4838 * The formula for the normal probability density function is:
4840 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4841 * \exp{(-(\frac{x}{\beta})^\alpha)}
4844 template<typename _RealType
= double>
4845 class weibull_distribution
4847 static_assert(std::is_floating_point
<_RealType
>::value
,
4848 "template argument not a floating point type");
4851 /** The type of the range of the distribution. */
4852 typedef _RealType result_type
;
4853 /** Parameter type. */
4856 typedef weibull_distribution
<_RealType
> distribution_type
;
4859 param_type(_RealType __a
= _RealType(1),
4860 _RealType __b
= _RealType(1))
4861 : _M_a(__a
), _M_b(__b
)
4873 operator==(const param_type
& __p1
, const param_type
& __p2
)
4874 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
4882 weibull_distribution(_RealType __a
= _RealType(1),
4883 _RealType __b
= _RealType(1))
4884 : _M_param(__a
, __b
)
4888 weibull_distribution(const param_type
& __p
)
4893 * @brief Resets the distribution state.
4900 * @brief Return the @f$a@f$ parameter of the distribution.
4904 { return _M_param
.a(); }
4907 * @brief Return the @f$b@f$ parameter of the distribution.
4911 { return _M_param
.b(); }
4914 * @brief Returns the parameter set of the distribution.
4918 { return _M_param
; }
4921 * @brief Sets the parameter set of the distribution.
4922 * @param __param The new parameter set of the distribution.
4925 param(const param_type
& __param
)
4926 { _M_param
= __param
; }
4929 * @brief Returns the greatest lower bound value of the distribution.
4933 { return result_type(0); }
4936 * @brief Returns the least upper bound value of the distribution.
4940 { return std::numeric_limits
<result_type
>::max(); }
4943 * @brief Generating functions.
4945 template<typename _UniformRandomNumberGenerator
>
4947 operator()(_UniformRandomNumberGenerator
& __urng
)
4948 { return this->operator()(__urng
, _M_param
); }
4950 template<typename _UniformRandomNumberGenerator
>
4952 operator()(_UniformRandomNumberGenerator
& __urng
,
4953 const param_type
& __p
);
4955 template<typename _ForwardIterator
,
4956 typename _UniformRandomNumberGenerator
>
4958 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4959 _UniformRandomNumberGenerator
& __urng
)
4960 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4962 template<typename _ForwardIterator
,
4963 typename _UniformRandomNumberGenerator
>
4965 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4966 _UniformRandomNumberGenerator
& __urng
,
4967 const param_type
& __p
)
4968 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4970 template<typename _UniformRandomNumberGenerator
>
4972 __generate(result_type
* __f
, result_type
* __t
,
4973 _UniformRandomNumberGenerator
& __urng
,
4974 const param_type
& __p
)
4975 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4978 * @brief Return true if two Weibull distributions have the same
4982 operator==(const weibull_distribution
& __d1
,
4983 const weibull_distribution
& __d2
)
4984 { return __d1
._M_param
== __d2
._M_param
; }
4987 template<typename _ForwardIterator
,
4988 typename _UniformRandomNumberGenerator
>
4990 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4991 _UniformRandomNumberGenerator
& __urng
,
4992 const param_type
& __p
);
4994 param_type _M_param
;
4998 * @brief Return true if two Weibull distributions have different
5001 template<typename _RealType
>
5003 operator!=(const std::weibull_distribution
<_RealType
>& __d1
,
5004 const std::weibull_distribution
<_RealType
>& __d2
)
5005 { return !(__d1
== __d2
); }
5008 * @brief Inserts a %weibull_distribution random number distribution
5009 * @p __x into the output stream @p __os.
5011 * @param __os An output stream.
5012 * @param __x A %weibull_distribution random number distribution.
5014 * @returns The output stream with the state of @p __x inserted or in
5017 template<typename _RealType
, typename _CharT
, typename _Traits
>
5018 std::basic_ostream
<_CharT
, _Traits
>&
5019 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5020 const std::weibull_distribution
<_RealType
>& __x
);
5023 * @brief Extracts a %weibull_distribution random number distribution
5024 * @p __x from the input stream @p __is.
5026 * @param __is An input stream.
5027 * @param __x A %weibull_distribution random number
5030 * @returns The input stream with @p __x extracted or in an error state.
5032 template<typename _RealType
, typename _CharT
, typename _Traits
>
5033 std::basic_istream
<_CharT
, _Traits
>&
5034 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5035 std::weibull_distribution
<_RealType
>& __x
);
5039 * @brief A extreme_value_distribution random number distribution.
5041 * The formula for the normal probability mass function is
5043 * p(x|a,b) = \frac{1}{b}
5044 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5047 template<typename _RealType
= double>
5048 class extreme_value_distribution
5050 static_assert(std::is_floating_point
<_RealType
>::value
,
5051 "template argument not a floating point type");
5054 /** The type of the range of the distribution. */
5055 typedef _RealType result_type
;
5056 /** Parameter type. */
5059 typedef extreme_value_distribution
<_RealType
> distribution_type
;
5062 param_type(_RealType __a
= _RealType(0),
5063 _RealType __b
= _RealType(1))
5064 : _M_a(__a
), _M_b(__b
)
5076 operator==(const param_type
& __p1
, const param_type
& __p2
)
5077 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
5085 extreme_value_distribution(_RealType __a
= _RealType(0),
5086 _RealType __b
= _RealType(1))
5087 : _M_param(__a
, __b
)
5091 extreme_value_distribution(const param_type
& __p
)
5096 * @brief Resets the distribution state.
5103 * @brief Return the @f$a@f$ parameter of the distribution.
5107 { return _M_param
.a(); }
5110 * @brief Return the @f$b@f$ parameter of the distribution.
5114 { return _M_param
.b(); }
5117 * @brief Returns the parameter set of the distribution.
5121 { return _M_param
; }
5124 * @brief Sets the parameter set of the distribution.
5125 * @param __param The new parameter set of the distribution.
5128 param(const param_type
& __param
)
5129 { _M_param
= __param
; }
5132 * @brief Returns the greatest lower bound value of the distribution.
5136 { return std::numeric_limits
<result_type
>::lowest(); }
5139 * @brief Returns the least upper bound value of the distribution.
5143 { return std::numeric_limits
<result_type
>::max(); }
5146 * @brief Generating functions.
5148 template<typename _UniformRandomNumberGenerator
>
5150 operator()(_UniformRandomNumberGenerator
& __urng
)
5151 { return this->operator()(__urng
, _M_param
); }
5153 template<typename _UniformRandomNumberGenerator
>
5155 operator()(_UniformRandomNumberGenerator
& __urng
,
5156 const param_type
& __p
);
5158 template<typename _ForwardIterator
,
5159 typename _UniformRandomNumberGenerator
>
5161 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5162 _UniformRandomNumberGenerator
& __urng
)
5163 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5165 template<typename _ForwardIterator
,
5166 typename _UniformRandomNumberGenerator
>
5168 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5169 _UniformRandomNumberGenerator
& __urng
,
5170 const param_type
& __p
)
5171 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5173 template<typename _UniformRandomNumberGenerator
>
5175 __generate(result_type
* __f
, result_type
* __t
,
5176 _UniformRandomNumberGenerator
& __urng
,
5177 const param_type
& __p
)
5178 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5181 * @brief Return true if two extreme value distributions have the same
5185 operator==(const extreme_value_distribution
& __d1
,
5186 const extreme_value_distribution
& __d2
)
5187 { return __d1
._M_param
== __d2
._M_param
; }
5190 template<typename _ForwardIterator
,
5191 typename _UniformRandomNumberGenerator
>
5193 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5194 _UniformRandomNumberGenerator
& __urng
,
5195 const param_type
& __p
);
5197 param_type _M_param
;
5201 * @brief Return true if two extreme value distributions have different
5204 template<typename _RealType
>
5206 operator!=(const std::extreme_value_distribution
<_RealType
>& __d1
,
5207 const std::extreme_value_distribution
<_RealType
>& __d2
)
5208 { return !(__d1
== __d2
); }
5211 * @brief Inserts a %extreme_value_distribution random number distribution
5212 * @p __x into the output stream @p __os.
5214 * @param __os An output stream.
5215 * @param __x A %extreme_value_distribution random number distribution.
5217 * @returns The output stream with the state of @p __x inserted or in
5220 template<typename _RealType
, typename _CharT
, typename _Traits
>
5221 std::basic_ostream
<_CharT
, _Traits
>&
5222 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5223 const std::extreme_value_distribution
<_RealType
>& __x
);
5226 * @brief Extracts a %extreme_value_distribution random number
5227 * distribution @p __x from the input stream @p __is.
5229 * @param __is An input stream.
5230 * @param __x A %extreme_value_distribution random number
5233 * @returns The input stream with @p __x extracted or in an error state.
5235 template<typename _RealType
, typename _CharT
, typename _Traits
>
5236 std::basic_istream
<_CharT
, _Traits
>&
5237 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5238 std::extreme_value_distribution
<_RealType
>& __x
);
5242 * @brief A discrete_distribution random number distribution.
5244 * The formula for the discrete probability mass function is
5247 template<typename _IntType
= int>
5248 class discrete_distribution
5250 static_assert(std::is_integral
<_IntType
>::value
,
5251 "template argument not an integral type");
5254 /** The type of the range of the distribution. */
5255 typedef _IntType result_type
;
5256 /** Parameter type. */
5259 typedef discrete_distribution
<_IntType
> distribution_type
;
5260 friend class discrete_distribution
<_IntType
>;
5263 : _M_prob(), _M_cp()
5266 template<typename _InputIterator
>
5267 param_type(_InputIterator __wbegin
,
5268 _InputIterator __wend
)
5269 : _M_prob(__wbegin
, __wend
), _M_cp()
5270 { _M_initialize(); }
5272 param_type(initializer_list
<double> __wil
)
5273 : _M_prob(__wil
.begin(), __wil
.end()), _M_cp()
5274 { _M_initialize(); }
5276 template<typename _Func
>
5277 param_type(size_t __nw
, double __xmin
, double __xmax
,
5280 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5281 param_type(const param_type
&) = default;
5282 param_type
& operator=(const param_type
&) = default;
5285 probabilities() const
5286 { return _M_prob
.empty() ? std::vector
<double>(1, 1.0) : _M_prob
; }
5289 operator==(const param_type
& __p1
, const param_type
& __p2
)
5290 { return __p1
._M_prob
== __p2
._M_prob
; }
5296 std::vector
<double> _M_prob
;
5297 std::vector
<double> _M_cp
;
5300 discrete_distribution()
5304 template<typename _InputIterator
>
5305 discrete_distribution(_InputIterator __wbegin
,
5306 _InputIterator __wend
)
5307 : _M_param(__wbegin
, __wend
)
5310 discrete_distribution(initializer_list
<double> __wl
)
5314 template<typename _Func
>
5315 discrete_distribution(size_t __nw
, double __xmin
, double __xmax
,
5317 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5321 discrete_distribution(const param_type
& __p
)
5326 * @brief Resets the distribution state.
5333 * @brief Returns the probabilities of the distribution.
5336 probabilities() const
5338 return _M_param
._M_prob
.empty()
5339 ? std::vector
<double>(1, 1.0) : _M_param
._M_prob
;
5343 * @brief Returns the parameter set of the distribution.
5347 { return _M_param
; }
5350 * @brief Sets the parameter set of the distribution.
5351 * @param __param The new parameter set of the distribution.
5354 param(const param_type
& __param
)
5355 { _M_param
= __param
; }
5358 * @brief Returns the greatest lower bound value of the distribution.
5362 { return result_type(0); }
5365 * @brief Returns the least upper bound value of the distribution.
5370 return _M_param
._M_prob
.empty()
5371 ? result_type(0) : result_type(_M_param
._M_prob
.size() - 1);
5375 * @brief Generating functions.
5377 template<typename _UniformRandomNumberGenerator
>
5379 operator()(_UniformRandomNumberGenerator
& __urng
)
5380 { return this->operator()(__urng
, _M_param
); }
5382 template<typename _UniformRandomNumberGenerator
>
5384 operator()(_UniformRandomNumberGenerator
& __urng
,
5385 const param_type
& __p
);
5387 template<typename _ForwardIterator
,
5388 typename _UniformRandomNumberGenerator
>
5390 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5391 _UniformRandomNumberGenerator
& __urng
)
5392 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5394 template<typename _ForwardIterator
,
5395 typename _UniformRandomNumberGenerator
>
5397 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5398 _UniformRandomNumberGenerator
& __urng
,
5399 const param_type
& __p
)
5400 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5402 template<typename _UniformRandomNumberGenerator
>
5404 __generate(result_type
* __f
, result_type
* __t
,
5405 _UniformRandomNumberGenerator
& __urng
,
5406 const param_type
& __p
)
5407 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5410 * @brief Return true if two discrete distributions have the same
5414 operator==(const discrete_distribution
& __d1
,
5415 const discrete_distribution
& __d2
)
5416 { return __d1
._M_param
== __d2
._M_param
; }
5419 * @brief Inserts a %discrete_distribution random number distribution
5420 * @p __x into the output stream @p __os.
5422 * @param __os An output stream.
5423 * @param __x A %discrete_distribution random number distribution.
5425 * @returns The output stream with the state of @p __x inserted or in
5428 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5429 friend std::basic_ostream
<_CharT
, _Traits
>&
5430 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5431 const std::discrete_distribution
<_IntType1
>& __x
);
5434 * @brief Extracts a %discrete_distribution random number distribution
5435 * @p __x from the input stream @p __is.
5437 * @param __is An input stream.
5438 * @param __x A %discrete_distribution random number
5441 * @returns The input stream with @p __x extracted or in an error
5444 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5445 friend std::basic_istream
<_CharT
, _Traits
>&
5446 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5447 std::discrete_distribution
<_IntType1
>& __x
);
5450 template<typename _ForwardIterator
,
5451 typename _UniformRandomNumberGenerator
>
5453 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5454 _UniformRandomNumberGenerator
& __urng
,
5455 const param_type
& __p
);
5457 param_type _M_param
;
5461 * @brief Return true if two discrete distributions have different
5464 template<typename _IntType
>
5466 operator!=(const std::discrete_distribution
<_IntType
>& __d1
,
5467 const std::discrete_distribution
<_IntType
>& __d2
)
5468 { return !(__d1
== __d2
); }
5472 * @brief A piecewise_constant_distribution random number distribution.
5474 * The formula for the piecewise constant probability mass function is
5477 template<typename _RealType
= double>
5478 class piecewise_constant_distribution
5480 static_assert(std::is_floating_point
<_RealType
>::value
,
5481 "template argument not a floating point type");
5484 /** The type of the range of the distribution. */
5485 typedef _RealType result_type
;
5486 /** Parameter type. */
5489 typedef piecewise_constant_distribution
<_RealType
> distribution_type
;
5490 friend class piecewise_constant_distribution
<_RealType
>;
5493 : _M_int(), _M_den(), _M_cp()
5496 template<typename _InputIteratorB
, typename _InputIteratorW
>
5497 param_type(_InputIteratorB __bfirst
,
5498 _InputIteratorB __bend
,
5499 _InputIteratorW __wbegin
);
5501 template<typename _Func
>
5502 param_type(initializer_list
<_RealType
> __bi
, _Func __fw
);
5504 template<typename _Func
>
5505 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5508 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5509 param_type(const param_type
&) = default;
5510 param_type
& operator=(const param_type
&) = default;
5512 std::vector
<_RealType
>
5517 std::vector
<_RealType
> __tmp(2);
5518 __tmp
[1] = _RealType(1);
5527 { return _M_den
.empty() ? std::vector
<double>(1, 1.0) : _M_den
; }
5530 operator==(const param_type
& __p1
, const param_type
& __p2
)
5531 { return __p1
._M_int
== __p2
._M_int
&& __p1
._M_den
== __p2
._M_den
; }
5537 std::vector
<_RealType
> _M_int
;
5538 std::vector
<double> _M_den
;
5539 std::vector
<double> _M_cp
;
5543 piecewise_constant_distribution()
5547 template<typename _InputIteratorB
, typename _InputIteratorW
>
5548 piecewise_constant_distribution(_InputIteratorB __bfirst
,
5549 _InputIteratorB __bend
,
5550 _InputIteratorW __wbegin
)
5551 : _M_param(__bfirst
, __bend
, __wbegin
)
5554 template<typename _Func
>
5555 piecewise_constant_distribution(initializer_list
<_RealType
> __bl
,
5557 : _M_param(__bl
, __fw
)
5560 template<typename _Func
>
5561 piecewise_constant_distribution(size_t __nw
,
5562 _RealType __xmin
, _RealType __xmax
,
5564 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5568 piecewise_constant_distribution(const param_type
& __p
)
5573 * @brief Resets the distribution state.
5580 * @brief Returns a vector of the intervals.
5582 std::vector
<_RealType
>
5585 if (_M_param
._M_int
.empty())
5587 std::vector
<_RealType
> __tmp(2);
5588 __tmp
[1] = _RealType(1);
5592 return _M_param
._M_int
;
5596 * @brief Returns a vector of the probability densities.
5601 return _M_param
._M_den
.empty()
5602 ? std::vector
<double>(1, 1.0) : _M_param
._M_den
;
5606 * @brief Returns the parameter set of the distribution.
5610 { return _M_param
; }
5613 * @brief Sets the parameter set of the distribution.
5614 * @param __param The new parameter set of the distribution.
5617 param(const param_type
& __param
)
5618 { _M_param
= __param
; }
5621 * @brief Returns the greatest lower bound value of the distribution.
5626 return _M_param
._M_int
.empty()
5627 ? result_type(0) : _M_param
._M_int
.front();
5631 * @brief Returns the least upper bound value of the distribution.
5636 return _M_param
._M_int
.empty()
5637 ? result_type(1) : _M_param
._M_int
.back();
5641 * @brief Generating functions.
5643 template<typename _UniformRandomNumberGenerator
>
5645 operator()(_UniformRandomNumberGenerator
& __urng
)
5646 { return this->operator()(__urng
, _M_param
); }
5648 template<typename _UniformRandomNumberGenerator
>
5650 operator()(_UniformRandomNumberGenerator
& __urng
,
5651 const param_type
& __p
);
5653 template<typename _ForwardIterator
,
5654 typename _UniformRandomNumberGenerator
>
5656 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5657 _UniformRandomNumberGenerator
& __urng
)
5658 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5660 template<typename _ForwardIterator
,
5661 typename _UniformRandomNumberGenerator
>
5663 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5664 _UniformRandomNumberGenerator
& __urng
,
5665 const param_type
& __p
)
5666 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5668 template<typename _UniformRandomNumberGenerator
>
5670 __generate(result_type
* __f
, result_type
* __t
,
5671 _UniformRandomNumberGenerator
& __urng
,
5672 const param_type
& __p
)
5673 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5676 * @brief Return true if two piecewise constant distributions have the
5680 operator==(const piecewise_constant_distribution
& __d1
,
5681 const piecewise_constant_distribution
& __d2
)
5682 { return __d1
._M_param
== __d2
._M_param
; }
5685 * @brief Inserts a %piecewise_constant_distribution random
5686 * number distribution @p __x into the output stream @p __os.
5688 * @param __os An output stream.
5689 * @param __x A %piecewise_constant_distribution random number
5692 * @returns The output stream with the state of @p __x inserted or in
5695 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5696 friend std::basic_ostream
<_CharT
, _Traits
>&
5697 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5698 const std::piecewise_constant_distribution
<_RealType1
>& __x
);
5701 * @brief Extracts a %piecewise_constant_distribution random
5702 * number distribution @p __x from the input stream @p __is.
5704 * @param __is An input stream.
5705 * @param __x A %piecewise_constant_distribution random number
5708 * @returns The input stream with @p __x extracted or in an error
5711 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5712 friend std::basic_istream
<_CharT
, _Traits
>&
5713 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5714 std::piecewise_constant_distribution
<_RealType1
>& __x
);
5717 template<typename _ForwardIterator
,
5718 typename _UniformRandomNumberGenerator
>
5720 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5721 _UniformRandomNumberGenerator
& __urng
,
5722 const param_type
& __p
);
5724 param_type _M_param
;
5728 * @brief Return true if two piecewise constant distributions have
5729 * different parameters.
5731 template<typename _RealType
>
5733 operator!=(const std::piecewise_constant_distribution
<_RealType
>& __d1
,
5734 const std::piecewise_constant_distribution
<_RealType
>& __d2
)
5735 { return !(__d1
== __d2
); }
5739 * @brief A piecewise_linear_distribution random number distribution.
5741 * The formula for the piecewise linear probability mass function is
5744 template<typename _RealType
= double>
5745 class piecewise_linear_distribution
5747 static_assert(std::is_floating_point
<_RealType
>::value
,
5748 "template argument not a floating point type");
5751 /** The type of the range of the distribution. */
5752 typedef _RealType result_type
;
5753 /** Parameter type. */
5756 typedef piecewise_linear_distribution
<_RealType
> distribution_type
;
5757 friend class piecewise_linear_distribution
<_RealType
>;
5760 : _M_int(), _M_den(), _M_cp(), _M_m()
5763 template<typename _InputIteratorB
, typename _InputIteratorW
>
5764 param_type(_InputIteratorB __bfirst
,
5765 _InputIteratorB __bend
,
5766 _InputIteratorW __wbegin
);
5768 template<typename _Func
>
5769 param_type(initializer_list
<_RealType
> __bl
, _Func __fw
);
5771 template<typename _Func
>
5772 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5775 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5776 param_type(const param_type
&) = default;
5777 param_type
& operator=(const param_type
&) = default;
5779 std::vector
<_RealType
>
5784 std::vector
<_RealType
> __tmp(2);
5785 __tmp
[1] = _RealType(1);
5794 { return _M_den
.empty() ? std::vector
<double>(2, 1.0) : _M_den
; }
5797 operator==(const param_type
& __p1
, const param_type
& __p2
)
5798 { return (__p1
._M_int
== __p2
._M_int
5799 && __p1
._M_den
== __p2
._M_den
); }
5805 std::vector
<_RealType
> _M_int
;
5806 std::vector
<double> _M_den
;
5807 std::vector
<double> _M_cp
;
5808 std::vector
<double> _M_m
;
5812 piecewise_linear_distribution()
5816 template<typename _InputIteratorB
, typename _InputIteratorW
>
5817 piecewise_linear_distribution(_InputIteratorB __bfirst
,
5818 _InputIteratorB __bend
,
5819 _InputIteratorW __wbegin
)
5820 : _M_param(__bfirst
, __bend
, __wbegin
)
5823 template<typename _Func
>
5824 piecewise_linear_distribution(initializer_list
<_RealType
> __bl
,
5826 : _M_param(__bl
, __fw
)
5829 template<typename _Func
>
5830 piecewise_linear_distribution(size_t __nw
,
5831 _RealType __xmin
, _RealType __xmax
,
5833 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5837 piecewise_linear_distribution(const param_type
& __p
)
5842 * Resets the distribution state.
5849 * @brief Return the intervals of the distribution.
5851 std::vector
<_RealType
>
5854 if (_M_param
._M_int
.empty())
5856 std::vector
<_RealType
> __tmp(2);
5857 __tmp
[1] = _RealType(1);
5861 return _M_param
._M_int
;
5865 * @brief Return a vector of the probability densities of the
5871 return _M_param
._M_den
.empty()
5872 ? std::vector
<double>(2, 1.0) : _M_param
._M_den
;
5876 * @brief Returns the parameter set of the distribution.
5880 { return _M_param
; }
5883 * @brief Sets the parameter set of the distribution.
5884 * @param __param The new parameter set of the distribution.
5887 param(const param_type
& __param
)
5888 { _M_param
= __param
; }
5891 * @brief Returns the greatest lower bound value of the distribution.
5896 return _M_param
._M_int
.empty()
5897 ? result_type(0) : _M_param
._M_int
.front();
5901 * @brief Returns the least upper bound value of the distribution.
5906 return _M_param
._M_int
.empty()
5907 ? result_type(1) : _M_param
._M_int
.back();
5911 * @brief Generating functions.
5913 template<typename _UniformRandomNumberGenerator
>
5915 operator()(_UniformRandomNumberGenerator
& __urng
)
5916 { return this->operator()(__urng
, _M_param
); }
5918 template<typename _UniformRandomNumberGenerator
>
5920 operator()(_UniformRandomNumberGenerator
& __urng
,
5921 const param_type
& __p
);
5923 template<typename _ForwardIterator
,
5924 typename _UniformRandomNumberGenerator
>
5926 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5927 _UniformRandomNumberGenerator
& __urng
)
5928 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5930 template<typename _ForwardIterator
,
5931 typename _UniformRandomNumberGenerator
>
5933 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5934 _UniformRandomNumberGenerator
& __urng
,
5935 const param_type
& __p
)
5936 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5938 template<typename _UniformRandomNumberGenerator
>
5940 __generate(result_type
* __f
, result_type
* __t
,
5941 _UniformRandomNumberGenerator
& __urng
,
5942 const param_type
& __p
)
5943 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5946 * @brief Return true if two piecewise linear distributions have the
5950 operator==(const piecewise_linear_distribution
& __d1
,
5951 const piecewise_linear_distribution
& __d2
)
5952 { return __d1
._M_param
== __d2
._M_param
; }
5955 * @brief Inserts a %piecewise_linear_distribution random number
5956 * distribution @p __x into the output stream @p __os.
5958 * @param __os An output stream.
5959 * @param __x A %piecewise_linear_distribution random number
5962 * @returns The output stream with the state of @p __x inserted or in
5965 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5966 friend std::basic_ostream
<_CharT
, _Traits
>&
5967 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5968 const std::piecewise_linear_distribution
<_RealType1
>& __x
);
5971 * @brief Extracts a %piecewise_linear_distribution random number
5972 * distribution @p __x from the input stream @p __is.
5974 * @param __is An input stream.
5975 * @param __x A %piecewise_linear_distribution random number
5978 * @returns The input stream with @p __x extracted or in an error
5981 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5982 friend std::basic_istream
<_CharT
, _Traits
>&
5983 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5984 std::piecewise_linear_distribution
<_RealType1
>& __x
);
5987 template<typename _ForwardIterator
,
5988 typename _UniformRandomNumberGenerator
>
5990 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5991 _UniformRandomNumberGenerator
& __urng
,
5992 const param_type
& __p
);
5994 param_type _M_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