1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2013 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 * @var _M_x The state of the generator. This is a ring buffer.
664 * @var _M_carry The carry.
665 * @var _M_p Current index of x(i - r).
667 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
668 class subtract_with_carry_engine
670 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
671 "substituting _UIntType not an unsigned integral type");
672 static_assert(0u < __s
&& __s
< __r
,
673 "template argument substituting __s out of bounds");
674 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
675 "template argument substituting __w out of bounds");
678 /** The type of the generated random value. */
679 typedef _UIntType result_type
;
682 static constexpr size_t word_size
= __w
;
683 static constexpr size_t short_lag
= __s
;
684 static constexpr size_t long_lag
= __r
;
685 static constexpr result_type default_seed
= 19780503u;
688 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
689 * random number generator.
692 subtract_with_carry_engine(result_type __sd
= default_seed
)
696 * @brief Constructs a %subtract_with_carry_engine random number engine
697 * seeded from the seed sequence @p __q.
699 * @param __q the seed sequence.
701 template<typename _Sseq
, typename
= typename
702 std::enable_if
<!std::is_same
<_Sseq
, subtract_with_carry_engine
>::value
>
705 subtract_with_carry_engine(_Sseq
& __q
)
709 * @brief Seeds the initial state @f$x_0@f$ of the random number
712 * N1688[4.19] modifies this as follows. If @p __value == 0,
713 * sets value to 19780503. In any case, with a linear
714 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
715 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
716 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
717 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
718 * set carry to 1, otherwise sets carry to 0.
721 seed(result_type __sd
= default_seed
);
724 * @brief Seeds the initial state @f$x_0@f$ of the
725 * % subtract_with_carry_engine random number generator.
727 template<typename _Sseq
>
728 typename
std::enable_if
<std::is_class
<_Sseq
>::value
>::type
732 * @brief Gets the inclusive minimum value of the range of random
733 * integers returned by this generator.
735 static constexpr result_type
740 * @brief Gets the inclusive maximum value of the range of random
741 * integers returned by this generator.
743 static constexpr result_type
745 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
748 * @brief Discard a sequence of random numbers.
751 discard(unsigned long long __z
)
753 for (; __z
!= 0ULL; --__z
)
758 * @brief Gets the next random number in the sequence.
764 * @brief Compares two % subtract_with_carry_engine random number
765 * generator objects of the same type for equality.
767 * @param __lhs A % subtract_with_carry_engine random number generator
769 * @param __rhs Another % subtract_with_carry_engine random number
772 * @returns true if the infinite sequences of generated values
773 * would be equal, false otherwise.
776 operator==(const subtract_with_carry_engine
& __lhs
,
777 const subtract_with_carry_engine
& __rhs
)
778 { return (std::equal(__lhs
._M_x
, __lhs
._M_x
+ long_lag
, __rhs
._M_x
)
779 && __lhs
._M_carry
== __rhs
._M_carry
780 && __lhs
._M_p
== __rhs
._M_p
); }
783 * @brief Inserts the current state of a % subtract_with_carry_engine
784 * random number generator engine @p __x into the output stream
787 * @param __os An output stream.
788 * @param __x A % subtract_with_carry_engine random number generator
791 * @returns The output stream with the state of @p __x inserted or in
794 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
795 typename _CharT
, typename _Traits
>
796 friend std::basic_ostream
<_CharT
, _Traits
>&
797 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
798 const std::subtract_with_carry_engine
<_UIntType1
, __w1
,
802 * @brief Extracts the current state of a % subtract_with_carry_engine
803 * random number generator engine @p __x from the input stream
806 * @param __is An input stream.
807 * @param __x A % subtract_with_carry_engine random number generator
810 * @returns The input stream with the state of @p __x extracted or in
813 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
814 typename _CharT
, typename _Traits
>
815 friend std::basic_istream
<_CharT
, _Traits
>&
816 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
817 std::subtract_with_carry_engine
<_UIntType1
, __w1
,
821 _UIntType _M_x
[long_lag
];
827 * @brief Compares two % subtract_with_carry_engine random number
828 * generator objects of the same type for inequality.
830 * @param __lhs A % subtract_with_carry_engine random number generator
832 * @param __rhs Another % subtract_with_carry_engine random number
835 * @returns true if the infinite sequences of generated values
836 * would be different, false otherwise.
838 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
840 operator!=(const std::subtract_with_carry_engine
<_UIntType
, __w
,
842 const std::subtract_with_carry_engine
<_UIntType
, __w
,
844 { return !(__lhs
== __rhs
); }
848 * Produces random numbers from some base engine by discarding blocks of
851 * 0 <= @p __r <= @p __p
853 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
854 class discard_block_engine
856 static_assert(1 <= __r
&& __r
<= __p
,
857 "template argument substituting __r out of bounds");
860 /** The type of the generated random value. */
861 typedef typename
_RandomNumberEngine::result_type result_type
;
864 static constexpr size_t block_size
= __p
;
865 static constexpr size_t used_block
= __r
;
868 * @brief Constructs a default %discard_block_engine engine.
870 * The underlying engine is default constructed as well.
872 discard_block_engine()
873 : _M_b(), _M_n(0) { }
876 * @brief Copy constructs a %discard_block_engine engine.
878 * Copies an existing base class random number generator.
879 * @param __rng An existing (base class) engine object.
882 discard_block_engine(const _RandomNumberEngine
& __rng
)
883 : _M_b(__rng
), _M_n(0) { }
886 * @brief Move constructs a %discard_block_engine engine.
888 * Copies an existing base class random number generator.
889 * @param __rng An existing (base class) engine object.
892 discard_block_engine(_RandomNumberEngine
&& __rng
)
893 : _M_b(std::move(__rng
)), _M_n(0) { }
896 * @brief Seed constructs a %discard_block_engine engine.
898 * Constructs the underlying generator engine seeded with @p __s.
899 * @param __s A seed value for the base class engine.
902 discard_block_engine(result_type __s
)
903 : _M_b(__s
), _M_n(0) { }
906 * @brief Generator construct a %discard_block_engine engine.
908 * @param __q A seed sequence.
910 template<typename _Sseq
, typename
= typename
911 std::enable_if
<!std::is_same
<_Sseq
, discard_block_engine
>::value
912 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
915 discard_block_engine(_Sseq
& __q
)
920 * @brief Reseeds the %discard_block_engine object with the default
921 * seed for the underlying base class generator engine.
931 * @brief Reseeds the %discard_block_engine object with the default
932 * seed for the underlying base class generator engine.
935 seed(result_type __s
)
942 * @brief Reseeds the %discard_block_engine object with the given seed
944 * @param __q A seed generator function.
946 template<typename _Sseq
>
955 * @brief Gets a const reference to the underlying generator engine
958 const _RandomNumberEngine
&
959 base() const noexcept
963 * @brief Gets the minimum value in the generated random number range.
965 static constexpr result_type
967 { return _RandomNumberEngine::min(); }
970 * @brief Gets the maximum value in the generated random number range.
972 static constexpr result_type
974 { return _RandomNumberEngine::max(); }
977 * @brief Discard a sequence of random numbers.
980 discard(unsigned long long __z
)
982 for (; __z
!= 0ULL; --__z
)
987 * @brief Gets the next value in the generated random number sequence.
993 * @brief Compares two %discard_block_engine random number generator
994 * objects of the same type for equality.
996 * @param __lhs A %discard_block_engine random number generator object.
997 * @param __rhs Another %discard_block_engine random number generator
1000 * @returns true if the infinite sequences of generated values
1001 * would be equal, false otherwise.
1004 operator==(const discard_block_engine
& __lhs
,
1005 const discard_block_engine
& __rhs
)
1006 { return __lhs
._M_b
== __rhs
._M_b
&& __lhs
._M_n
== __rhs
._M_n
; }
1009 * @brief Inserts the current state of a %discard_block_engine random
1010 * number generator engine @p __x into the output stream
1013 * @param __os An output stream.
1014 * @param __x A %discard_block_engine random number generator engine.
1016 * @returns The output stream with the state of @p __x inserted or in
1019 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1020 typename _CharT
, typename _Traits
>
1021 friend std::basic_ostream
<_CharT
, _Traits
>&
1022 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1023 const std::discard_block_engine
<_RandomNumberEngine1
,
1027 * @brief Extracts the current state of a % subtract_with_carry_engine
1028 * random number generator engine @p __x from the input stream
1031 * @param __is An input stream.
1032 * @param __x A %discard_block_engine random number generator engine.
1034 * @returns The input stream with the state of @p __x extracted or in
1037 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
1038 typename _CharT
, typename _Traits
>
1039 friend std::basic_istream
<_CharT
, _Traits
>&
1040 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1041 std::discard_block_engine
<_RandomNumberEngine1
,
1045 _RandomNumberEngine _M_b
;
1050 * @brief Compares two %discard_block_engine random number generator
1051 * objects of the same type for inequality.
1053 * @param __lhs A %discard_block_engine random number generator object.
1054 * @param __rhs Another %discard_block_engine random number generator
1057 * @returns true if the infinite sequences of generated values
1058 * would be different, false otherwise.
1060 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
1062 operator!=(const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1064 const std::discard_block_engine
<_RandomNumberEngine
, __p
,
1066 { return !(__lhs
== __rhs
); }
1070 * Produces random numbers by combining random numbers from some base
1071 * engine to produce random numbers with a specifies number of bits @p __w.
1073 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1074 class independent_bits_engine
1076 static_assert(std::is_unsigned
<_UIntType
>::value
, "template argument "
1077 "substituting _UIntType not an unsigned integral type");
1078 static_assert(0u < __w
&& __w
<= std::numeric_limits
<_UIntType
>::digits
,
1079 "template argument substituting __w out of bounds");
1082 /** The type of the generated random value. */
1083 typedef _UIntType result_type
;
1086 * @brief Constructs a default %independent_bits_engine engine.
1088 * The underlying engine is default constructed as well.
1090 independent_bits_engine()
1094 * @brief Copy constructs a %independent_bits_engine engine.
1096 * Copies an existing base class random number generator.
1097 * @param __rng An existing (base class) engine object.
1100 independent_bits_engine(const _RandomNumberEngine
& __rng
)
1104 * @brief Move constructs a %independent_bits_engine engine.
1106 * Copies an existing base class random number generator.
1107 * @param __rng An existing (base class) engine object.
1110 independent_bits_engine(_RandomNumberEngine
&& __rng
)
1111 : _M_b(std::move(__rng
)) { }
1114 * @brief Seed constructs a %independent_bits_engine engine.
1116 * Constructs the underlying generator engine seeded with @p __s.
1117 * @param __s A seed value for the base class engine.
1120 independent_bits_engine(result_type __s
)
1124 * @brief Generator construct a %independent_bits_engine engine.
1126 * @param __q A seed sequence.
1128 template<typename _Sseq
, typename
= typename
1129 std::enable_if
<!std::is_same
<_Sseq
, independent_bits_engine
>::value
1130 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1133 independent_bits_engine(_Sseq
& __q
)
1138 * @brief Reseeds the %independent_bits_engine object with the default
1139 * seed for the underlying base class generator engine.
1146 * @brief Reseeds the %independent_bits_engine object with the default
1147 * seed for the underlying base class generator engine.
1150 seed(result_type __s
)
1154 * @brief Reseeds the %independent_bits_engine object with the given
1156 * @param __q A seed generator function.
1158 template<typename _Sseq
>
1164 * @brief Gets a const reference to the underlying generator engine
1167 const _RandomNumberEngine
&
1168 base() const noexcept
1172 * @brief Gets the minimum value in the generated random number range.
1174 static constexpr result_type
1179 * @brief Gets the maximum value in the generated random number range.
1181 static constexpr result_type
1183 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
1186 * @brief Discard a sequence of random numbers.
1189 discard(unsigned long long __z
)
1191 for (; __z
!= 0ULL; --__z
)
1196 * @brief Gets the next value in the generated random number sequence.
1202 * @brief Compares two %independent_bits_engine random number generator
1203 * objects of the same type for equality.
1205 * @param __lhs A %independent_bits_engine random number generator
1207 * @param __rhs Another %independent_bits_engine random number generator
1210 * @returns true if the infinite sequences of generated values
1211 * would be equal, false otherwise.
1214 operator==(const independent_bits_engine
& __lhs
,
1215 const independent_bits_engine
& __rhs
)
1216 { return __lhs
._M_b
== __rhs
._M_b
; }
1219 * @brief Extracts the current state of a % subtract_with_carry_engine
1220 * random number generator engine @p __x from the input stream
1223 * @param __is An input stream.
1224 * @param __x A %independent_bits_engine random number generator
1227 * @returns The input stream with the state of @p __x extracted or in
1230 template<typename _CharT
, typename _Traits
>
1231 friend std::basic_istream
<_CharT
, _Traits
>&
1232 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1233 std::independent_bits_engine
<_RandomNumberEngine
,
1234 __w
, _UIntType
>& __x
)
1241 _RandomNumberEngine _M_b
;
1245 * @brief Compares two %independent_bits_engine random number generator
1246 * objects of the same type for inequality.
1248 * @param __lhs A %independent_bits_engine random number generator
1250 * @param __rhs Another %independent_bits_engine random number generator
1253 * @returns true if the infinite sequences of generated values
1254 * would be different, false otherwise.
1256 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
1258 operator!=(const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1260 const std::independent_bits_engine
<_RandomNumberEngine
, __w
,
1262 { return !(__lhs
== __rhs
); }
1265 * @brief Inserts the current state of a %independent_bits_engine random
1266 * number generator engine @p __x into the output stream @p __os.
1268 * @param __os An output stream.
1269 * @param __x A %independent_bits_engine random number generator engine.
1271 * @returns The output stream with the state of @p __x inserted or in
1274 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
,
1275 typename _CharT
, typename _Traits
>
1276 std::basic_ostream
<_CharT
, _Traits
>&
1277 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1278 const std::independent_bits_engine
<_RandomNumberEngine
,
1279 __w
, _UIntType
>& __x
)
1287 * @brief Produces random numbers by combining random numbers from some
1288 * base engine to produce random numbers with a specifies number of bits
1291 template<typename _RandomNumberEngine
, size_t __k
>
1292 class shuffle_order_engine
1294 static_assert(1u <= __k
, "template argument substituting "
1295 "__k out of bound");
1298 /** The type of the generated random value. */
1299 typedef typename
_RandomNumberEngine::result_type result_type
;
1301 static constexpr size_t table_size
= __k
;
1304 * @brief Constructs a default %shuffle_order_engine engine.
1306 * The underlying engine is default constructed as well.
1308 shuffle_order_engine()
1310 { _M_initialize(); }
1313 * @brief Copy constructs a %shuffle_order_engine engine.
1315 * Copies an existing base class random number generator.
1316 * @param __rng An existing (base class) engine object.
1319 shuffle_order_engine(const _RandomNumberEngine
& __rng
)
1321 { _M_initialize(); }
1324 * @brief Move constructs a %shuffle_order_engine engine.
1326 * Copies an existing base class random number generator.
1327 * @param __rng An existing (base class) engine object.
1330 shuffle_order_engine(_RandomNumberEngine
&& __rng
)
1331 : _M_b(std::move(__rng
))
1332 { _M_initialize(); }
1335 * @brief Seed constructs a %shuffle_order_engine engine.
1337 * Constructs the underlying generator engine seeded with @p __s.
1338 * @param __s A seed value for the base class engine.
1341 shuffle_order_engine(result_type __s
)
1343 { _M_initialize(); }
1346 * @brief Generator construct a %shuffle_order_engine engine.
1348 * @param __q A seed sequence.
1350 template<typename _Sseq
, typename
= typename
1351 std::enable_if
<!std::is_same
<_Sseq
, shuffle_order_engine
>::value
1352 && !std::is_same
<_Sseq
, _RandomNumberEngine
>::value
>
1355 shuffle_order_engine(_Sseq
& __q
)
1357 { _M_initialize(); }
1360 * @brief Reseeds the %shuffle_order_engine object with the default seed
1361 for the underlying base class generator engine.
1371 * @brief Reseeds the %shuffle_order_engine object with the default seed
1372 * for the underlying base class generator engine.
1375 seed(result_type __s
)
1382 * @brief Reseeds the %shuffle_order_engine object with the given seed
1384 * @param __q A seed generator function.
1386 template<typename _Sseq
>
1395 * Gets a const reference to the underlying generator engine object.
1397 const _RandomNumberEngine
&
1398 base() const noexcept
1402 * Gets the minimum value in the generated random number range.
1404 static constexpr result_type
1406 { return _RandomNumberEngine::min(); }
1409 * Gets the maximum value in the generated random number range.
1411 static constexpr result_type
1413 { return _RandomNumberEngine::max(); }
1416 * Discard a sequence of random numbers.
1419 discard(unsigned long long __z
)
1421 for (; __z
!= 0ULL; --__z
)
1426 * Gets the next value in the generated random number sequence.
1432 * Compares two %shuffle_order_engine random number generator objects
1433 * of the same type for equality.
1435 * @param __lhs A %shuffle_order_engine random number generator object.
1436 * @param __rhs Another %shuffle_order_engine random number generator
1439 * @returns true if the infinite sequences of generated values
1440 * would be equal, false otherwise.
1443 operator==(const shuffle_order_engine
& __lhs
,
1444 const shuffle_order_engine
& __rhs
)
1445 { return (__lhs
._M_b
== __rhs
._M_b
1446 && std::equal(__lhs
._M_v
, __lhs
._M_v
+ __k
, __rhs
._M_v
)
1447 && __lhs
._M_y
== __rhs
._M_y
); }
1450 * @brief Inserts the current state of a %shuffle_order_engine random
1451 * number generator engine @p __x into the output stream
1454 * @param __os An output stream.
1455 * @param __x A %shuffle_order_engine random number generator engine.
1457 * @returns The output stream with the state of @p __x inserted or in
1460 template<typename _RandomNumberEngine1
, size_t __k1
,
1461 typename _CharT
, typename _Traits
>
1462 friend std::basic_ostream
<_CharT
, _Traits
>&
1463 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1464 const std::shuffle_order_engine
<_RandomNumberEngine1
,
1468 * @brief Extracts the current state of a % subtract_with_carry_engine
1469 * random number generator engine @p __x from the input stream
1472 * @param __is An input stream.
1473 * @param __x A %shuffle_order_engine random number generator engine.
1475 * @returns The input stream with the state of @p __x extracted or in
1478 template<typename _RandomNumberEngine1
, size_t __k1
,
1479 typename _CharT
, typename _Traits
>
1480 friend std::basic_istream
<_CharT
, _Traits
>&
1481 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1482 std::shuffle_order_engine
<_RandomNumberEngine1
, __k1
>& __x
);
1485 void _M_initialize()
1487 for (size_t __i
= 0; __i
< __k
; ++__i
)
1492 _RandomNumberEngine _M_b
;
1493 result_type _M_v
[__k
];
1498 * Compares two %shuffle_order_engine random number generator objects
1499 * of the same type for inequality.
1501 * @param __lhs A %shuffle_order_engine random number generator object.
1502 * @param __rhs Another %shuffle_order_engine random number generator
1505 * @returns true if the infinite sequences of generated values
1506 * would be different, false otherwise.
1508 template<typename _RandomNumberEngine
, size_t __k
>
1510 operator!=(const std::shuffle_order_engine
<_RandomNumberEngine
,
1512 const std::shuffle_order_engine
<_RandomNumberEngine
,
1514 { return !(__lhs
== __rhs
); }
1518 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1520 typedef linear_congruential_engine
<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1524 * An alternative LCR (Lehmer Generator function).
1526 typedef linear_congruential_engine
<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1530 * The classic Mersenne Twister.
1533 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1534 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1535 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1537 typedef mersenne_twister_engine
<
1543 0xefc60000UL
, 18, 1812433253UL> mt19937
;
1546 * An alternative Mersenne Twister.
1548 typedef mersenne_twister_engine
<
1551 0xb5026f5aa96619e9ULL
, 29,
1552 0x5555555555555555ULL
, 17,
1553 0x71d67fffeda60000ULL
, 37,
1554 0xfff7eee000000000ULL
, 43,
1555 6364136223846793005ULL> mt19937_64
;
1557 typedef subtract_with_carry_engine
<uint_fast32_t, 24, 10, 24>
1560 typedef subtract_with_carry_engine
<uint_fast64_t, 48, 5, 12>
1563 typedef discard_block_engine
<ranlux24_base
, 223, 23> ranlux24
;
1565 typedef discard_block_engine
<ranlux48_base
, 389, 11> ranlux48
;
1567 typedef shuffle_order_engine
<minstd_rand0
, 256> knuth_b
;
1569 typedef minstd_rand0 default_random_engine
;
1572 * A standard interface to a platform-specific non-deterministic
1573 * random number generator (if any are available).
1578 /** The type of the generated random value. */
1579 typedef unsigned int result_type
;
1581 // constructors, destructors and member functions
1583 #ifdef _GLIBCXX_USE_RANDOM_TR1
1586 random_device(const std::string
& __token
= "default")
1597 random_device(const std::string
& __token
= "mt19937")
1598 { _M_init_pretr1(__token
); }
1604 static constexpr result_type
1606 { return std::numeric_limits
<result_type
>::min(); }
1608 static constexpr result_type
1610 { return std::numeric_limits
<result_type
>::max(); }
1613 entropy() const noexcept
1619 #ifdef _GLIBCXX_USE_RANDOM_TR1
1620 return this->_M_getval();
1622 return this->_M_getval_pretr1();
1626 // No copy functions.
1627 random_device(const random_device
&) = delete;
1628 void operator=(const random_device
&) = delete;
1632 void _M_init(const std::string
& __token
);
1633 void _M_init_pretr1(const std::string
& __token
);
1636 result_type
_M_getval();
1637 result_type
_M_getval_pretr1();
1646 /* @} */ // group random_generators
1649 * @addtogroup random_distributions Random Number Distributions
1655 * @addtogroup random_distributions_uniform Uniform Distributions
1656 * @ingroup random_distributions
1661 * @brief Uniform discrete distribution for random numbers.
1662 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1663 * probability throughout the range.
1665 template<typename _IntType
= int>
1666 class uniform_int_distribution
1668 static_assert(std::is_integral
<_IntType
>::value
,
1669 "template argument not an integral type");
1672 /** The type of the range of the distribution. */
1673 typedef _IntType result_type
;
1674 /** Parameter type. */
1677 typedef uniform_int_distribution
<_IntType
> distribution_type
;
1680 param_type(_IntType __a
= 0,
1681 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1682 : _M_a(__a
), _M_b(__b
)
1684 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1696 operator==(const param_type
& __p1
, const param_type
& __p2
)
1697 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1706 * @brief Constructs a uniform distribution object.
1709 uniform_int_distribution(_IntType __a
= 0,
1710 _IntType __b
= std::numeric_limits
<_IntType
>::max())
1711 : _M_param(__a
, __b
)
1715 uniform_int_distribution(const param_type
& __p
)
1720 * @brief Resets the distribution state.
1722 * Does nothing for the uniform integer distribution.
1729 { return _M_param
.a(); }
1733 { return _M_param
.b(); }
1736 * @brief Returns the parameter set of the distribution.
1740 { return _M_param
; }
1743 * @brief Sets the parameter set of the distribution.
1744 * @param __param The new parameter set of the distribution.
1747 param(const param_type
& __param
)
1748 { _M_param
= __param
; }
1751 * @brief Returns the inclusive lower bound of the distribution range.
1755 { return this->a(); }
1758 * @brief Returns the inclusive upper bound of the distribution range.
1762 { return this->b(); }
1765 * @brief Generating functions.
1767 template<typename _UniformRandomNumberGenerator
>
1769 operator()(_UniformRandomNumberGenerator
& __urng
)
1770 { return this->operator()(__urng
, _M_param
); }
1772 template<typename _UniformRandomNumberGenerator
>
1774 operator()(_UniformRandomNumberGenerator
& __urng
,
1775 const param_type
& __p
);
1777 template<typename _ForwardIterator
,
1778 typename _UniformRandomNumberGenerator
>
1780 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1781 _UniformRandomNumberGenerator
& __urng
)
1782 { this->__generate(__f
, __t
, __urng
, _M_param
); }
1784 template<typename _ForwardIterator
,
1785 typename _UniformRandomNumberGenerator
>
1787 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1788 _UniformRandomNumberGenerator
& __urng
,
1789 const param_type
& __p
)
1790 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1792 template<typename _UniformRandomNumberGenerator
>
1794 __generate(result_type
* __f
, result_type
* __t
,
1795 _UniformRandomNumberGenerator
& __urng
,
1796 const param_type
& __p
)
1797 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
1800 * @brief Return true if two uniform integer distributions have
1801 * the same parameters.
1804 operator==(const uniform_int_distribution
& __d1
,
1805 const uniform_int_distribution
& __d2
)
1806 { return __d1
._M_param
== __d2
._M_param
; }
1809 template<typename _ForwardIterator
,
1810 typename _UniformRandomNumberGenerator
>
1812 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
1813 _UniformRandomNumberGenerator
& __urng
,
1814 const param_type
& __p
);
1816 param_type _M_param
;
1820 * @brief Return true if two uniform integer distributions have
1821 * different parameters.
1823 template<typename _IntType
>
1825 operator!=(const std::uniform_int_distribution
<_IntType
>& __d1
,
1826 const std::uniform_int_distribution
<_IntType
>& __d2
)
1827 { return !(__d1
== __d2
); }
1830 * @brief Inserts a %uniform_int_distribution random number
1831 * distribution @p __x into the output stream @p os.
1833 * @param __os An output stream.
1834 * @param __x A %uniform_int_distribution random number distribution.
1836 * @returns The output stream with the state of @p __x inserted or in
1839 template<typename _IntType
, typename _CharT
, typename _Traits
>
1840 std::basic_ostream
<_CharT
, _Traits
>&
1841 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1842 const std::uniform_int_distribution
<_IntType
>&);
1845 * @brief Extracts a %uniform_int_distribution random number distribution
1846 * @p __x from the input stream @p __is.
1848 * @param __is An input stream.
1849 * @param __x A %uniform_int_distribution random number generator engine.
1851 * @returns The input stream with @p __x extracted or in an error state.
1853 template<typename _IntType
, typename _CharT
, typename _Traits
>
1854 std::basic_istream
<_CharT
, _Traits
>&
1855 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1856 std::uniform_int_distribution
<_IntType
>&);
1860 * @brief Uniform continuous distribution for random numbers.
1862 * A continuous random distribution on the range [min, max) with equal
1863 * probability throughout the range. The URNG should be real-valued and
1864 * deliver number in the range [0, 1).
1866 template<typename _RealType
= double>
1867 class uniform_real_distribution
1869 static_assert(std::is_floating_point
<_RealType
>::value
,
1870 "template argument not a floating point type");
1873 /** The type of the range of the distribution. */
1874 typedef _RealType result_type
;
1875 /** Parameter type. */
1878 typedef uniform_real_distribution
<_RealType
> distribution_type
;
1881 param_type(_RealType __a
= _RealType(0),
1882 _RealType __b
= _RealType(1))
1883 : _M_a(__a
), _M_b(__b
)
1885 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1897 operator==(const param_type
& __p1
, const param_type
& __p2
)
1898 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
1907 * @brief Constructs a uniform_real_distribution object.
1909 * @param __a [IN] The lower bound of the distribution.
1910 * @param __b [IN] The upper bound of the distribution.
1913 uniform_real_distribution(_RealType __a
= _RealType(0),
1914 _RealType __b
= _RealType(1))
1915 : _M_param(__a
, __b
)
1919 uniform_real_distribution(const param_type
& __p
)
1924 * @brief Resets the distribution state.
1926 * Does nothing for the uniform real distribution.
1933 { return _M_param
.a(); }
1937 { return _M_param
.b(); }
1940 * @brief Returns the parameter set of the distribution.
1944 { return _M_param
; }
1947 * @brief Sets the parameter set of the distribution.
1948 * @param __param The new parameter set of the distribution.
1951 param(const param_type
& __param
)
1952 { _M_param
= __param
; }
1955 * @brief Returns the inclusive lower bound of the distribution range.
1959 { return this->a(); }
1962 * @brief Returns the inclusive upper bound of the distribution range.
1966 { return this->b(); }
1969 * @brief Generating functions.
1971 template<typename _UniformRandomNumberGenerator
>
1973 operator()(_UniformRandomNumberGenerator
& __urng
)
1974 { return this->operator()(__urng
, _M_param
); }
1976 template<typename _UniformRandomNumberGenerator
>
1978 operator()(_UniformRandomNumberGenerator
& __urng
,
1979 const param_type
& __p
)
1981 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1983 return (__aurng() * (__p
.b() - __p
.a())) + __p
.a();
1986 template<typename _ForwardIterator
,
1987 typename _UniformRandomNumberGenerator
>
1989 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1990 _UniformRandomNumberGenerator
& __urng
)
1991 { this->__generate(__f
, __t
, __urng
, _M_param
); }
1993 template<typename _ForwardIterator
,
1994 typename _UniformRandomNumberGenerator
>
1996 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
1997 _UniformRandomNumberGenerator
& __urng
,
1998 const param_type
& __p
)
1999 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2001 template<typename _UniformRandomNumberGenerator
>
2003 __generate(result_type
* __f
, result_type
* __t
,
2004 _UniformRandomNumberGenerator
& __urng
,
2005 const param_type
& __p
)
2006 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2009 * @brief Return true if two uniform real distributions have
2010 * the same parameters.
2013 operator==(const uniform_real_distribution
& __d1
,
2014 const uniform_real_distribution
& __d2
)
2015 { return __d1
._M_param
== __d2
._M_param
; }
2018 template<typename _ForwardIterator
,
2019 typename _UniformRandomNumberGenerator
>
2021 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2022 _UniformRandomNumberGenerator
& __urng
,
2023 const param_type
& __p
);
2025 param_type _M_param
;
2029 * @brief Return true if two uniform real distributions have
2030 * different parameters.
2032 template<typename _IntType
>
2034 operator!=(const std::uniform_real_distribution
<_IntType
>& __d1
,
2035 const std::uniform_real_distribution
<_IntType
>& __d2
)
2036 { return !(__d1
== __d2
); }
2039 * @brief Inserts a %uniform_real_distribution random number
2040 * distribution @p __x into the output stream @p __os.
2042 * @param __os An output stream.
2043 * @param __x A %uniform_real_distribution random number distribution.
2045 * @returns The output stream with the state of @p __x inserted or in
2048 template<typename _RealType
, typename _CharT
, typename _Traits
>
2049 std::basic_ostream
<_CharT
, _Traits
>&
2050 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2051 const std::uniform_real_distribution
<_RealType
>&);
2054 * @brief Extracts a %uniform_real_distribution random number distribution
2055 * @p __x from the input stream @p __is.
2057 * @param __is An input stream.
2058 * @param __x A %uniform_real_distribution random number generator engine.
2060 * @returns The input stream with @p __x extracted or in an error state.
2062 template<typename _RealType
, typename _CharT
, typename _Traits
>
2063 std::basic_istream
<_CharT
, _Traits
>&
2064 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2065 std::uniform_real_distribution
<_RealType
>&);
2067 /* @} */ // group random_distributions_uniform
2070 * @addtogroup random_distributions_normal Normal Distributions
2071 * @ingroup random_distributions
2076 * @brief A normal continuous distribution for random numbers.
2078 * The formula for the normal probability density function is
2080 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
2081 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
2084 template<typename _RealType
= double>
2085 class normal_distribution
2087 static_assert(std::is_floating_point
<_RealType
>::value
,
2088 "template argument not a floating point type");
2091 /** The type of the range of the distribution. */
2092 typedef _RealType result_type
;
2093 /** Parameter type. */
2096 typedef normal_distribution
<_RealType
> distribution_type
;
2099 param_type(_RealType __mean
= _RealType(0),
2100 _RealType __stddev
= _RealType(1))
2101 : _M_mean(__mean
), _M_stddev(__stddev
)
2103 _GLIBCXX_DEBUG_ASSERT(_M_stddev
> _RealType(0));
2112 { return _M_stddev
; }
2115 operator==(const param_type
& __p1
, const param_type
& __p2
)
2116 { return (__p1
._M_mean
== __p2
._M_mean
2117 && __p1
._M_stddev
== __p2
._M_stddev
); }
2121 _RealType _M_stddev
;
2126 * Constructs a normal distribution with parameters @f$mean@f$ and
2127 * standard deviation.
2130 normal_distribution(result_type __mean
= result_type(0),
2131 result_type __stddev
= result_type(1))
2132 : _M_param(__mean
, __stddev
), _M_saved_available(false)
2136 normal_distribution(const param_type
& __p
)
2137 : _M_param(__p
), _M_saved_available(false)
2141 * @brief Resets the distribution state.
2145 { _M_saved_available
= false; }
2148 * @brief Returns the mean of the distribution.
2152 { return _M_param
.mean(); }
2155 * @brief Returns the standard deviation of the distribution.
2159 { return _M_param
.stddev(); }
2162 * @brief Returns the parameter set of the distribution.
2166 { return _M_param
; }
2169 * @brief Sets the parameter set of the distribution.
2170 * @param __param The new parameter set of the distribution.
2173 param(const param_type
& __param
)
2174 { _M_param
= __param
; }
2177 * @brief Returns the greatest lower bound value of the distribution.
2181 { return std::numeric_limits
<result_type
>::lowest(); }
2184 * @brief Returns the least upper bound value of the distribution.
2188 { return std::numeric_limits
<result_type
>::max(); }
2191 * @brief Generating functions.
2193 template<typename _UniformRandomNumberGenerator
>
2195 operator()(_UniformRandomNumberGenerator
& __urng
)
2196 { return this->operator()(__urng
, _M_param
); }
2198 template<typename _UniformRandomNumberGenerator
>
2200 operator()(_UniformRandomNumberGenerator
& __urng
,
2201 const param_type
& __p
);
2203 template<typename _ForwardIterator
,
2204 typename _UniformRandomNumberGenerator
>
2206 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2207 _UniformRandomNumberGenerator
& __urng
)
2208 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2210 template<typename _ForwardIterator
,
2211 typename _UniformRandomNumberGenerator
>
2213 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2214 _UniformRandomNumberGenerator
& __urng
,
2215 const param_type
& __p
)
2216 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2218 template<typename _UniformRandomNumberGenerator
>
2220 __generate(result_type
* __f
, result_type
* __t
,
2221 _UniformRandomNumberGenerator
& __urng
,
2222 const param_type
& __p
)
2223 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2226 * @brief Return true if two normal distributions have
2227 * the same parameters and the sequences that would
2228 * be generated are equal.
2230 template<typename _RealType1
>
2232 operator==(const std::normal_distribution
<_RealType1
>& __d1
,
2233 const std::normal_distribution
<_RealType1
>& __d2
);
2236 * @brief Inserts a %normal_distribution random number distribution
2237 * @p __x into the output stream @p __os.
2239 * @param __os An output stream.
2240 * @param __x A %normal_distribution random number distribution.
2242 * @returns The output stream with the state of @p __x inserted or in
2245 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2246 friend std::basic_ostream
<_CharT
, _Traits
>&
2247 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2248 const std::normal_distribution
<_RealType1
>& __x
);
2251 * @brief Extracts a %normal_distribution random number distribution
2252 * @p __x from the input stream @p __is.
2254 * @param __is An input stream.
2255 * @param __x A %normal_distribution random number generator engine.
2257 * @returns The input stream with @p __x extracted or in an error
2260 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2261 friend std::basic_istream
<_CharT
, _Traits
>&
2262 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2263 std::normal_distribution
<_RealType1
>& __x
);
2266 template<typename _ForwardIterator
,
2267 typename _UniformRandomNumberGenerator
>
2269 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2270 _UniformRandomNumberGenerator
& __urng
,
2271 const param_type
& __p
);
2273 param_type _M_param
;
2274 result_type _M_saved
;
2275 bool _M_saved_available
;
2279 * @brief Return true if two normal distributions are different.
2281 template<typename _RealType
>
2283 operator!=(const std::normal_distribution
<_RealType
>& __d1
,
2284 const std::normal_distribution
<_RealType
>& __d2
)
2285 { return !(__d1
== __d2
); }
2289 * @brief A lognormal_distribution random number distribution.
2291 * The formula for the normal probability mass function is
2293 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2294 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2297 template<typename _RealType
= double>
2298 class lognormal_distribution
2300 static_assert(std::is_floating_point
<_RealType
>::value
,
2301 "template argument not a floating point type");
2304 /** The type of the range of the distribution. */
2305 typedef _RealType result_type
;
2306 /** Parameter type. */
2309 typedef lognormal_distribution
<_RealType
> distribution_type
;
2312 param_type(_RealType __m
= _RealType(0),
2313 _RealType __s
= _RealType(1))
2314 : _M_m(__m
), _M_s(__s
)
2326 operator==(const param_type
& __p1
, const param_type
& __p2
)
2327 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_s
== __p2
._M_s
; }
2335 lognormal_distribution(_RealType __m
= _RealType(0),
2336 _RealType __s
= _RealType(1))
2337 : _M_param(__m
, __s
), _M_nd()
2341 lognormal_distribution(const param_type
& __p
)
2342 : _M_param(__p
), _M_nd()
2346 * Resets the distribution state.
2357 { return _M_param
.m(); }
2361 { return _M_param
.s(); }
2364 * @brief Returns the parameter set of the distribution.
2368 { return _M_param
; }
2371 * @brief Sets the parameter set of the distribution.
2372 * @param __param The new parameter set of the distribution.
2375 param(const param_type
& __param
)
2376 { _M_param
= __param
; }
2379 * @brief Returns the greatest lower bound value of the distribution.
2383 { return result_type(0); }
2386 * @brief Returns the least upper bound value of the distribution.
2390 { return std::numeric_limits
<result_type
>::max(); }
2393 * @brief Generating functions.
2395 template<typename _UniformRandomNumberGenerator
>
2397 operator()(_UniformRandomNumberGenerator
& __urng
)
2398 { return this->operator()(__urng
, _M_param
); }
2400 template<typename _UniformRandomNumberGenerator
>
2402 operator()(_UniformRandomNumberGenerator
& __urng
,
2403 const param_type
& __p
)
2404 { return std::exp(__p
.s() * _M_nd(__urng
) + __p
.m()); }
2406 template<typename _ForwardIterator
,
2407 typename _UniformRandomNumberGenerator
>
2409 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2410 _UniformRandomNumberGenerator
& __urng
)
2411 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2413 template<typename _ForwardIterator
,
2414 typename _UniformRandomNumberGenerator
>
2416 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2417 _UniformRandomNumberGenerator
& __urng
,
2418 const param_type
& __p
)
2419 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2421 template<typename _UniformRandomNumberGenerator
>
2423 __generate(result_type
* __f
, result_type
* __t
,
2424 _UniformRandomNumberGenerator
& __urng
,
2425 const param_type
& __p
)
2426 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2429 * @brief Return true if two lognormal distributions have
2430 * the same parameters and the sequences that would
2431 * be generated are equal.
2434 operator==(const lognormal_distribution
& __d1
,
2435 const lognormal_distribution
& __d2
)
2436 { return (__d1
._M_param
== __d2
._M_param
2437 && __d1
._M_nd
== __d2
._M_nd
); }
2440 * @brief Inserts a %lognormal_distribution random number distribution
2441 * @p __x into the output stream @p __os.
2443 * @param __os An output stream.
2444 * @param __x A %lognormal_distribution random number distribution.
2446 * @returns The output stream with the state of @p __x inserted or in
2449 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2450 friend std::basic_ostream
<_CharT
, _Traits
>&
2451 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2452 const std::lognormal_distribution
<_RealType1
>& __x
);
2455 * @brief Extracts a %lognormal_distribution random number distribution
2456 * @p __x from the input stream @p __is.
2458 * @param __is An input stream.
2459 * @param __x A %lognormal_distribution random number
2462 * @returns The input stream with @p __x extracted or in an error state.
2464 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2465 friend std::basic_istream
<_CharT
, _Traits
>&
2466 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2467 std::lognormal_distribution
<_RealType1
>& __x
);
2470 template<typename _ForwardIterator
,
2471 typename _UniformRandomNumberGenerator
>
2473 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2474 _UniformRandomNumberGenerator
& __urng
,
2475 const param_type
& __p
);
2477 param_type _M_param
;
2479 std::normal_distribution
<result_type
> _M_nd
;
2483 * @brief Return true if two lognormal distributions are different.
2485 template<typename _RealType
>
2487 operator!=(const std::lognormal_distribution
<_RealType
>& __d1
,
2488 const std::lognormal_distribution
<_RealType
>& __d2
)
2489 { return !(__d1
== __d2
); }
2493 * @brief A gamma continuous distribution for random numbers.
2495 * The formula for the gamma probability density function is:
2497 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2498 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2501 template<typename _RealType
= double>
2502 class gamma_distribution
2504 static_assert(std::is_floating_point
<_RealType
>::value
,
2505 "template argument not a floating point type");
2508 /** The type of the range of the distribution. */
2509 typedef _RealType result_type
;
2510 /** Parameter type. */
2513 typedef gamma_distribution
<_RealType
> distribution_type
;
2514 friend class gamma_distribution
<_RealType
>;
2517 param_type(_RealType __alpha_val
= _RealType(1),
2518 _RealType __beta_val
= _RealType(1))
2519 : _M_alpha(__alpha_val
), _M_beta(__beta_val
)
2521 _GLIBCXX_DEBUG_ASSERT(_M_alpha
> _RealType(0));
2527 { return _M_alpha
; }
2534 operator==(const param_type
& __p1
, const param_type
& __p2
)
2535 { return (__p1
._M_alpha
== __p2
._M_alpha
2536 && __p1
._M_beta
== __p2
._M_beta
); }
2545 _RealType _M_malpha
, _M_a2
;
2550 * @brief Constructs a gamma distribution with parameters
2551 * @f$\alpha@f$ and @f$\beta@f$.
2554 gamma_distribution(_RealType __alpha_val
= _RealType(1),
2555 _RealType __beta_val
= _RealType(1))
2556 : _M_param(__alpha_val
, __beta_val
), _M_nd()
2560 gamma_distribution(const param_type
& __p
)
2561 : _M_param(__p
), _M_nd()
2565 * @brief Resets the distribution state.
2572 * @brief Returns the @f$\alpha@f$ of the distribution.
2576 { return _M_param
.alpha(); }
2579 * @brief Returns the @f$\beta@f$ of the distribution.
2583 { return _M_param
.beta(); }
2586 * @brief Returns the parameter set of the distribution.
2590 { return _M_param
; }
2593 * @brief Sets the parameter set of the distribution.
2594 * @param __param The new parameter set of the distribution.
2597 param(const param_type
& __param
)
2598 { _M_param
= __param
; }
2601 * @brief Returns the greatest lower bound value of the distribution.
2605 { return result_type(0); }
2608 * @brief Returns the least upper bound value of the distribution.
2612 { return std::numeric_limits
<result_type
>::max(); }
2615 * @brief Generating functions.
2617 template<typename _UniformRandomNumberGenerator
>
2619 operator()(_UniformRandomNumberGenerator
& __urng
)
2620 { return this->operator()(__urng
, _M_param
); }
2622 template<typename _UniformRandomNumberGenerator
>
2624 operator()(_UniformRandomNumberGenerator
& __urng
,
2625 const param_type
& __p
);
2627 template<typename _ForwardIterator
,
2628 typename _UniformRandomNumberGenerator
>
2630 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2631 _UniformRandomNumberGenerator
& __urng
)
2632 { this->__generate(__f
, __t
, __urng
, _M_param
); }
2634 template<typename _ForwardIterator
,
2635 typename _UniformRandomNumberGenerator
>
2637 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2638 _UniformRandomNumberGenerator
& __urng
,
2639 const param_type
& __p
)
2640 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2642 template<typename _UniformRandomNumberGenerator
>
2644 __generate(result_type
* __f
, result_type
* __t
,
2645 _UniformRandomNumberGenerator
& __urng
,
2646 const param_type
& __p
)
2647 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
2650 * @brief Return true if two gamma distributions have the same
2651 * parameters and the sequences that would be generated
2655 operator==(const gamma_distribution
& __d1
,
2656 const gamma_distribution
& __d2
)
2657 { return (__d1
._M_param
== __d2
._M_param
2658 && __d1
._M_nd
== __d2
._M_nd
); }
2661 * @brief Inserts a %gamma_distribution random number distribution
2662 * @p __x into the output stream @p __os.
2664 * @param __os An output stream.
2665 * @param __x A %gamma_distribution random number distribution.
2667 * @returns The output stream with the state of @p __x inserted or in
2670 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2671 friend std::basic_ostream
<_CharT
, _Traits
>&
2672 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2673 const std::gamma_distribution
<_RealType1
>& __x
);
2676 * @brief Extracts a %gamma_distribution random number distribution
2677 * @p __x from the input stream @p __is.
2679 * @param __is An input stream.
2680 * @param __x A %gamma_distribution random number generator engine.
2682 * @returns The input stream with @p __x extracted or in an error state.
2684 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2685 friend std::basic_istream
<_CharT
, _Traits
>&
2686 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2687 std::gamma_distribution
<_RealType1
>& __x
);
2690 template<typename _ForwardIterator
,
2691 typename _UniformRandomNumberGenerator
>
2693 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2694 _UniformRandomNumberGenerator
& __urng
,
2695 const param_type
& __p
);
2697 param_type _M_param
;
2699 std::normal_distribution
<result_type
> _M_nd
;
2703 * @brief Return true if two gamma distributions are different.
2705 template<typename _RealType
>
2707 operator!=(const std::gamma_distribution
<_RealType
>& __d1
,
2708 const std::gamma_distribution
<_RealType
>& __d2
)
2709 { return !(__d1
== __d2
); }
2713 * @brief A chi_squared_distribution random number distribution.
2715 * The formula for the normal probability mass function is
2716 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2718 template<typename _RealType
= double>
2719 class chi_squared_distribution
2721 static_assert(std::is_floating_point
<_RealType
>::value
,
2722 "template argument not a floating point type");
2725 /** The type of the range of the distribution. */
2726 typedef _RealType result_type
;
2727 /** Parameter type. */
2730 typedef chi_squared_distribution
<_RealType
> distribution_type
;
2733 param_type(_RealType __n
= _RealType(1))
2742 operator==(const param_type
& __p1
, const param_type
& __p2
)
2743 { return __p1
._M_n
== __p2
._M_n
; }
2750 chi_squared_distribution(_RealType __n
= _RealType(1))
2751 : _M_param(__n
), _M_gd(__n
/ 2)
2755 chi_squared_distribution(const param_type
& __p
)
2756 : _M_param(__p
), _M_gd(__p
.n() / 2)
2760 * @brief Resets the distribution state.
2771 { return _M_param
.n(); }
2774 * @brief Returns the parameter set of the distribution.
2778 { return _M_param
; }
2781 * @brief Sets the parameter set of the distribution.
2782 * @param __param The new parameter set of the distribution.
2785 param(const param_type
& __param
)
2786 { _M_param
= __param
; }
2789 * @brief Returns the greatest lower bound value of the distribution.
2793 { return result_type(0); }
2796 * @brief Returns the least upper bound value of the distribution.
2800 { return std::numeric_limits
<result_type
>::max(); }
2803 * @brief Generating functions.
2805 template<typename _UniformRandomNumberGenerator
>
2807 operator()(_UniformRandomNumberGenerator
& __urng
)
2808 { return 2 * _M_gd(__urng
); }
2810 template<typename _UniformRandomNumberGenerator
>
2812 operator()(_UniformRandomNumberGenerator
& __urng
,
2813 const param_type
& __p
)
2815 typedef typename
std::gamma_distribution
<result_type
>::param_type
2817 return 2 * _M_gd(__urng
, param_type(__p
.n() / 2));
2820 template<typename _ForwardIterator
,
2821 typename _UniformRandomNumberGenerator
>
2823 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2824 _UniformRandomNumberGenerator
& __urng
)
2825 { this->__generate_impl(__f
, __t
, __urng
); }
2827 template<typename _ForwardIterator
,
2828 typename _UniformRandomNumberGenerator
>
2830 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
2831 _UniformRandomNumberGenerator
& __urng
,
2832 const param_type
& __p
)
2833 { typename
std::gamma_distribution
<result_type
>::param_type
2835 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2837 template<typename _UniformRandomNumberGenerator
>
2839 __generate(result_type
* __f
, result_type
* __t
,
2840 _UniformRandomNumberGenerator
& __urng
)
2841 { this->__generate_impl(__f
, __t
, __urng
); }
2843 template<typename _UniformRandomNumberGenerator
>
2845 __generate(result_type
* __f
, result_type
* __t
,
2846 _UniformRandomNumberGenerator
& __urng
,
2847 const param_type
& __p
)
2848 { typename
std::gamma_distribution
<result_type
>::param_type
2850 this->__generate_impl(__f
, __t
, __urng
, __p2
); }
2853 * @brief Return true if two Chi-squared distributions have
2854 * the same parameters and the sequences that would be
2855 * generated are equal.
2858 operator==(const chi_squared_distribution
& __d1
,
2859 const chi_squared_distribution
& __d2
)
2860 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
2863 * @brief Inserts a %chi_squared_distribution random number distribution
2864 * @p __x into the output stream @p __os.
2866 * @param __os An output stream.
2867 * @param __x A %chi_squared_distribution random number distribution.
2869 * @returns The output stream with the state of @p __x inserted or in
2872 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2873 friend std::basic_ostream
<_CharT
, _Traits
>&
2874 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
2875 const std::chi_squared_distribution
<_RealType1
>& __x
);
2878 * @brief Extracts a %chi_squared_distribution random number distribution
2879 * @p __x from the input stream @p __is.
2881 * @param __is An input stream.
2882 * @param __x A %chi_squared_distribution random number
2885 * @returns The input stream with @p __x extracted or in an error state.
2887 template<typename _RealType1
, typename _CharT
, typename _Traits
>
2888 friend std::basic_istream
<_CharT
, _Traits
>&
2889 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2890 std::chi_squared_distribution
<_RealType1
>& __x
);
2893 template<typename _ForwardIterator
,
2894 typename _UniformRandomNumberGenerator
>
2896 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2897 _UniformRandomNumberGenerator
& __urng
);
2899 template<typename _ForwardIterator
,
2900 typename _UniformRandomNumberGenerator
>
2902 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
2903 _UniformRandomNumberGenerator
& __urng
,
2905 std::gamma_distribution
<result_type
>::param_type
& __p
);
2907 param_type _M_param
;
2909 std::gamma_distribution
<result_type
> _M_gd
;
2913 * @brief Return true if two Chi-squared distributions are different.
2915 template<typename _RealType
>
2917 operator!=(const std::chi_squared_distribution
<_RealType
>& __d1
,
2918 const std::chi_squared_distribution
<_RealType
>& __d2
)
2919 { return !(__d1
== __d2
); }
2923 * @brief A cauchy_distribution random number distribution.
2925 * The formula for the normal probability mass function is
2926 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2928 template<typename _RealType
= double>
2929 class cauchy_distribution
2931 static_assert(std::is_floating_point
<_RealType
>::value
,
2932 "template argument not a floating point type");
2935 /** The type of the range of the distribution. */
2936 typedef _RealType result_type
;
2937 /** Parameter type. */
2940 typedef cauchy_distribution
<_RealType
> distribution_type
;
2943 param_type(_RealType __a
= _RealType(0),
2944 _RealType __b
= _RealType(1))
2945 : _M_a(__a
), _M_b(__b
)
2957 operator==(const param_type
& __p1
, const param_type
& __p2
)
2958 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
2966 cauchy_distribution(_RealType __a
= _RealType(0),
2967 _RealType __b
= _RealType(1))
2968 : _M_param(__a
, __b
)
2972 cauchy_distribution(const param_type
& __p
)
2977 * @brief Resets the distribution state.
2988 { return _M_param
.a(); }
2992 { return _M_param
.b(); }
2995 * @brief Returns the parameter set of the distribution.
2999 { return _M_param
; }
3002 * @brief Sets the parameter set of the distribution.
3003 * @param __param The new parameter set of the distribution.
3006 param(const param_type
& __param
)
3007 { _M_param
= __param
; }
3010 * @brief Returns the greatest lower bound value of the distribution.
3014 { return std::numeric_limits
<result_type
>::lowest(); }
3017 * @brief Returns the least upper bound value of the distribution.
3021 { return std::numeric_limits
<result_type
>::max(); }
3024 * @brief Generating functions.
3026 template<typename _UniformRandomNumberGenerator
>
3028 operator()(_UniformRandomNumberGenerator
& __urng
)
3029 { return this->operator()(__urng
, _M_param
); }
3031 template<typename _UniformRandomNumberGenerator
>
3033 operator()(_UniformRandomNumberGenerator
& __urng
,
3034 const param_type
& __p
);
3036 template<typename _ForwardIterator
,
3037 typename _UniformRandomNumberGenerator
>
3039 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3040 _UniformRandomNumberGenerator
& __urng
)
3041 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3043 template<typename _ForwardIterator
,
3044 typename _UniformRandomNumberGenerator
>
3046 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3047 _UniformRandomNumberGenerator
& __urng
,
3048 const param_type
& __p
)
3049 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3051 template<typename _UniformRandomNumberGenerator
>
3053 __generate(result_type
* __f
, result_type
* __t
,
3054 _UniformRandomNumberGenerator
& __urng
,
3055 const param_type
& __p
)
3056 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3059 * @brief Return true if two Cauchy distributions have
3060 * the same parameters.
3063 operator==(const cauchy_distribution
& __d1
,
3064 const cauchy_distribution
& __d2
)
3065 { return __d1
._M_param
== __d2
._M_param
; }
3068 template<typename _ForwardIterator
,
3069 typename _UniformRandomNumberGenerator
>
3071 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3072 _UniformRandomNumberGenerator
& __urng
,
3073 const param_type
& __p
);
3075 param_type _M_param
;
3079 * @brief Return true if two Cauchy distributions have
3080 * different parameters.
3082 template<typename _RealType
>
3084 operator!=(const std::cauchy_distribution
<_RealType
>& __d1
,
3085 const std::cauchy_distribution
<_RealType
>& __d2
)
3086 { return !(__d1
== __d2
); }
3089 * @brief Inserts a %cauchy_distribution random number distribution
3090 * @p __x into the output stream @p __os.
3092 * @param __os An output stream.
3093 * @param __x A %cauchy_distribution random number distribution.
3095 * @returns The output stream with the state of @p __x inserted or in
3098 template<typename _RealType
, typename _CharT
, typename _Traits
>
3099 std::basic_ostream
<_CharT
, _Traits
>&
3100 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3101 const std::cauchy_distribution
<_RealType
>& __x
);
3104 * @brief Extracts a %cauchy_distribution random number distribution
3105 * @p __x from the input stream @p __is.
3107 * @param __is An input stream.
3108 * @param __x A %cauchy_distribution random number
3111 * @returns The input stream with @p __x extracted or in an error state.
3113 template<typename _RealType
, typename _CharT
, typename _Traits
>
3114 std::basic_istream
<_CharT
, _Traits
>&
3115 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3116 std::cauchy_distribution
<_RealType
>& __x
);
3120 * @brief A fisher_f_distribution random number distribution.
3122 * The formula for the normal probability mass function is
3124 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3125 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3126 * (1 + \frac{mx}{n})^{-(m+n)/2}
3129 template<typename _RealType
= double>
3130 class fisher_f_distribution
3132 static_assert(std::is_floating_point
<_RealType
>::value
,
3133 "template argument not a floating point type");
3136 /** The type of the range of the distribution. */
3137 typedef _RealType result_type
;
3138 /** Parameter type. */
3141 typedef fisher_f_distribution
<_RealType
> distribution_type
;
3144 param_type(_RealType __m
= _RealType(1),
3145 _RealType __n
= _RealType(1))
3146 : _M_m(__m
), _M_n(__n
)
3158 operator==(const param_type
& __p1
, const param_type
& __p2
)
3159 { return __p1
._M_m
== __p2
._M_m
&& __p1
._M_n
== __p2
._M_n
; }
3167 fisher_f_distribution(_RealType __m
= _RealType(1),
3168 _RealType __n
= _RealType(1))
3169 : _M_param(__m
, __n
), _M_gd_x(__m
/ 2), _M_gd_y(__n
/ 2)
3173 fisher_f_distribution(const param_type
& __p
)
3174 : _M_param(__p
), _M_gd_x(__p
.m() / 2), _M_gd_y(__p
.n() / 2)
3178 * @brief Resets the distribution state.
3192 { return _M_param
.m(); }
3196 { return _M_param
.n(); }
3199 * @brief Returns the parameter set of the distribution.
3203 { return _M_param
; }
3206 * @brief Sets the parameter set of the distribution.
3207 * @param __param The new parameter set of the distribution.
3210 param(const param_type
& __param
)
3211 { _M_param
= __param
; }
3214 * @brief Returns the greatest lower bound value of the distribution.
3218 { return result_type(0); }
3221 * @brief Returns the least upper bound value of the distribution.
3225 { return std::numeric_limits
<result_type
>::max(); }
3228 * @brief Generating functions.
3230 template<typename _UniformRandomNumberGenerator
>
3232 operator()(_UniformRandomNumberGenerator
& __urng
)
3233 { return (_M_gd_x(__urng
) * n()) / (_M_gd_y(__urng
) * m()); }
3235 template<typename _UniformRandomNumberGenerator
>
3237 operator()(_UniformRandomNumberGenerator
& __urng
,
3238 const param_type
& __p
)
3240 typedef typename
std::gamma_distribution
<result_type
>::param_type
3242 return ((_M_gd_x(__urng
, param_type(__p
.m() / 2)) * n())
3243 / (_M_gd_y(__urng
, param_type(__p
.n() / 2)) * m()));
3246 template<typename _ForwardIterator
,
3247 typename _UniformRandomNumberGenerator
>
3249 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3250 _UniformRandomNumberGenerator
& __urng
)
3251 { this->__generate_impl(__f
, __t
, __urng
); }
3253 template<typename _ForwardIterator
,
3254 typename _UniformRandomNumberGenerator
>
3256 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3257 _UniformRandomNumberGenerator
& __urng
,
3258 const param_type
& __p
)
3259 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3261 template<typename _UniformRandomNumberGenerator
>
3263 __generate(result_type
* __f
, result_type
* __t
,
3264 _UniformRandomNumberGenerator
& __urng
)
3265 { this->__generate_impl(__f
, __t
, __urng
); }
3267 template<typename _UniformRandomNumberGenerator
>
3269 __generate(result_type
* __f
, result_type
* __t
,
3270 _UniformRandomNumberGenerator
& __urng
,
3271 const param_type
& __p
)
3272 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3275 * @brief Return true if two Fisher f distributions have
3276 * the same parameters and the sequences that would
3277 * be generated are equal.
3280 operator==(const fisher_f_distribution
& __d1
,
3281 const fisher_f_distribution
& __d2
)
3282 { return (__d1
._M_param
== __d2
._M_param
3283 && __d1
._M_gd_x
== __d2
._M_gd_x
3284 && __d1
._M_gd_y
== __d2
._M_gd_y
); }
3287 * @brief Inserts a %fisher_f_distribution random number distribution
3288 * @p __x into the output stream @p __os.
3290 * @param __os An output stream.
3291 * @param __x A %fisher_f_distribution random number distribution.
3293 * @returns The output stream with the state of @p __x inserted or in
3296 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3297 friend std::basic_ostream
<_CharT
, _Traits
>&
3298 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3299 const std::fisher_f_distribution
<_RealType1
>& __x
);
3302 * @brief Extracts a %fisher_f_distribution random number distribution
3303 * @p __x from the input stream @p __is.
3305 * @param __is An input stream.
3306 * @param __x A %fisher_f_distribution random number
3309 * @returns The input stream with @p __x extracted or in an error state.
3311 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3312 friend std::basic_istream
<_CharT
, _Traits
>&
3313 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3314 std::fisher_f_distribution
<_RealType1
>& __x
);
3317 template<typename _ForwardIterator
,
3318 typename _UniformRandomNumberGenerator
>
3320 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3321 _UniformRandomNumberGenerator
& __urng
);
3323 template<typename _ForwardIterator
,
3324 typename _UniformRandomNumberGenerator
>
3326 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3327 _UniformRandomNumberGenerator
& __urng
,
3328 const param_type
& __p
);
3330 param_type _M_param
;
3332 std::gamma_distribution
<result_type
> _M_gd_x
, _M_gd_y
;
3336 * @brief Return true if two Fisher f distributions are different.
3338 template<typename _RealType
>
3340 operator!=(const std::fisher_f_distribution
<_RealType
>& __d1
,
3341 const std::fisher_f_distribution
<_RealType
>& __d2
)
3342 { return !(__d1
== __d2
); }
3345 * @brief A student_t_distribution random number distribution.
3347 * The formula for the normal probability mass function is:
3349 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3350 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3353 template<typename _RealType
= double>
3354 class student_t_distribution
3356 static_assert(std::is_floating_point
<_RealType
>::value
,
3357 "template argument not a floating point type");
3360 /** The type of the range of the distribution. */
3361 typedef _RealType result_type
;
3362 /** Parameter type. */
3365 typedef student_t_distribution
<_RealType
> distribution_type
;
3368 param_type(_RealType __n
= _RealType(1))
3377 operator==(const param_type
& __p1
, const param_type
& __p2
)
3378 { return __p1
._M_n
== __p2
._M_n
; }
3385 student_t_distribution(_RealType __n
= _RealType(1))
3386 : _M_param(__n
), _M_nd(), _M_gd(__n
/ 2, 2)
3390 student_t_distribution(const param_type
& __p
)
3391 : _M_param(__p
), _M_nd(), _M_gd(__p
.n() / 2, 2)
3395 * @brief Resets the distribution state.
3409 { return _M_param
.n(); }
3412 * @brief Returns the parameter set of the distribution.
3416 { return _M_param
; }
3419 * @brief Sets the parameter set of the distribution.
3420 * @param __param The new parameter set of the distribution.
3423 param(const param_type
& __param
)
3424 { _M_param
= __param
; }
3427 * @brief Returns the greatest lower bound value of the distribution.
3431 { return std::numeric_limits
<result_type
>::lowest(); }
3434 * @brief Returns the least upper bound value of the distribution.
3438 { return std::numeric_limits
<result_type
>::max(); }
3441 * @brief Generating functions.
3443 template<typename _UniformRandomNumberGenerator
>
3445 operator()(_UniformRandomNumberGenerator
& __urng
)
3446 { return _M_nd(__urng
) * std::sqrt(n() / _M_gd(__urng
)); }
3448 template<typename _UniformRandomNumberGenerator
>
3450 operator()(_UniformRandomNumberGenerator
& __urng
,
3451 const param_type
& __p
)
3453 typedef typename
std::gamma_distribution
<result_type
>::param_type
3456 const result_type __g
= _M_gd(__urng
, param_type(__p
.n() / 2, 2));
3457 return _M_nd(__urng
) * std::sqrt(__p
.n() / __g
);
3460 template<typename _ForwardIterator
,
3461 typename _UniformRandomNumberGenerator
>
3463 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3464 _UniformRandomNumberGenerator
& __urng
)
3465 { this->__generate_impl(__f
, __t
, __urng
); }
3467 template<typename _ForwardIterator
,
3468 typename _UniformRandomNumberGenerator
>
3470 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3471 _UniformRandomNumberGenerator
& __urng
,
3472 const param_type
& __p
)
3473 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3475 template<typename _UniformRandomNumberGenerator
>
3477 __generate(result_type
* __f
, result_type
* __t
,
3478 _UniformRandomNumberGenerator
& __urng
)
3479 { this->__generate_impl(__f
, __t
, __urng
); }
3481 template<typename _UniformRandomNumberGenerator
>
3483 __generate(result_type
* __f
, result_type
* __t
,
3484 _UniformRandomNumberGenerator
& __urng
,
3485 const param_type
& __p
)
3486 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3489 * @brief Return true if two Student t distributions have
3490 * the same parameters and the sequences that would
3491 * be generated are equal.
3494 operator==(const student_t_distribution
& __d1
,
3495 const student_t_distribution
& __d2
)
3496 { return (__d1
._M_param
== __d2
._M_param
3497 && __d1
._M_nd
== __d2
._M_nd
&& __d1
._M_gd
== __d2
._M_gd
); }
3500 * @brief Inserts a %student_t_distribution random number distribution
3501 * @p __x into the output stream @p __os.
3503 * @param __os An output stream.
3504 * @param __x A %student_t_distribution random number distribution.
3506 * @returns The output stream with the state of @p __x inserted or in
3509 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3510 friend std::basic_ostream
<_CharT
, _Traits
>&
3511 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3512 const std::student_t_distribution
<_RealType1
>& __x
);
3515 * @brief Extracts a %student_t_distribution random number distribution
3516 * @p __x from the input stream @p __is.
3518 * @param __is An input stream.
3519 * @param __x A %student_t_distribution random number
3522 * @returns The input stream with @p __x extracted or in an error state.
3524 template<typename _RealType1
, typename _CharT
, typename _Traits
>
3525 friend std::basic_istream
<_CharT
, _Traits
>&
3526 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3527 std::student_t_distribution
<_RealType1
>& __x
);
3530 template<typename _ForwardIterator
,
3531 typename _UniformRandomNumberGenerator
>
3533 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3534 _UniformRandomNumberGenerator
& __urng
);
3535 template<typename _ForwardIterator
,
3536 typename _UniformRandomNumberGenerator
>
3538 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3539 _UniformRandomNumberGenerator
& __urng
,
3540 const param_type
& __p
);
3542 param_type _M_param
;
3544 std::normal_distribution
<result_type
> _M_nd
;
3545 std::gamma_distribution
<result_type
> _M_gd
;
3549 * @brief Return true if two Student t distributions are different.
3551 template<typename _RealType
>
3553 operator!=(const std::student_t_distribution
<_RealType
>& __d1
,
3554 const std::student_t_distribution
<_RealType
>& __d2
)
3555 { return !(__d1
== __d2
); }
3558 /* @} */ // group random_distributions_normal
3561 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3562 * @ingroup random_distributions
3567 * @brief A Bernoulli random number distribution.
3569 * Generates a sequence of true and false values with likelihood @f$p@f$
3570 * that true will come up and @f$(1 - p)@f$ that false will appear.
3572 class bernoulli_distribution
3575 /** The type of the range of the distribution. */
3576 typedef bool result_type
;
3577 /** Parameter type. */
3580 typedef bernoulli_distribution distribution_type
;
3583 param_type(double __p
= 0.5)
3586 _GLIBCXX_DEBUG_ASSERT((_M_p
>= 0.0) && (_M_p
<= 1.0));
3594 operator==(const param_type
& __p1
, const param_type
& __p2
)
3595 { return __p1
._M_p
== __p2
._M_p
; }
3603 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3605 * @param __p [IN] The likelihood of a true result being returned.
3606 * Must be in the interval @f$[0, 1]@f$.
3609 bernoulli_distribution(double __p
= 0.5)
3614 bernoulli_distribution(const param_type
& __p
)
3619 * @brief Resets the distribution state.
3621 * Does nothing for a Bernoulli distribution.
3627 * @brief Returns the @p p parameter of the distribution.
3631 { return _M_param
.p(); }
3634 * @brief Returns the parameter set of the distribution.
3638 { return _M_param
; }
3641 * @brief Sets the parameter set of the distribution.
3642 * @param __param The new parameter set of the distribution.
3645 param(const param_type
& __param
)
3646 { _M_param
= __param
; }
3649 * @brief Returns the greatest lower bound value of the distribution.
3653 { return std::numeric_limits
<result_type
>::min(); }
3656 * @brief Returns the least upper bound value of the distribution.
3660 { return std::numeric_limits
<result_type
>::max(); }
3663 * @brief Generating functions.
3665 template<typename _UniformRandomNumberGenerator
>
3667 operator()(_UniformRandomNumberGenerator
& __urng
)
3668 { return this->operator()(__urng
, _M_param
); }
3670 template<typename _UniformRandomNumberGenerator
>
3672 operator()(_UniformRandomNumberGenerator
& __urng
,
3673 const param_type
& __p
)
3675 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
3677 if ((__aurng() - __aurng
.min())
3678 < __p
.p() * (__aurng
.max() - __aurng
.min()))
3683 template<typename _ForwardIterator
,
3684 typename _UniformRandomNumberGenerator
>
3686 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3687 _UniformRandomNumberGenerator
& __urng
)
3688 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3690 template<typename _ForwardIterator
,
3691 typename _UniformRandomNumberGenerator
>
3693 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3694 _UniformRandomNumberGenerator
& __urng
, const param_type
& __p
)
3695 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3697 template<typename _UniformRandomNumberGenerator
>
3699 __generate(result_type
* __f
, result_type
* __t
,
3700 _UniformRandomNumberGenerator
& __urng
,
3701 const param_type
& __p
)
3702 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3705 * @brief Return true if two Bernoulli distributions have
3706 * the same parameters.
3709 operator==(const bernoulli_distribution
& __d1
,
3710 const bernoulli_distribution
& __d2
)
3711 { return __d1
._M_param
== __d2
._M_param
; }
3714 template<typename _ForwardIterator
,
3715 typename _UniformRandomNumberGenerator
>
3717 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3718 _UniformRandomNumberGenerator
& __urng
,
3719 const param_type
& __p
);
3721 param_type _M_param
;
3725 * @brief Return true if two Bernoulli distributions have
3726 * different parameters.
3729 operator!=(const std::bernoulli_distribution
& __d1
,
3730 const std::bernoulli_distribution
& __d2
)
3731 { return !(__d1
== __d2
); }
3734 * @brief Inserts a %bernoulli_distribution random number distribution
3735 * @p __x into the output stream @p __os.
3737 * @param __os An output stream.
3738 * @param __x A %bernoulli_distribution random number distribution.
3740 * @returns The output stream with the state of @p __x inserted or in
3743 template<typename _CharT
, typename _Traits
>
3744 std::basic_ostream
<_CharT
, _Traits
>&
3745 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3746 const std::bernoulli_distribution
& __x
);
3749 * @brief Extracts a %bernoulli_distribution random number distribution
3750 * @p __x from the input stream @p __is.
3752 * @param __is An input stream.
3753 * @param __x A %bernoulli_distribution random number generator engine.
3755 * @returns The input stream with @p __x extracted or in an error state.
3757 template<typename _CharT
, typename _Traits
>
3758 std::basic_istream
<_CharT
, _Traits
>&
3759 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3760 std::bernoulli_distribution
& __x
)
3764 __x
.param(bernoulli_distribution::param_type(__p
));
3770 * @brief A discrete binomial random number distribution.
3772 * The formula for the binomial probability density function is
3773 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3774 * and @f$p@f$ are the parameters of the distribution.
3776 template<typename _IntType
= int>
3777 class binomial_distribution
3779 static_assert(std::is_integral
<_IntType
>::value
,
3780 "template argument not an integral type");
3783 /** The type of the range of the distribution. */
3784 typedef _IntType result_type
;
3785 /** Parameter type. */
3788 typedef binomial_distribution
<_IntType
> distribution_type
;
3789 friend class binomial_distribution
<_IntType
>;
3792 param_type(_IntType __t
= _IntType(1), double __p
= 0.5)
3793 : _M_t(__t
), _M_p(__p
)
3795 _GLIBCXX_DEBUG_ASSERT((_M_t
>= _IntType(0))
3810 operator==(const param_type
& __p1
, const param_type
& __p2
)
3811 { return __p1
._M_t
== __p2
._M_t
&& __p1
._M_p
== __p2
._M_p
; }
3821 #if _GLIBCXX_USE_C99_MATH_TR1
3822 double _M_d1
, _M_d2
, _M_s1
, _M_s2
, _M_c
,
3823 _M_a1
, _M_a123
, _M_s
, _M_lf
, _M_lp1p
;
3828 // constructors and member function
3830 binomial_distribution(_IntType __t
= _IntType(1),
3832 : _M_param(__t
, __p
), _M_nd()
3836 binomial_distribution(const param_type
& __p
)
3837 : _M_param(__p
), _M_nd()
3841 * @brief Resets the distribution state.
3848 * @brief Returns the distribution @p t parameter.
3852 { return _M_param
.t(); }
3855 * @brief Returns the distribution @p p parameter.
3859 { return _M_param
.p(); }
3862 * @brief Returns the parameter set of the distribution.
3866 { return _M_param
; }
3869 * @brief Sets the parameter set of the distribution.
3870 * @param __param The new parameter set of the distribution.
3873 param(const param_type
& __param
)
3874 { _M_param
= __param
; }
3877 * @brief Returns the greatest lower bound value of the distribution.
3884 * @brief Returns the least upper bound value of the distribution.
3888 { return _M_param
.t(); }
3891 * @brief Generating functions.
3893 template<typename _UniformRandomNumberGenerator
>
3895 operator()(_UniformRandomNumberGenerator
& __urng
)
3896 { return this->operator()(__urng
, _M_param
); }
3898 template<typename _UniformRandomNumberGenerator
>
3900 operator()(_UniformRandomNumberGenerator
& __urng
,
3901 const param_type
& __p
);
3903 template<typename _ForwardIterator
,
3904 typename _UniformRandomNumberGenerator
>
3906 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3907 _UniformRandomNumberGenerator
& __urng
)
3908 { this->__generate(__f
, __t
, __urng
, _M_param
); }
3910 template<typename _ForwardIterator
,
3911 typename _UniformRandomNumberGenerator
>
3913 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
3914 _UniformRandomNumberGenerator
& __urng
,
3915 const param_type
& __p
)
3916 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3918 template<typename _UniformRandomNumberGenerator
>
3920 __generate(result_type
* __f
, result_type
* __t
,
3921 _UniformRandomNumberGenerator
& __urng
,
3922 const param_type
& __p
)
3923 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
3926 * @brief Return true if two binomial distributions have
3927 * the same parameters and the sequences that would
3928 * be generated are equal.
3931 operator==(const binomial_distribution
& __d1
,
3932 const binomial_distribution
& __d2
)
3933 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3934 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
3936 { return __d1
._M_param
== __d2
._M_param
; }
3940 * @brief Inserts a %binomial_distribution random number distribution
3941 * @p __x into the output stream @p __os.
3943 * @param __os An output stream.
3944 * @param __x A %binomial_distribution random number distribution.
3946 * @returns The output stream with the state of @p __x inserted or in
3949 template<typename _IntType1
,
3950 typename _CharT
, typename _Traits
>
3951 friend std::basic_ostream
<_CharT
, _Traits
>&
3952 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
3953 const std::binomial_distribution
<_IntType1
>& __x
);
3956 * @brief Extracts a %binomial_distribution random number distribution
3957 * @p __x from the input stream @p __is.
3959 * @param __is An input stream.
3960 * @param __x A %binomial_distribution random number generator engine.
3962 * @returns The input stream with @p __x extracted or in an error
3965 template<typename _IntType1
,
3966 typename _CharT
, typename _Traits
>
3967 friend std::basic_istream
<_CharT
, _Traits
>&
3968 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
3969 std::binomial_distribution
<_IntType1
>& __x
);
3972 template<typename _ForwardIterator
,
3973 typename _UniformRandomNumberGenerator
>
3975 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
3976 _UniformRandomNumberGenerator
& __urng
,
3977 const param_type
& __p
);
3979 template<typename _UniformRandomNumberGenerator
>
3981 _M_waiting(_UniformRandomNumberGenerator
& __urng
,
3982 _IntType __t
, double __q
);
3984 param_type _M_param
;
3986 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3987 std::normal_distribution
<double> _M_nd
;
3991 * @brief Return true if two binomial distributions are different.
3993 template<typename _IntType
>
3995 operator!=(const std::binomial_distribution
<_IntType
>& __d1
,
3996 const std::binomial_distribution
<_IntType
>& __d2
)
3997 { return !(__d1
== __d2
); }
4001 * @brief A discrete geometric random number distribution.
4003 * The formula for the geometric probability density function is
4004 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
4007 template<typename _IntType
= int>
4008 class geometric_distribution
4010 static_assert(std::is_integral
<_IntType
>::value
,
4011 "template argument not an integral type");
4014 /** The type of the range of the distribution. */
4015 typedef _IntType result_type
;
4016 /** Parameter type. */
4019 typedef geometric_distribution
<_IntType
> distribution_type
;
4020 friend class geometric_distribution
<_IntType
>;
4023 param_type(double __p
= 0.5)
4026 _GLIBCXX_DEBUG_ASSERT((_M_p
> 0.0) && (_M_p
< 1.0));
4035 operator==(const param_type
& __p1
, const param_type
& __p2
)
4036 { return __p1
._M_p
== __p2
._M_p
; }
4041 { _M_log_1_p
= std::log(1.0 - _M_p
); }
4048 // constructors and member function
4050 geometric_distribution(double __p
= 0.5)
4055 geometric_distribution(const param_type
& __p
)
4060 * @brief Resets the distribution state.
4062 * Does nothing for the geometric distribution.
4068 * @brief Returns the distribution parameter @p p.
4072 { return _M_param
.p(); }
4075 * @brief Returns the parameter set of the distribution.
4079 { return _M_param
; }
4082 * @brief Sets the parameter set of the distribution.
4083 * @param __param The new parameter set of the distribution.
4086 param(const param_type
& __param
)
4087 { _M_param
= __param
; }
4090 * @brief Returns the greatest lower bound value of the distribution.
4097 * @brief Returns the least upper bound value of the distribution.
4101 { return std::numeric_limits
<result_type
>::max(); }
4104 * @brief Generating functions.
4106 template<typename _UniformRandomNumberGenerator
>
4108 operator()(_UniformRandomNumberGenerator
& __urng
)
4109 { return this->operator()(__urng
, _M_param
); }
4111 template<typename _UniformRandomNumberGenerator
>
4113 operator()(_UniformRandomNumberGenerator
& __urng
,
4114 const param_type
& __p
);
4116 template<typename _ForwardIterator
,
4117 typename _UniformRandomNumberGenerator
>
4119 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4120 _UniformRandomNumberGenerator
& __urng
)
4121 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4123 template<typename _ForwardIterator
,
4124 typename _UniformRandomNumberGenerator
>
4126 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4127 _UniformRandomNumberGenerator
& __urng
,
4128 const param_type
& __p
)
4129 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4131 template<typename _UniformRandomNumberGenerator
>
4133 __generate(result_type
* __f
, result_type
* __t
,
4134 _UniformRandomNumberGenerator
& __urng
,
4135 const param_type
& __p
)
4136 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4139 * @brief Return true if two geometric distributions have
4140 * the same parameters.
4143 operator==(const geometric_distribution
& __d1
,
4144 const geometric_distribution
& __d2
)
4145 { return __d1
._M_param
== __d2
._M_param
; }
4148 template<typename _ForwardIterator
,
4149 typename _UniformRandomNumberGenerator
>
4151 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4152 _UniformRandomNumberGenerator
& __urng
,
4153 const param_type
& __p
);
4155 param_type _M_param
;
4159 * @brief Return true if two geometric distributions have
4160 * different parameters.
4162 template<typename _IntType
>
4164 operator!=(const std::geometric_distribution
<_IntType
>& __d1
,
4165 const std::geometric_distribution
<_IntType
>& __d2
)
4166 { return !(__d1
== __d2
); }
4169 * @brief Inserts a %geometric_distribution random number distribution
4170 * @p __x into the output stream @p __os.
4172 * @param __os An output stream.
4173 * @param __x A %geometric_distribution random number distribution.
4175 * @returns The output stream with the state of @p __x inserted or in
4178 template<typename _IntType
,
4179 typename _CharT
, typename _Traits
>
4180 std::basic_ostream
<_CharT
, _Traits
>&
4181 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4182 const std::geometric_distribution
<_IntType
>& __x
);
4185 * @brief Extracts a %geometric_distribution random number distribution
4186 * @p __x from the input stream @p __is.
4188 * @param __is An input stream.
4189 * @param __x A %geometric_distribution random number generator engine.
4191 * @returns The input stream with @p __x extracted or in an error state.
4193 template<typename _IntType
,
4194 typename _CharT
, typename _Traits
>
4195 std::basic_istream
<_CharT
, _Traits
>&
4196 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4197 std::geometric_distribution
<_IntType
>& __x
);
4201 * @brief A negative_binomial_distribution random number distribution.
4203 * The formula for the negative binomial probability mass function is
4204 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4205 * and @f$p@f$ are the parameters of the distribution.
4207 template<typename _IntType
= int>
4208 class negative_binomial_distribution
4210 static_assert(std::is_integral
<_IntType
>::value
,
4211 "template argument not an integral type");
4214 /** The type of the range of the distribution. */
4215 typedef _IntType result_type
;
4216 /** Parameter type. */
4219 typedef negative_binomial_distribution
<_IntType
> distribution_type
;
4222 param_type(_IntType __k
= 1, double __p
= 0.5)
4223 : _M_k(__k
), _M_p(__p
)
4225 _GLIBCXX_DEBUG_ASSERT((_M_k
> 0) && (_M_p
> 0.0) && (_M_p
<= 1.0));
4237 operator==(const param_type
& __p1
, const param_type
& __p2
)
4238 { return __p1
._M_k
== __p2
._M_k
&& __p1
._M_p
== __p2
._M_p
; }
4246 negative_binomial_distribution(_IntType __k
= 1, double __p
= 0.5)
4247 : _M_param(__k
, __p
), _M_gd(__k
, (1.0 - __p
) / __p
)
4251 negative_binomial_distribution(const param_type
& __p
)
4252 : _M_param(__p
), _M_gd(__p
.k(), (1.0 - __p
.p()) / __p
.p())
4256 * @brief Resets the distribution state.
4263 * @brief Return the @f$k@f$ parameter of the distribution.
4267 { return _M_param
.k(); }
4270 * @brief Return the @f$p@f$ parameter of the distribution.
4274 { return _M_param
.p(); }
4277 * @brief Returns the parameter set of the distribution.
4281 { return _M_param
; }
4284 * @brief Sets the parameter set of the distribution.
4285 * @param __param The new parameter set of the distribution.
4288 param(const param_type
& __param
)
4289 { _M_param
= __param
; }
4292 * @brief Returns the greatest lower bound value of the distribution.
4296 { return result_type(0); }
4299 * @brief Returns the least upper bound value of the distribution.
4303 { return std::numeric_limits
<result_type
>::max(); }
4306 * @brief Generating functions.
4308 template<typename _UniformRandomNumberGenerator
>
4310 operator()(_UniformRandomNumberGenerator
& __urng
);
4312 template<typename _UniformRandomNumberGenerator
>
4314 operator()(_UniformRandomNumberGenerator
& __urng
,
4315 const param_type
& __p
);
4317 template<typename _ForwardIterator
,
4318 typename _UniformRandomNumberGenerator
>
4320 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4321 _UniformRandomNumberGenerator
& __urng
)
4322 { this->__generate_impl(__f
, __t
, __urng
); }
4324 template<typename _ForwardIterator
,
4325 typename _UniformRandomNumberGenerator
>
4327 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4328 _UniformRandomNumberGenerator
& __urng
,
4329 const param_type
& __p
)
4330 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4332 template<typename _UniformRandomNumberGenerator
>
4334 __generate(result_type
* __f
, result_type
* __t
,
4335 _UniformRandomNumberGenerator
& __urng
)
4336 { this->__generate_impl(__f
, __t
, __urng
); }
4338 template<typename _UniformRandomNumberGenerator
>
4340 __generate(result_type
* __f
, result_type
* __t
,
4341 _UniformRandomNumberGenerator
& __urng
,
4342 const param_type
& __p
)
4343 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4346 * @brief Return true if two negative binomial distributions have
4347 * the same parameters and the sequences that would be
4348 * generated are equal.
4351 operator==(const negative_binomial_distribution
& __d1
,
4352 const negative_binomial_distribution
& __d2
)
4353 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_gd
== __d2
._M_gd
; }
4356 * @brief Inserts a %negative_binomial_distribution random
4357 * number distribution @p __x into the output stream @p __os.
4359 * @param __os An output stream.
4360 * @param __x A %negative_binomial_distribution random number
4363 * @returns The output stream with the state of @p __x inserted or in
4366 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4367 friend std::basic_ostream
<_CharT
, _Traits
>&
4368 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4369 const std::negative_binomial_distribution
<_IntType1
>& __x
);
4372 * @brief Extracts a %negative_binomial_distribution random number
4373 * distribution @p __x from the input stream @p __is.
4375 * @param __is An input stream.
4376 * @param __x A %negative_binomial_distribution random number
4379 * @returns The input stream with @p __x extracted or in an error state.
4381 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4382 friend std::basic_istream
<_CharT
, _Traits
>&
4383 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4384 std::negative_binomial_distribution
<_IntType1
>& __x
);
4387 template<typename _ForwardIterator
,
4388 typename _UniformRandomNumberGenerator
>
4390 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4391 _UniformRandomNumberGenerator
& __urng
);
4392 template<typename _ForwardIterator
,
4393 typename _UniformRandomNumberGenerator
>
4395 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4396 _UniformRandomNumberGenerator
& __urng
,
4397 const param_type
& __p
);
4399 param_type _M_param
;
4401 std::gamma_distribution
<double> _M_gd
;
4405 * @brief Return true if two negative binomial distributions are different.
4407 template<typename _IntType
>
4409 operator!=(const std::negative_binomial_distribution
<_IntType
>& __d1
,
4410 const std::negative_binomial_distribution
<_IntType
>& __d2
)
4411 { return !(__d1
== __d2
); }
4414 /* @} */ // group random_distributions_bernoulli
4417 * @addtogroup random_distributions_poisson Poisson Distributions
4418 * @ingroup random_distributions
4423 * @brief A discrete Poisson random number distribution.
4425 * The formula for the Poisson probability density function is
4426 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4427 * parameter of the distribution.
4429 template<typename _IntType
= int>
4430 class poisson_distribution
4432 static_assert(std::is_integral
<_IntType
>::value
,
4433 "template argument not an integral type");
4436 /** The type of the range of the distribution. */
4437 typedef _IntType result_type
;
4438 /** Parameter type. */
4441 typedef poisson_distribution
<_IntType
> distribution_type
;
4442 friend class poisson_distribution
<_IntType
>;
4445 param_type(double __mean
= 1.0)
4448 _GLIBCXX_DEBUG_ASSERT(_M_mean
> 0.0);
4457 operator==(const param_type
& __p1
, const param_type
& __p2
)
4458 { return __p1
._M_mean
== __p2
._M_mean
; }
4461 // Hosts either log(mean) or the threshold of the simple method.
4468 #if _GLIBCXX_USE_C99_MATH_TR1
4469 double _M_lfm
, _M_sm
, _M_d
, _M_scx
, _M_1cx
, _M_c2b
, _M_cb
;
4473 // constructors and member function
4475 poisson_distribution(double __mean
= 1.0)
4476 : _M_param(__mean
), _M_nd()
4480 poisson_distribution(const param_type
& __p
)
4481 : _M_param(__p
), _M_nd()
4485 * @brief Resets the distribution state.
4492 * @brief Returns the distribution parameter @p mean.
4496 { return _M_param
.mean(); }
4499 * @brief Returns the parameter set of the distribution.
4503 { return _M_param
; }
4506 * @brief Sets the parameter set of the distribution.
4507 * @param __param The new parameter set of the distribution.
4510 param(const param_type
& __param
)
4511 { _M_param
= __param
; }
4514 * @brief Returns the greatest lower bound value of the distribution.
4521 * @brief Returns the least upper bound value of the distribution.
4525 { return std::numeric_limits
<result_type
>::max(); }
4528 * @brief Generating functions.
4530 template<typename _UniformRandomNumberGenerator
>
4532 operator()(_UniformRandomNumberGenerator
& __urng
)
4533 { return this->operator()(__urng
, _M_param
); }
4535 template<typename _UniformRandomNumberGenerator
>
4537 operator()(_UniformRandomNumberGenerator
& __urng
,
4538 const param_type
& __p
);
4540 template<typename _ForwardIterator
,
4541 typename _UniformRandomNumberGenerator
>
4543 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4544 _UniformRandomNumberGenerator
& __urng
)
4545 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4547 template<typename _ForwardIterator
,
4548 typename _UniformRandomNumberGenerator
>
4550 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4551 _UniformRandomNumberGenerator
& __urng
,
4552 const param_type
& __p
)
4553 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4555 template<typename _UniformRandomNumberGenerator
>
4557 __generate(result_type
* __f
, result_type
* __t
,
4558 _UniformRandomNumberGenerator
& __urng
,
4559 const param_type
& __p
)
4560 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4563 * @brief Return true if two Poisson distributions have the same
4564 * parameters and the sequences that would be generated
4568 operator==(const poisson_distribution
& __d1
,
4569 const poisson_distribution
& __d2
)
4570 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4571 { return __d1
._M_param
== __d2
._M_param
&& __d1
._M_nd
== __d2
._M_nd
; }
4573 { return __d1
._M_param
== __d2
._M_param
; }
4577 * @brief Inserts a %poisson_distribution random number distribution
4578 * @p __x into the output stream @p __os.
4580 * @param __os An output stream.
4581 * @param __x A %poisson_distribution random number distribution.
4583 * @returns The output stream with the state of @p __x inserted or in
4586 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4587 friend std::basic_ostream
<_CharT
, _Traits
>&
4588 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4589 const std::poisson_distribution
<_IntType1
>& __x
);
4592 * @brief Extracts a %poisson_distribution random number distribution
4593 * @p __x from the input stream @p __is.
4595 * @param __is An input stream.
4596 * @param __x A %poisson_distribution random number generator engine.
4598 * @returns The input stream with @p __x extracted or in an error
4601 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4602 friend std::basic_istream
<_CharT
, _Traits
>&
4603 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4604 std::poisson_distribution
<_IntType1
>& __x
);
4607 template<typename _ForwardIterator
,
4608 typename _UniformRandomNumberGenerator
>
4610 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4611 _UniformRandomNumberGenerator
& __urng
,
4612 const param_type
& __p
);
4614 param_type _M_param
;
4616 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4617 std::normal_distribution
<double> _M_nd
;
4621 * @brief Return true if two Poisson distributions are different.
4623 template<typename _IntType
>
4625 operator!=(const std::poisson_distribution
<_IntType
>& __d1
,
4626 const std::poisson_distribution
<_IntType
>& __d2
)
4627 { return !(__d1
== __d2
); }
4631 * @brief An exponential continuous distribution for random numbers.
4633 * The formula for the exponential probability density function is
4634 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4636 * <table border=1 cellpadding=10 cellspacing=0>
4637 * <caption align=top>Distribution Statistics</caption>
4638 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4639 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4640 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4641 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4642 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4645 template<typename _RealType
= double>
4646 class exponential_distribution
4648 static_assert(std::is_floating_point
<_RealType
>::value
,
4649 "template argument not a floating point type");
4652 /** The type of the range of the distribution. */
4653 typedef _RealType result_type
;
4654 /** Parameter type. */
4657 typedef exponential_distribution
<_RealType
> distribution_type
;
4660 param_type(_RealType __lambda
= _RealType(1))
4661 : _M_lambda(__lambda
)
4663 _GLIBCXX_DEBUG_ASSERT(_M_lambda
> _RealType(0));
4668 { return _M_lambda
; }
4671 operator==(const param_type
& __p1
, const param_type
& __p2
)
4672 { return __p1
._M_lambda
== __p2
._M_lambda
; }
4675 _RealType _M_lambda
;
4680 * @brief Constructs an exponential distribution with inverse scale
4681 * parameter @f$\lambda@f$.
4684 exponential_distribution(const result_type
& __lambda
= result_type(1))
4685 : _M_param(__lambda
)
4689 exponential_distribution(const param_type
& __p
)
4694 * @brief Resets the distribution state.
4696 * Has no effect on exponential distributions.
4702 * @brief Returns the inverse scale parameter of the distribution.
4706 { return _M_param
.lambda(); }
4709 * @brief Returns the parameter set of the distribution.
4713 { return _M_param
; }
4716 * @brief Sets the parameter set of the distribution.
4717 * @param __param The new parameter set of the distribution.
4720 param(const param_type
& __param
)
4721 { _M_param
= __param
; }
4724 * @brief Returns the greatest lower bound value of the distribution.
4728 { return result_type(0); }
4731 * @brief Returns the least upper bound value of the distribution.
4735 { return std::numeric_limits
<result_type
>::max(); }
4738 * @brief Generating functions.
4740 template<typename _UniformRandomNumberGenerator
>
4742 operator()(_UniformRandomNumberGenerator
& __urng
)
4743 { return this->operator()(__urng
, _M_param
); }
4745 template<typename _UniformRandomNumberGenerator
>
4747 operator()(_UniformRandomNumberGenerator
& __urng
,
4748 const param_type
& __p
)
4750 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
4752 return -std::log(result_type(1) - __aurng()) / __p
.lambda();
4755 template<typename _ForwardIterator
,
4756 typename _UniformRandomNumberGenerator
>
4758 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4759 _UniformRandomNumberGenerator
& __urng
)
4760 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4762 template<typename _ForwardIterator
,
4763 typename _UniformRandomNumberGenerator
>
4765 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4766 _UniformRandomNumberGenerator
& __urng
,
4767 const param_type
& __p
)
4768 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4770 template<typename _UniformRandomNumberGenerator
>
4772 __generate(result_type
* __f
, result_type
* __t
,
4773 _UniformRandomNumberGenerator
& __urng
,
4774 const param_type
& __p
)
4775 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4778 * @brief Return true if two exponential distributions have the same
4782 operator==(const exponential_distribution
& __d1
,
4783 const exponential_distribution
& __d2
)
4784 { return __d1
._M_param
== __d2
._M_param
; }
4787 template<typename _ForwardIterator
,
4788 typename _UniformRandomNumberGenerator
>
4790 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4791 _UniformRandomNumberGenerator
& __urng
,
4792 const param_type
& __p
);
4794 param_type _M_param
;
4798 * @brief Return true if two exponential distributions have different
4801 template<typename _RealType
>
4803 operator!=(const std::exponential_distribution
<_RealType
>& __d1
,
4804 const std::exponential_distribution
<_RealType
>& __d2
)
4805 { return !(__d1
== __d2
); }
4808 * @brief Inserts a %exponential_distribution random number distribution
4809 * @p __x into the output stream @p __os.
4811 * @param __os An output stream.
4812 * @param __x A %exponential_distribution random number distribution.
4814 * @returns The output stream with the state of @p __x inserted or in
4817 template<typename _RealType
, typename _CharT
, typename _Traits
>
4818 std::basic_ostream
<_CharT
, _Traits
>&
4819 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
4820 const std::exponential_distribution
<_RealType
>& __x
);
4823 * @brief Extracts a %exponential_distribution random number distribution
4824 * @p __x from the input stream @p __is.
4826 * @param __is An input stream.
4827 * @param __x A %exponential_distribution random number
4830 * @returns The input stream with @p __x extracted or in an error state.
4832 template<typename _RealType
, typename _CharT
, typename _Traits
>
4833 std::basic_istream
<_CharT
, _Traits
>&
4834 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
4835 std::exponential_distribution
<_RealType
>& __x
);
4839 * @brief A weibull_distribution random number distribution.
4841 * The formula for the normal probability density function is:
4843 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4844 * \exp{(-(\frac{x}{\beta})^\alpha)}
4847 template<typename _RealType
= double>
4848 class weibull_distribution
4850 static_assert(std::is_floating_point
<_RealType
>::value
,
4851 "template argument not a floating point type");
4854 /** The type of the range of the distribution. */
4855 typedef _RealType result_type
;
4856 /** Parameter type. */
4859 typedef weibull_distribution
<_RealType
> distribution_type
;
4862 param_type(_RealType __a
= _RealType(1),
4863 _RealType __b
= _RealType(1))
4864 : _M_a(__a
), _M_b(__b
)
4876 operator==(const param_type
& __p1
, const param_type
& __p2
)
4877 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
4885 weibull_distribution(_RealType __a
= _RealType(1),
4886 _RealType __b
= _RealType(1))
4887 : _M_param(__a
, __b
)
4891 weibull_distribution(const param_type
& __p
)
4896 * @brief Resets the distribution state.
4903 * @brief Return the @f$a@f$ parameter of the distribution.
4907 { return _M_param
.a(); }
4910 * @brief Return the @f$b@f$ parameter of the distribution.
4914 { return _M_param
.b(); }
4917 * @brief Returns the parameter set of the distribution.
4921 { return _M_param
; }
4924 * @brief Sets the parameter set of the distribution.
4925 * @param __param The new parameter set of the distribution.
4928 param(const param_type
& __param
)
4929 { _M_param
= __param
; }
4932 * @brief Returns the greatest lower bound value of the distribution.
4936 { return result_type(0); }
4939 * @brief Returns the least upper bound value of the distribution.
4943 { return std::numeric_limits
<result_type
>::max(); }
4946 * @brief Generating functions.
4948 template<typename _UniformRandomNumberGenerator
>
4950 operator()(_UniformRandomNumberGenerator
& __urng
)
4951 { return this->operator()(__urng
, _M_param
); }
4953 template<typename _UniformRandomNumberGenerator
>
4955 operator()(_UniformRandomNumberGenerator
& __urng
,
4956 const param_type
& __p
);
4958 template<typename _ForwardIterator
,
4959 typename _UniformRandomNumberGenerator
>
4961 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4962 _UniformRandomNumberGenerator
& __urng
)
4963 { this->__generate(__f
, __t
, __urng
, _M_param
); }
4965 template<typename _ForwardIterator
,
4966 typename _UniformRandomNumberGenerator
>
4968 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
4969 _UniformRandomNumberGenerator
& __urng
,
4970 const param_type
& __p
)
4971 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4973 template<typename _UniformRandomNumberGenerator
>
4975 __generate(result_type
* __f
, result_type
* __t
,
4976 _UniformRandomNumberGenerator
& __urng
,
4977 const param_type
& __p
)
4978 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
4981 * @brief Return true if two Weibull distributions have the same
4985 operator==(const weibull_distribution
& __d1
,
4986 const weibull_distribution
& __d2
)
4987 { return __d1
._M_param
== __d2
._M_param
; }
4990 template<typename _ForwardIterator
,
4991 typename _UniformRandomNumberGenerator
>
4993 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
4994 _UniformRandomNumberGenerator
& __urng
,
4995 const param_type
& __p
);
4997 param_type _M_param
;
5001 * @brief Return true if two Weibull distributions have different
5004 template<typename _RealType
>
5006 operator!=(const std::weibull_distribution
<_RealType
>& __d1
,
5007 const std::weibull_distribution
<_RealType
>& __d2
)
5008 { return !(__d1
== __d2
); }
5011 * @brief Inserts a %weibull_distribution random number distribution
5012 * @p __x into the output stream @p __os.
5014 * @param __os An output stream.
5015 * @param __x A %weibull_distribution random number distribution.
5017 * @returns The output stream with the state of @p __x inserted or in
5020 template<typename _RealType
, typename _CharT
, typename _Traits
>
5021 std::basic_ostream
<_CharT
, _Traits
>&
5022 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5023 const std::weibull_distribution
<_RealType
>& __x
);
5026 * @brief Extracts a %weibull_distribution random number distribution
5027 * @p __x from the input stream @p __is.
5029 * @param __is An input stream.
5030 * @param __x A %weibull_distribution random number
5033 * @returns The input stream with @p __x extracted or in an error state.
5035 template<typename _RealType
, typename _CharT
, typename _Traits
>
5036 std::basic_istream
<_CharT
, _Traits
>&
5037 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5038 std::weibull_distribution
<_RealType
>& __x
);
5042 * @brief A extreme_value_distribution random number distribution.
5044 * The formula for the normal probability mass function is
5046 * p(x|a,b) = \frac{1}{b}
5047 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5050 template<typename _RealType
= double>
5051 class extreme_value_distribution
5053 static_assert(std::is_floating_point
<_RealType
>::value
,
5054 "template argument not a floating point type");
5057 /** The type of the range of the distribution. */
5058 typedef _RealType result_type
;
5059 /** Parameter type. */
5062 typedef extreme_value_distribution
<_RealType
> distribution_type
;
5065 param_type(_RealType __a
= _RealType(0),
5066 _RealType __b
= _RealType(1))
5067 : _M_a(__a
), _M_b(__b
)
5079 operator==(const param_type
& __p1
, const param_type
& __p2
)
5080 { return __p1
._M_a
== __p2
._M_a
&& __p1
._M_b
== __p2
._M_b
; }
5088 extreme_value_distribution(_RealType __a
= _RealType(0),
5089 _RealType __b
= _RealType(1))
5090 : _M_param(__a
, __b
)
5094 extreme_value_distribution(const param_type
& __p
)
5099 * @brief Resets the distribution state.
5106 * @brief Return the @f$a@f$ parameter of the distribution.
5110 { return _M_param
.a(); }
5113 * @brief Return the @f$b@f$ parameter of the distribution.
5117 { return _M_param
.b(); }
5120 * @brief Returns the parameter set of the distribution.
5124 { return _M_param
; }
5127 * @brief Sets the parameter set of the distribution.
5128 * @param __param The new parameter set of the distribution.
5131 param(const param_type
& __param
)
5132 { _M_param
= __param
; }
5135 * @brief Returns the greatest lower bound value of the distribution.
5139 { return std::numeric_limits
<result_type
>::lowest(); }
5142 * @brief Returns the least upper bound value of the distribution.
5146 { return std::numeric_limits
<result_type
>::max(); }
5149 * @brief Generating functions.
5151 template<typename _UniformRandomNumberGenerator
>
5153 operator()(_UniformRandomNumberGenerator
& __urng
)
5154 { return this->operator()(__urng
, _M_param
); }
5156 template<typename _UniformRandomNumberGenerator
>
5158 operator()(_UniformRandomNumberGenerator
& __urng
,
5159 const param_type
& __p
);
5161 template<typename _ForwardIterator
,
5162 typename _UniformRandomNumberGenerator
>
5164 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5165 _UniformRandomNumberGenerator
& __urng
)
5166 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5168 template<typename _ForwardIterator
,
5169 typename _UniformRandomNumberGenerator
>
5171 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5172 _UniformRandomNumberGenerator
& __urng
,
5173 const param_type
& __p
)
5174 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5176 template<typename _UniformRandomNumberGenerator
>
5178 __generate(result_type
* __f
, result_type
* __t
,
5179 _UniformRandomNumberGenerator
& __urng
,
5180 const param_type
& __p
)
5181 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5184 * @brief Return true if two extreme value distributions have the same
5188 operator==(const extreme_value_distribution
& __d1
,
5189 const extreme_value_distribution
& __d2
)
5190 { return __d1
._M_param
== __d2
._M_param
; }
5193 template<typename _ForwardIterator
,
5194 typename _UniformRandomNumberGenerator
>
5196 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5197 _UniformRandomNumberGenerator
& __urng
,
5198 const param_type
& __p
);
5200 param_type _M_param
;
5204 * @brief Return true if two extreme value distributions have different
5207 template<typename _RealType
>
5209 operator!=(const std::extreme_value_distribution
<_RealType
>& __d1
,
5210 const std::extreme_value_distribution
<_RealType
>& __d2
)
5211 { return !(__d1
== __d2
); }
5214 * @brief Inserts a %extreme_value_distribution random number distribution
5215 * @p __x into the output stream @p __os.
5217 * @param __os An output stream.
5218 * @param __x A %extreme_value_distribution random number distribution.
5220 * @returns The output stream with the state of @p __x inserted or in
5223 template<typename _RealType
, typename _CharT
, typename _Traits
>
5224 std::basic_ostream
<_CharT
, _Traits
>&
5225 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5226 const std::extreme_value_distribution
<_RealType
>& __x
);
5229 * @brief Extracts a %extreme_value_distribution random number
5230 * distribution @p __x from the input stream @p __is.
5232 * @param __is An input stream.
5233 * @param __x A %extreme_value_distribution random number
5236 * @returns The input stream with @p __x extracted or in an error state.
5238 template<typename _RealType
, typename _CharT
, typename _Traits
>
5239 std::basic_istream
<_CharT
, _Traits
>&
5240 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5241 std::extreme_value_distribution
<_RealType
>& __x
);
5245 * @brief A discrete_distribution random number distribution.
5247 * The formula for the discrete probability mass function is
5250 template<typename _IntType
= int>
5251 class discrete_distribution
5253 static_assert(std::is_integral
<_IntType
>::value
,
5254 "template argument not an integral type");
5257 /** The type of the range of the distribution. */
5258 typedef _IntType result_type
;
5259 /** Parameter type. */
5262 typedef discrete_distribution
<_IntType
> distribution_type
;
5263 friend class discrete_distribution
<_IntType
>;
5266 : _M_prob(), _M_cp()
5269 template<typename _InputIterator
>
5270 param_type(_InputIterator __wbegin
,
5271 _InputIterator __wend
)
5272 : _M_prob(__wbegin
, __wend
), _M_cp()
5273 { _M_initialize(); }
5275 param_type(initializer_list
<double> __wil
)
5276 : _M_prob(__wil
.begin(), __wil
.end()), _M_cp()
5277 { _M_initialize(); }
5279 template<typename _Func
>
5280 param_type(size_t __nw
, double __xmin
, double __xmax
,
5283 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5284 param_type(const param_type
&) = default;
5285 param_type
& operator=(const param_type
&) = default;
5288 probabilities() const
5289 { return _M_prob
.empty() ? std::vector
<double>(1, 1.0) : _M_prob
; }
5292 operator==(const param_type
& __p1
, const param_type
& __p2
)
5293 { return __p1
._M_prob
== __p2
._M_prob
; }
5299 std::vector
<double> _M_prob
;
5300 std::vector
<double> _M_cp
;
5303 discrete_distribution()
5307 template<typename _InputIterator
>
5308 discrete_distribution(_InputIterator __wbegin
,
5309 _InputIterator __wend
)
5310 : _M_param(__wbegin
, __wend
)
5313 discrete_distribution(initializer_list
<double> __wl
)
5317 template<typename _Func
>
5318 discrete_distribution(size_t __nw
, double __xmin
, double __xmax
,
5320 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5324 discrete_distribution(const param_type
& __p
)
5329 * @brief Resets the distribution state.
5336 * @brief Returns the probabilities of the distribution.
5339 probabilities() const
5341 return _M_param
._M_prob
.empty()
5342 ? std::vector
<double>(1, 1.0) : _M_param
._M_prob
;
5346 * @brief Returns the parameter set of the distribution.
5350 { return _M_param
; }
5353 * @brief Sets the parameter set of the distribution.
5354 * @param __param The new parameter set of the distribution.
5357 param(const param_type
& __param
)
5358 { _M_param
= __param
; }
5361 * @brief Returns the greatest lower bound value of the distribution.
5365 { return result_type(0); }
5368 * @brief Returns the least upper bound value of the distribution.
5373 return _M_param
._M_prob
.empty()
5374 ? result_type(0) : result_type(_M_param
._M_prob
.size() - 1);
5378 * @brief Generating functions.
5380 template<typename _UniformRandomNumberGenerator
>
5382 operator()(_UniformRandomNumberGenerator
& __urng
)
5383 { return this->operator()(__urng
, _M_param
); }
5385 template<typename _UniformRandomNumberGenerator
>
5387 operator()(_UniformRandomNumberGenerator
& __urng
,
5388 const param_type
& __p
);
5390 template<typename _ForwardIterator
,
5391 typename _UniformRandomNumberGenerator
>
5393 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5394 _UniformRandomNumberGenerator
& __urng
)
5395 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5397 template<typename _ForwardIterator
,
5398 typename _UniformRandomNumberGenerator
>
5400 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5401 _UniformRandomNumberGenerator
& __urng
,
5402 const param_type
& __p
)
5403 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5405 template<typename _UniformRandomNumberGenerator
>
5407 __generate(result_type
* __f
, result_type
* __t
,
5408 _UniformRandomNumberGenerator
& __urng
,
5409 const param_type
& __p
)
5410 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5413 * @brief Return true if two discrete distributions have the same
5417 operator==(const discrete_distribution
& __d1
,
5418 const discrete_distribution
& __d2
)
5419 { return __d1
._M_param
== __d2
._M_param
; }
5422 * @brief Inserts a %discrete_distribution random number distribution
5423 * @p __x into the output stream @p __os.
5425 * @param __os An output stream.
5426 * @param __x A %discrete_distribution random number distribution.
5428 * @returns The output stream with the state of @p __x inserted or in
5431 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5432 friend std::basic_ostream
<_CharT
, _Traits
>&
5433 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5434 const std::discrete_distribution
<_IntType1
>& __x
);
5437 * @brief Extracts a %discrete_distribution random number distribution
5438 * @p __x from the input stream @p __is.
5440 * @param __is An input stream.
5441 * @param __x A %discrete_distribution random number
5444 * @returns The input stream with @p __x extracted or in an error
5447 template<typename _IntType1
, typename _CharT
, typename _Traits
>
5448 friend std::basic_istream
<_CharT
, _Traits
>&
5449 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5450 std::discrete_distribution
<_IntType1
>& __x
);
5453 template<typename _ForwardIterator
,
5454 typename _UniformRandomNumberGenerator
>
5456 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5457 _UniformRandomNumberGenerator
& __urng
,
5458 const param_type
& __p
);
5460 param_type _M_param
;
5464 * @brief Return true if two discrete distributions have different
5467 template<typename _IntType
>
5469 operator!=(const std::discrete_distribution
<_IntType
>& __d1
,
5470 const std::discrete_distribution
<_IntType
>& __d2
)
5471 { return !(__d1
== __d2
); }
5475 * @brief A piecewise_constant_distribution random number distribution.
5477 * The formula for the piecewise constant probability mass function is
5480 template<typename _RealType
= double>
5481 class piecewise_constant_distribution
5483 static_assert(std::is_floating_point
<_RealType
>::value
,
5484 "template argument not a floating point type");
5487 /** The type of the range of the distribution. */
5488 typedef _RealType result_type
;
5489 /** Parameter type. */
5492 typedef piecewise_constant_distribution
<_RealType
> distribution_type
;
5493 friend class piecewise_constant_distribution
<_RealType
>;
5496 : _M_int(), _M_den(), _M_cp()
5499 template<typename _InputIteratorB
, typename _InputIteratorW
>
5500 param_type(_InputIteratorB __bfirst
,
5501 _InputIteratorB __bend
,
5502 _InputIteratorW __wbegin
);
5504 template<typename _Func
>
5505 param_type(initializer_list
<_RealType
> __bi
, _Func __fw
);
5507 template<typename _Func
>
5508 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5511 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5512 param_type(const param_type
&) = default;
5513 param_type
& operator=(const param_type
&) = default;
5515 std::vector
<_RealType
>
5520 std::vector
<_RealType
> __tmp(2);
5521 __tmp
[1] = _RealType(1);
5530 { return _M_den
.empty() ? std::vector
<double>(1, 1.0) : _M_den
; }
5533 operator==(const param_type
& __p1
, const param_type
& __p2
)
5534 { return __p1
._M_int
== __p2
._M_int
&& __p1
._M_den
== __p2
._M_den
; }
5540 std::vector
<_RealType
> _M_int
;
5541 std::vector
<double> _M_den
;
5542 std::vector
<double> _M_cp
;
5546 piecewise_constant_distribution()
5550 template<typename _InputIteratorB
, typename _InputIteratorW
>
5551 piecewise_constant_distribution(_InputIteratorB __bfirst
,
5552 _InputIteratorB __bend
,
5553 _InputIteratorW __wbegin
)
5554 : _M_param(__bfirst
, __bend
, __wbegin
)
5557 template<typename _Func
>
5558 piecewise_constant_distribution(initializer_list
<_RealType
> __bl
,
5560 : _M_param(__bl
, __fw
)
5563 template<typename _Func
>
5564 piecewise_constant_distribution(size_t __nw
,
5565 _RealType __xmin
, _RealType __xmax
,
5567 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5571 piecewise_constant_distribution(const param_type
& __p
)
5576 * @brief Resets the distribution state.
5583 * @brief Returns a vector of the intervals.
5585 std::vector
<_RealType
>
5588 if (_M_param
._M_int
.empty())
5590 std::vector
<_RealType
> __tmp(2);
5591 __tmp
[1] = _RealType(1);
5595 return _M_param
._M_int
;
5599 * @brief Returns a vector of the probability densities.
5604 return _M_param
._M_den
.empty()
5605 ? std::vector
<double>(1, 1.0) : _M_param
._M_den
;
5609 * @brief Returns the parameter set of the distribution.
5613 { return _M_param
; }
5616 * @brief Sets the parameter set of the distribution.
5617 * @param __param The new parameter set of the distribution.
5620 param(const param_type
& __param
)
5621 { _M_param
= __param
; }
5624 * @brief Returns the greatest lower bound value of the distribution.
5629 return _M_param
._M_int
.empty()
5630 ? result_type(0) : _M_param
._M_int
.front();
5634 * @brief Returns the least upper bound value of the distribution.
5639 return _M_param
._M_int
.empty()
5640 ? result_type(1) : _M_param
._M_int
.back();
5644 * @brief Generating functions.
5646 template<typename _UniformRandomNumberGenerator
>
5648 operator()(_UniformRandomNumberGenerator
& __urng
)
5649 { return this->operator()(__urng
, _M_param
); }
5651 template<typename _UniformRandomNumberGenerator
>
5653 operator()(_UniformRandomNumberGenerator
& __urng
,
5654 const param_type
& __p
);
5656 template<typename _ForwardIterator
,
5657 typename _UniformRandomNumberGenerator
>
5659 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5660 _UniformRandomNumberGenerator
& __urng
)
5661 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5663 template<typename _ForwardIterator
,
5664 typename _UniformRandomNumberGenerator
>
5666 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5667 _UniformRandomNumberGenerator
& __urng
,
5668 const param_type
& __p
)
5669 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5671 template<typename _UniformRandomNumberGenerator
>
5673 __generate(result_type
* __f
, result_type
* __t
,
5674 _UniformRandomNumberGenerator
& __urng
,
5675 const param_type
& __p
)
5676 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5679 * @brief Return true if two piecewise constant distributions have the
5683 operator==(const piecewise_constant_distribution
& __d1
,
5684 const piecewise_constant_distribution
& __d2
)
5685 { return __d1
._M_param
== __d2
._M_param
; }
5688 * @brief Inserts a %piecewise_constant_distribution random
5689 * number distribution @p __x into the output stream @p __os.
5691 * @param __os An output stream.
5692 * @param __x A %piecewise_constant_distribution random number
5695 * @returns The output stream with the state of @p __x inserted or in
5698 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5699 friend std::basic_ostream
<_CharT
, _Traits
>&
5700 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5701 const std::piecewise_constant_distribution
<_RealType1
>& __x
);
5704 * @brief Extracts a %piecewise_constant_distribution random
5705 * number distribution @p __x from the input stream @p __is.
5707 * @param __is An input stream.
5708 * @param __x A %piecewise_constant_distribution random number
5711 * @returns The input stream with @p __x extracted or in an error
5714 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5715 friend std::basic_istream
<_CharT
, _Traits
>&
5716 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5717 std::piecewise_constant_distribution
<_RealType1
>& __x
);
5720 template<typename _ForwardIterator
,
5721 typename _UniformRandomNumberGenerator
>
5723 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5724 _UniformRandomNumberGenerator
& __urng
,
5725 const param_type
& __p
);
5727 param_type _M_param
;
5731 * @brief Return true if two piecewise constant distributions have
5732 * different parameters.
5734 template<typename _RealType
>
5736 operator!=(const std::piecewise_constant_distribution
<_RealType
>& __d1
,
5737 const std::piecewise_constant_distribution
<_RealType
>& __d2
)
5738 { return !(__d1
== __d2
); }
5742 * @brief A piecewise_linear_distribution random number distribution.
5744 * The formula for the piecewise linear probability mass function is
5747 template<typename _RealType
= double>
5748 class piecewise_linear_distribution
5750 static_assert(std::is_floating_point
<_RealType
>::value
,
5751 "template argument not a floating point type");
5754 /** The type of the range of the distribution. */
5755 typedef _RealType result_type
;
5756 /** Parameter type. */
5759 typedef piecewise_linear_distribution
<_RealType
> distribution_type
;
5760 friend class piecewise_linear_distribution
<_RealType
>;
5763 : _M_int(), _M_den(), _M_cp(), _M_m()
5766 template<typename _InputIteratorB
, typename _InputIteratorW
>
5767 param_type(_InputIteratorB __bfirst
,
5768 _InputIteratorB __bend
,
5769 _InputIteratorW __wbegin
);
5771 template<typename _Func
>
5772 param_type(initializer_list
<_RealType
> __bl
, _Func __fw
);
5774 template<typename _Func
>
5775 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
5778 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5779 param_type(const param_type
&) = default;
5780 param_type
& operator=(const param_type
&) = default;
5782 std::vector
<_RealType
>
5787 std::vector
<_RealType
> __tmp(2);
5788 __tmp
[1] = _RealType(1);
5797 { return _M_den
.empty() ? std::vector
<double>(2, 1.0) : _M_den
; }
5800 operator==(const param_type
& __p1
, const param_type
& __p2
)
5801 { return (__p1
._M_int
== __p2
._M_int
5802 && __p1
._M_den
== __p2
._M_den
); }
5808 std::vector
<_RealType
> _M_int
;
5809 std::vector
<double> _M_den
;
5810 std::vector
<double> _M_cp
;
5811 std::vector
<double> _M_m
;
5815 piecewise_linear_distribution()
5819 template<typename _InputIteratorB
, typename _InputIteratorW
>
5820 piecewise_linear_distribution(_InputIteratorB __bfirst
,
5821 _InputIteratorB __bend
,
5822 _InputIteratorW __wbegin
)
5823 : _M_param(__bfirst
, __bend
, __wbegin
)
5826 template<typename _Func
>
5827 piecewise_linear_distribution(initializer_list
<_RealType
> __bl
,
5829 : _M_param(__bl
, __fw
)
5832 template<typename _Func
>
5833 piecewise_linear_distribution(size_t __nw
,
5834 _RealType __xmin
, _RealType __xmax
,
5836 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
5840 piecewise_linear_distribution(const param_type
& __p
)
5845 * Resets the distribution state.
5852 * @brief Return the intervals of the distribution.
5854 std::vector
<_RealType
>
5857 if (_M_param
._M_int
.empty())
5859 std::vector
<_RealType
> __tmp(2);
5860 __tmp
[1] = _RealType(1);
5864 return _M_param
._M_int
;
5868 * @brief Return a vector of the probability densities of the
5874 return _M_param
._M_den
.empty()
5875 ? std::vector
<double>(2, 1.0) : _M_param
._M_den
;
5879 * @brief Returns the parameter set of the distribution.
5883 { return _M_param
; }
5886 * @brief Sets the parameter set of the distribution.
5887 * @param __param The new parameter set of the distribution.
5890 param(const param_type
& __param
)
5891 { _M_param
= __param
; }
5894 * @brief Returns the greatest lower bound value of the distribution.
5899 return _M_param
._M_int
.empty()
5900 ? result_type(0) : _M_param
._M_int
.front();
5904 * @brief Returns the least upper bound value of the distribution.
5909 return _M_param
._M_int
.empty()
5910 ? result_type(1) : _M_param
._M_int
.back();
5914 * @brief Generating functions.
5916 template<typename _UniformRandomNumberGenerator
>
5918 operator()(_UniformRandomNumberGenerator
& __urng
)
5919 { return this->operator()(__urng
, _M_param
); }
5921 template<typename _UniformRandomNumberGenerator
>
5923 operator()(_UniformRandomNumberGenerator
& __urng
,
5924 const param_type
& __p
);
5926 template<typename _ForwardIterator
,
5927 typename _UniformRandomNumberGenerator
>
5929 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5930 _UniformRandomNumberGenerator
& __urng
)
5931 { this->__generate(__f
, __t
, __urng
, _M_param
); }
5933 template<typename _ForwardIterator
,
5934 typename _UniformRandomNumberGenerator
>
5936 __generate(_ForwardIterator __f
, _ForwardIterator __t
,
5937 _UniformRandomNumberGenerator
& __urng
,
5938 const param_type
& __p
)
5939 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5941 template<typename _UniformRandomNumberGenerator
>
5943 __generate(result_type
* __f
, result_type
* __t
,
5944 _UniformRandomNumberGenerator
& __urng
,
5945 const param_type
& __p
)
5946 { this->__generate_impl(__f
, __t
, __urng
, __p
); }
5949 * @brief Return true if two piecewise linear distributions have the
5953 operator==(const piecewise_linear_distribution
& __d1
,
5954 const piecewise_linear_distribution
& __d2
)
5955 { return __d1
._M_param
== __d2
._M_param
; }
5958 * @brief Inserts a %piecewise_linear_distribution random number
5959 * distribution @p __x into the output stream @p __os.
5961 * @param __os An output stream.
5962 * @param __x A %piecewise_linear_distribution random number
5965 * @returns The output stream with the state of @p __x inserted or in
5968 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5969 friend std::basic_ostream
<_CharT
, _Traits
>&
5970 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
5971 const std::piecewise_linear_distribution
<_RealType1
>& __x
);
5974 * @brief Extracts a %piecewise_linear_distribution random number
5975 * distribution @p __x from the input stream @p __is.
5977 * @param __is An input stream.
5978 * @param __x A %piecewise_linear_distribution random number
5981 * @returns The input stream with @p __x extracted or in an error
5984 template<typename _RealType1
, typename _CharT
, typename _Traits
>
5985 friend std::basic_istream
<_CharT
, _Traits
>&
5986 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
5987 std::piecewise_linear_distribution
<_RealType1
>& __x
);
5990 template<typename _ForwardIterator
,
5991 typename _UniformRandomNumberGenerator
>
5993 __generate_impl(_ForwardIterator __f
, _ForwardIterator __t
,
5994 _UniformRandomNumberGenerator
& __urng
,
5995 const param_type
& __p
);
5997 param_type _M_param
;
6001 * @brief Return true if two piecewise linear distributions have
6002 * different parameters.
6004 template<typename _RealType
>
6006 operator!=(const std::piecewise_linear_distribution
<_RealType
>& __d1
,
6007 const std::piecewise_linear_distribution
<_RealType
>& __d2
)
6008 { return !(__d1
== __d2
); }
6011 /* @} */ // group random_distributions_poisson
6013 /* @} */ // group random_distributions
6016 * @addtogroup random_utilities Random Number Utilities
6022 * @brief The seed_seq class generates sequences of seeds for random
6023 * number generators.
6029 /** The type of the seed vales. */
6030 typedef uint_least32_t result_type
;
6032 /** Default constructor. */
6037 template<typename _IntType
>
6038 seed_seq(std::initializer_list
<_IntType
> il
);
6040 template<typename _InputIterator
>
6041 seed_seq(_InputIterator __begin
, _InputIterator __end
);
6043 // generating functions
6044 template<typename _RandomAccessIterator
>
6046 generate(_RandomAccessIterator __begin
, _RandomAccessIterator __end
);
6048 // property functions
6050 { return _M_v
.size(); }
6052 template<typename OutputIterator
>
6054 param(OutputIterator __dest
) const
6055 { std::copy(_M_v
.begin(), _M_v
.end(), __dest
); }
6059 std::vector
<result_type
> _M_v
;
6062 /* @} */ // group random_utilities
6064 /* @} */ // group random
6066 _GLIBCXX_END_NAMESPACE_VERSION