1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009, 2010 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 * You should not attempt to use it directly.
38 // [26.4] Random number generation
41 * @defgroup random Random Number Generation
44 * A facility for generating random numbers on selected distributions.
49 * @brief A function template for converting the output of a (integral)
50 * uniform random number generator to a floatng point result in the range
53 template<typename _RealType, size_t __bits,
54 typename _UniformRandomNumberGenerator>
56 generate_canonical(_UniformRandomNumberGenerator& __g);
59 * Implementation-space details.
63 template<typename _UIntType, size_t __w,
64 bool = __w < static_cast<size_t>
65 (std::numeric_limits<_UIntType>::digits)>
67 { static const _UIntType __value = 0; };
69 template<typename _UIntType, size_t __w>
70 struct _Shift<_UIntType, __w, true>
71 { static const _UIntType __value = _UIntType(1) << __w; };
73 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
76 // Dispatch based on modulus value to prevent divide-by-zero compile-time
77 // errors when m == 0.
78 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
81 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
84 * An adaptor class for converting the output of any Generator into
85 * the input for a specific Distribution.
87 template<typename _Engine, typename _DInputType>
92 _Adaptor(_Engine& __g)
97 { return _DInputType(0); }
101 { return _DInputType(1); }
104 * Converts a value generated by the adapted random number generator
105 * into a value in the input domain for the dependent random number
111 return std::generate_canonical<_DInputType,
112 std::numeric_limits<_DInputType>::digits,
119 } // namespace __detail
122 * @addtogroup random_generators Random Number Generators
125 * These classes define objects which provide random or pseudorandom
126 * numbers, either from a discrete or a continuous interval. The
127 * random number generator supplied as a part of this library are
128 * all uniform random number generators which provide a sequence of
129 * random number uniformly distributed over their range.
131 * A number generator is a function object with an operator() that
132 * takes zero arguments and returns a number.
134 * A compliant random number generator must satisfy the following
135 * requirements. <table border=1 cellpadding=10 cellspacing=0>
136 * <caption align=top>Random Number Generator Requirements</caption>
137 * <tr><td>To be documented.</td></tr> </table>
143 * @brief A model of a linear congruential random number generator.
145 * A random number generator that produces pseudorandom numbers via
148 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
151 * The template parameter @p _UIntType must be an unsigned integral type
152 * large enough to store values up to (__m-1). If the template parameter
153 * @p __m is 0, the modulus @p __m used is
154 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
155 * parameters @p __a and @p __c must be less than @p __m.
157 * The size of the state is @f$1@f$.
159 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
160 class linear_congruential_engine
162 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
163 "substituting _UIntType not an unsigned integral type");
164 static_assert(__m == 0u || (__a < __m && __c < __m),
165 "template argument substituting __m out of bounds");
168 /** The type of the generated random value. */
169 typedef _UIntType result_type;
171 /** The multiplier. */
172 static const result_type multiplier = __a;
174 static const result_type increment = __c;
176 static const result_type modulus = __m;
177 static const result_type default_seed = 1u;
180 * @brief Constructs a %linear_congruential_engine random number
181 * generator engine with seed @p __s. The default seed value
184 * @param __s The initial seed value.
187 linear_congruential_engine(result_type __s = default_seed)
191 * @brief Constructs a %linear_congruential_engine random number
192 * generator engine seeded from the seed sequence @p __q.
194 * @param __q the seed sequence.
196 template<typename _Sseq, typename = typename
197 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
200 linear_congruential_engine(_Sseq& __q)
204 * @brief Reseeds the %linear_congruential_engine random number generator
205 * engine sequence to the seed @p __s.
207 * @param __s The new seed.
210 seed(result_type __s = default_seed);
213 * @brief Reseeds the %linear_congruential_engine random number generator
215 * sequence using values from the seed sequence @p __q.
217 * @param __q the seed sequence.
219 template<typename _Sseq>
220 typename std::enable_if<std::is_class<_Sseq>::value>::type
224 * @brief Gets the smallest possible value in the output range.
226 * The minimum depends on the @p __c parameter: if it is zero, the
227 * minimum generated must be > 0, otherwise 0 is allowed.
229 * @todo This should be constexpr.
233 { return __c == 0u ? 1u : 0u; }
236 * @brief Gets the largest possible value in the output range.
238 * @todo This should be constexpr.
245 * @brief Discard a sequence of random numbers.
247 * @todo Look for a faster way to do discard.
250 discard(unsigned long long __z)
252 for (; __z != 0ULL; --__z)
257 * @brief Gets the next random number in the sequence.
262 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
267 * @brief Compares two linear congruential random number generator
268 * objects of the same type for equality.
270 * @param __lhs A linear congruential random number generator object.
271 * @param __rhs Another linear congruential random number generator
274 * @returns true if the infinite sequences of generated values
275 * would be equal, false otherwise.
278 operator==(const linear_congruential_engine& __lhs,
279 const linear_congruential_engine& __rhs)
280 { return __lhs._M_x == __rhs._M_x; }
283 * @brief Writes the textual representation of the state x(i) of x to
286 * @param __os The output stream.
287 * @param __lcr A % linear_congruential_engine random number generator.
290 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
291 _UIntType1 __m1, typename _CharT, typename _Traits>
292 friend std::basic_ostream<_CharT, _Traits>&
293 operator<<(std::basic_ostream<_CharT, _Traits>&,
294 const std::linear_congruential_engine<_UIntType1,
298 * @brief Sets the state of the engine by reading its textual
299 * representation from @p __is.
301 * The textual representation must have been previously written using
302 * an output stream whose imbued locale and whose type's template
303 * specialization arguments _CharT and _Traits were the same as those
306 * @param __is The input stream.
307 * @param __lcr A % linear_congruential_engine random number generator.
310 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
311 _UIntType1 __m1, typename _CharT, typename _Traits>
312 friend std::basic_istream<_CharT, _Traits>&
313 operator>>(std::basic_istream<_CharT, _Traits>&,
314 std::linear_congruential_engine<_UIntType1, __a1,
322 * @brief Compares two linear congruential random number generator
323 * objects of the same type for inequality.
325 * @param __lhs A linear congruential random number generator object.
326 * @param __rhs Another linear congruential random number generator
329 * @returns true if the infinite sequences of generated values
330 * would be different, false otherwise.
332 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
334 operator!=(const std::linear_congruential_engine<_UIntType, __a,
336 const std::linear_congruential_engine<_UIntType, __a,
338 { return !(__lhs == __rhs); }
342 * A generalized feedback shift register discrete random number generator.
344 * This algorithm avoids multiplication and division and is designed to be
345 * friendly to a pipelined architecture. If the parameters are chosen
346 * correctly, this generator will produce numbers with a very long period and
347 * fairly good apparent entropy, although still not cryptographically strong.
349 * The best way to use this generator is with the predefined mt19937 class.
351 * This algorithm was originally invented by Makoto Matsumoto and
354 * @var word_size The number of bits in each element of the state vector.
355 * @var state_size The degree of recursion.
356 * @var shift_size The period parameter.
357 * @var mask_bits The separation point bit index.
358 * @var parameter_a The last row of the twist matrix.
359 * @var output_u The first right-shift tempering matrix parameter.
360 * @var output_s The first left-shift tempering matrix parameter.
361 * @var output_b The first left-shift tempering matrix mask.
362 * @var output_t The second left-shift tempering matrix parameter.
363 * @var output_c The second left-shift tempering matrix mask.
364 * @var output_l The second right-shift tempering matrix parameter.
366 template<typename _UIntType, size_t __w,
367 size_t __n, size_t __m, size_t __r,
368 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
369 _UIntType __b, size_t __t,
370 _UIntType __c, size_t __l, _UIntType __f>
371 class mersenne_twister_engine
373 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
374 "substituting _UIntType not an unsigned integral type");
375 static_assert(1u <= __m && __m <= __n,
376 "template argument substituting __m out of bounds");
377 static_assert(__r <= __w, "template argument substituting "
379 static_assert(__u <= __w, "template argument substituting "
381 static_assert(__s <= __w, "template argument substituting "
383 static_assert(__t <= __w, "template argument substituting "
385 static_assert(__l <= __w, "template argument substituting "
387 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
388 "template argument substituting __w out of bound");
389 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
390 "template argument substituting __a out of bound");
391 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
392 "template argument substituting __b out of bound");
393 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
394 "template argument substituting __c out of bound");
395 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
396 "template argument substituting __d out of bound");
397 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
398 "template argument substituting __f out of bound");
401 /** The type of the generated random value. */
402 typedef _UIntType result_type;
405 static const size_t word_size = __w;
406 static const size_t state_size = __n;
407 static const size_t shift_size = __m;
408 static const size_t mask_bits = __r;
409 static const result_type xor_mask = __a;
410 static const size_t tempering_u = __u;
411 static const result_type tempering_d = __d;
412 static const size_t tempering_s = __s;
413 static const result_type tempering_b = __b;
414 static const size_t tempering_t = __t;
415 static const result_type tempering_c = __c;
416 static const size_t tempering_l = __l;
417 static const result_type initialization_multiplier = __f;
418 static const result_type default_seed = 5489u;
420 // constructors and member function
422 mersenne_twister_engine(result_type __sd = default_seed)
426 * @brief Constructs a %mersenne_twister_engine random number generator
427 * engine seeded from the seed sequence @p __q.
429 * @param __q the seed sequence.
431 template<typename _Sseq, typename = typename
432 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
435 mersenne_twister_engine(_Sseq& __q)
439 seed(result_type __sd = default_seed);
441 template<typename _Sseq>
442 typename std::enable_if<std::is_class<_Sseq>::value>::type
446 * @brief Gets the smallest possible value in the output range.
448 * @todo This should be constexpr.
455 * @brief Gets the largest possible value in the output range.
457 * @todo This should be constexpr.
461 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
464 * @brief Discard a sequence of random numbers.
466 * @todo Look for a faster way to do discard.
469 discard(unsigned long long __z)
471 for (; __z != 0ULL; --__z)
479 * @brief Compares two % mersenne_twister_engine random number generator
480 * objects of the same type for equality.
482 * @param __lhs A % mersenne_twister_engine random number generator
484 * @param __rhs Another % mersenne_twister_engine random number
487 * @returns true if the infinite sequences of generated values
488 * would be equal, false otherwise.
491 operator==(const mersenne_twister_engine& __lhs,
492 const mersenne_twister_engine& __rhs)
493 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
496 * @brief Inserts the current state of a % mersenne_twister_engine
497 * random number generator engine @p __x into the output stream
500 * @param __os An output stream.
501 * @param __x A % mersenne_twister_engine random number generator
504 * @returns The output stream with the state of @p __x inserted or in
507 template<typename _UIntType1,
508 size_t __w1, size_t __n1,
509 size_t __m1, size_t __r1,
510 _UIntType1 __a1, size_t __u1,
511 _UIntType1 __d1, size_t __s1,
512 _UIntType1 __b1, size_t __t1,
513 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
514 typename _CharT, typename _Traits>
515 friend std::basic_ostream<_CharT, _Traits>&
516 operator<<(std::basic_ostream<_CharT, _Traits>&,
517 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
518 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
522 * @brief Extracts the current state of a % mersenne_twister_engine
523 * random number generator engine @p __x from the input stream
526 * @param __is An input stream.
527 * @param __x A % mersenne_twister_engine random number generator
530 * @returns The input stream with the state of @p __x extracted or in
533 template<typename _UIntType1,
534 size_t __w1, size_t __n1,
535 size_t __m1, size_t __r1,
536 _UIntType1 __a1, size_t __u1,
537 _UIntType1 __d1, size_t __s1,
538 _UIntType1 __b1, size_t __t1,
539 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
540 typename _CharT, typename _Traits>
541 friend std::basic_istream<_CharT, _Traits>&
542 operator>>(std::basic_istream<_CharT, _Traits>&,
543 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
544 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
548 _UIntType _M_x[state_size];
553 * @brief Compares two % mersenne_twister_engine random number generator
554 * objects of the same type for inequality.
556 * @param __lhs A % mersenne_twister_engine random number generator
558 * @param __rhs Another % mersenne_twister_engine random number
561 * @returns true if the infinite sequences of generated values
562 * would be different, false otherwise.
564 template<typename _UIntType, size_t __w,
565 size_t __n, size_t __m, size_t __r,
566 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
567 _UIntType __b, size_t __t,
568 _UIntType __c, size_t __l, _UIntType __f>
570 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
571 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
572 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
573 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
574 { return !(__lhs == __rhs); }
578 * @brief The Marsaglia-Zaman generator.
580 * This is a model of a Generalized Fibonacci discrete random number
581 * generator, sometimes referred to as the SWC generator.
583 * A discrete random number generator that produces pseudorandom
586 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
589 * The size of the state is @f$r@f$
590 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
592 * @var _M_x The state of the generator. This is a ring buffer.
593 * @var _M_carry The carry.
594 * @var _M_p Current index of x(i - r).
596 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
597 class subtract_with_carry_engine
599 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
600 "substituting _UIntType not an unsigned integral type");
601 static_assert(0u < __s && __s < __r,
602 "template argument substituting __s out of bounds");
603 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
604 "template argument substituting __w out of bounds");
607 /** The type of the generated random value. */
608 typedef _UIntType result_type;
611 static const size_t word_size = __w;
612 static const size_t short_lag = __s;
613 static const size_t long_lag = __r;
614 static const result_type default_seed = 19780503u;
617 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
618 * random number generator.
621 subtract_with_carry_engine(result_type __sd = default_seed)
625 * @brief Constructs a %subtract_with_carry_engine random number engine
626 * seeded from the seed sequence @p __q.
628 * @param __q the seed sequence.
630 template<typename _Sseq, typename = typename
631 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
634 subtract_with_carry_engine(_Sseq& __q)
638 * @brief Seeds the initial state @f$x_0@f$ of the random number
641 * N1688[4.19] modifies this as follows. If @p __value == 0,
642 * sets value to 19780503. In any case, with a linear
643 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
644 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
645 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
646 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
647 * set carry to 1, otherwise sets carry to 0.
650 seed(result_type __sd = default_seed);
653 * @brief Seeds the initial state @f$x_0@f$ of the
654 * % subtract_with_carry_engine random number generator.
656 template<typename _Sseq>
657 typename std::enable_if<std::is_class<_Sseq>::value>::type
661 * @brief Gets the inclusive minimum value of the range of random
662 * integers returned by this generator.
664 * @todo This should be constexpr.
671 * @brief Gets the inclusive maximum value of the range of random
672 * integers returned by this generator.
674 * @todo This should be constexpr.
678 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
681 * @brief Discard a sequence of random numbers.
683 * @todo Look for a faster way to do discard.
686 discard(unsigned long long __z)
688 for (; __z != 0ULL; --__z)
693 * @brief Gets the next random number in the sequence.
699 * @brief Compares two % subtract_with_carry_engine random number
700 * generator objects of the same type for equality.
702 * @param __lhs A % subtract_with_carry_engine random number generator
704 * @param __rhs Another % subtract_with_carry_engine random number
707 * @returns true if the infinite sequences of generated values
708 * would be equal, false otherwise.
711 operator==(const subtract_with_carry_engine& __lhs,
712 const subtract_with_carry_engine& __rhs)
713 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
716 * @brief Inserts the current state of a % subtract_with_carry_engine
717 * random number generator engine @p __x into the output stream
720 * @param __os An output stream.
721 * @param __x A % subtract_with_carry_engine random number generator
724 * @returns The output stream with the state of @p __x inserted or in
727 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
728 typename _CharT, typename _Traits>
729 friend std::basic_ostream<_CharT, _Traits>&
730 operator<<(std::basic_ostream<_CharT, _Traits>&,
731 const std::subtract_with_carry_engine<_UIntType1, __w1,
735 * @brief Extracts the current state of a % subtract_with_carry_engine
736 * random number generator engine @p __x from the input stream
739 * @param __is An input stream.
740 * @param __x A % subtract_with_carry_engine random number generator
743 * @returns The input stream with the state of @p __x extracted or in
746 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
747 typename _CharT, typename _Traits>
748 friend std::basic_istream<_CharT, _Traits>&
749 operator>>(std::basic_istream<_CharT, _Traits>&,
750 std::subtract_with_carry_engine<_UIntType1, __w1,
754 _UIntType _M_x[long_lag];
760 * @brief Compares two % subtract_with_carry_engine random number
761 * generator objects of the same type for inequality.
763 * @param __lhs A % subtract_with_carry_engine random number generator
765 * @param __rhs Another % subtract_with_carry_engine random number
768 * @returns true if the infinite sequences of generated values
769 * would be different, false otherwise.
771 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
773 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
775 const std::subtract_with_carry_engine<_UIntType, __w,
777 { return !(__lhs == __rhs); }
781 * Produces random numbers from some base engine by discarding blocks of
784 * 0 <= @p __r <= @p __p
786 template<typename _RandomNumberEngine, size_t __p, size_t __r>
787 class discard_block_engine
789 static_assert(1 <= __r && __r <= __p,
790 "template argument substituting __r out of bounds");
793 /** The type of the generated random value. */
794 typedef typename _RandomNumberEngine::result_type result_type;
797 static const size_t block_size = __p;
798 static const size_t used_block = __r;
801 * @brief Constructs a default %discard_block_engine engine.
803 * The underlying engine is default constructed as well.
805 discard_block_engine()
806 : _M_b(), _M_n(0) { }
809 * @brief Copy constructs a %discard_block_engine engine.
811 * Copies an existing base class random number generator.
812 * @param rng An existing (base class) engine object.
815 discard_block_engine(const _RandomNumberEngine& __rne)
816 : _M_b(__rne), _M_n(0) { }
819 * @brief Move constructs a %discard_block_engine engine.
821 * Copies an existing base class random number generator.
822 * @param rng An existing (base class) engine object.
825 discard_block_engine(_RandomNumberEngine&& __rne)
826 : _M_b(std::move(__rne)), _M_n(0) { }
829 * @brief Seed constructs a %discard_block_engine engine.
831 * Constructs the underlying generator engine seeded with @p __s.
832 * @param __s A seed value for the base class engine.
835 discard_block_engine(result_type __s)
836 : _M_b(__s), _M_n(0) { }
839 * @brief Generator construct a %discard_block_engine engine.
841 * @param __q A seed sequence.
843 template<typename _Sseq, typename = typename
844 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
845 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
848 discard_block_engine(_Sseq& __q)
853 * @brief Reseeds the %discard_block_engine object with the default
854 * seed for the underlying base class generator engine.
864 * @brief Reseeds the %discard_block_engine object with the default
865 * seed for the underlying base class generator engine.
868 seed(result_type __s)
875 * @brief Reseeds the %discard_block_engine object with the given seed
877 * @param __q A seed generator function.
879 template<typename _Sseq>
888 * @brief Gets a const reference to the underlying generator engine
891 const _RandomNumberEngine&
896 * @brief Gets the minimum value in the generated random number range.
898 * @todo This should be constexpr.
902 { return _M_b.min(); }
905 * @brief Gets the maximum value in the generated random number range.
907 * @todo This should be constexpr.
911 { return _M_b.max(); }
914 * @brief Discard a sequence of random numbers.
916 * @todo Look for a faster way to do discard.
919 discard(unsigned long long __z)
921 for (; __z != 0ULL; --__z)
926 * @brief Gets the next value in the generated random number sequence.
932 * @brief Compares two %discard_block_engine random number generator
933 * objects of the same type for equality.
935 * @param __lhs A %discard_block_engine random number generator object.
936 * @param __rhs Another %discard_block_engine random number generator
939 * @returns true if the infinite sequences of generated values
940 * would be equal, false otherwise.
943 operator==(const discard_block_engine& __lhs,
944 const discard_block_engine& __rhs)
945 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
948 * @brief Inserts the current state of a %discard_block_engine random
949 * number generator engine @p __x into the output stream
952 * @param __os An output stream.
953 * @param __x A %discard_block_engine random number generator engine.
955 * @returns The output stream with the state of @p __x inserted or in
958 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
959 typename _CharT, typename _Traits>
960 friend std::basic_ostream<_CharT, _Traits>&
961 operator<<(std::basic_ostream<_CharT, _Traits>&,
962 const std::discard_block_engine<_RandomNumberEngine1,
966 * @brief Extracts the current state of a % subtract_with_carry_engine
967 * random number generator engine @p __x from the input stream
970 * @param __is An input stream.
971 * @param __x A %discard_block_engine random number generator engine.
973 * @returns The input stream with the state of @p __x extracted or in
976 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
977 typename _CharT, typename _Traits>
978 friend std::basic_istream<_CharT, _Traits>&
979 operator>>(std::basic_istream<_CharT, _Traits>&,
980 std::discard_block_engine<_RandomNumberEngine1,
984 _RandomNumberEngine _M_b;
989 * @brief Compares two %discard_block_engine random number generator
990 * objects of the same type for inequality.
992 * @param __lhs A %discard_block_engine random number generator object.
993 * @param __rhs Another %discard_block_engine random number generator
996 * @returns true if the infinite sequences of generated values
997 * would be different, false otherwise.
999 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1001 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1003 const std::discard_block_engine<_RandomNumberEngine, __p,
1005 { return !(__lhs == __rhs); }
1009 * Produces random numbers by combining random numbers from some base
1010 * engine to produce random numbers with a specifies number of bits @p __w.
1012 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1013 class independent_bits_engine
1015 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1016 "substituting _UIntType not an unsigned integral type");
1017 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1018 "template argument substituting __w out of bounds");
1021 /** The type of the generated random value. */
1022 typedef _UIntType result_type;
1025 * @brief Constructs a default %independent_bits_engine engine.
1027 * The underlying engine is default constructed as well.
1029 independent_bits_engine()
1033 * @brief Copy constructs a %independent_bits_engine engine.
1035 * Copies an existing base class random number generator.
1036 * @param rng An existing (base class) engine object.
1039 independent_bits_engine(const _RandomNumberEngine& __rne)
1043 * @brief Move constructs a %independent_bits_engine engine.
1045 * Copies an existing base class random number generator.
1046 * @param rng An existing (base class) engine object.
1049 independent_bits_engine(_RandomNumberEngine&& __rne)
1050 : _M_b(std::move(__rne)) { }
1053 * @brief Seed constructs a %independent_bits_engine engine.
1055 * Constructs the underlying generator engine seeded with @p __s.
1056 * @param __s A seed value for the base class engine.
1059 independent_bits_engine(result_type __s)
1063 * @brief Generator construct a %independent_bits_engine engine.
1065 * @param __q A seed sequence.
1067 template<typename _Sseq, typename = typename
1068 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1069 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1072 independent_bits_engine(_Sseq& __q)
1077 * @brief Reseeds the %independent_bits_engine object with the default
1078 * seed for the underlying base class generator engine.
1085 * @brief Reseeds the %independent_bits_engine object with the default
1086 * seed for the underlying base class generator engine.
1089 seed(result_type __s)
1093 * @brief Reseeds the %independent_bits_engine object with the given
1095 * @param __q A seed generator function.
1097 template<typename _Sseq>
1103 * @brief Gets a const reference to the underlying generator engine
1106 const _RandomNumberEngine&
1111 * @brief Gets the minimum value in the generated random number range.
1113 * @todo This should be constexpr.
1120 * @brief Gets the maximum value in the generated random number range.
1122 * @todo This should be constexpr.
1126 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1129 * @brief Discard a sequence of random numbers.
1131 * @todo Look for a faster way to do discard.
1134 discard(unsigned long long __z)
1136 for (; __z != 0ULL; --__z)
1141 * @brief Gets the next value in the generated random number sequence.
1147 * @brief Compares two %independent_bits_engine random number generator
1148 * objects of the same type for equality.
1150 * @param __lhs A %independent_bits_engine random number generator
1152 * @param __rhs Another %independent_bits_engine random number generator
1155 * @returns true if the infinite sequences of generated values
1156 * would be equal, false otherwise.
1159 operator==(const independent_bits_engine& __lhs,
1160 const independent_bits_engine& __rhs)
1161 { return __lhs._M_b == __rhs._M_b; }
1164 * @brief Extracts the current state of a % subtract_with_carry_engine
1165 * random number generator engine @p __x from the input stream
1168 * @param __is An input stream.
1169 * @param __x A %independent_bits_engine random number generator
1172 * @returns The input stream with the state of @p __x extracted or in
1175 template<typename _CharT, typename _Traits>
1176 friend std::basic_istream<_CharT, _Traits>&
1177 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1178 std::independent_bits_engine<_RandomNumberEngine,
1179 __w, _UIntType>& __x)
1186 _RandomNumberEngine _M_b;
1190 * @brief Compares two %independent_bits_engine random number generator
1191 * objects of the same type for inequality.
1193 * @param __lhs A %independent_bits_engine random number generator
1195 * @param __rhs Another %independent_bits_engine random number generator
1198 * @returns true if the infinite sequences of generated values
1199 * would be different, false otherwise.
1201 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1203 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1205 const std::independent_bits_engine<_RandomNumberEngine, __w,
1207 { return !(__lhs == __rhs); }
1210 * @brief Inserts the current state of a %independent_bits_engine random
1211 * number generator engine @p __x into the output stream @p __os.
1213 * @param __os An output stream.
1214 * @param __x A %independent_bits_engine random number generator engine.
1216 * @returns The output stream with the state of @p __x inserted or in
1219 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1220 typename _CharT, typename _Traits>
1221 std::basic_ostream<_CharT, _Traits>&
1222 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1223 const std::independent_bits_engine<_RandomNumberEngine,
1224 __w, _UIntType>& __x)
1232 * @brief Produces random numbers by combining random numbers from some
1233 * base engine to produce random numbers with a specifies number of bits
1236 template<typename _RandomNumberEngine, size_t __k>
1237 class shuffle_order_engine
1239 static_assert(1u <= __k, "template argument substituting "
1240 "__k out of bound");
1243 /** The type of the generated random value. */
1244 typedef typename _RandomNumberEngine::result_type result_type;
1246 static const size_t table_size = __k;
1249 * @brief Constructs a default %shuffle_order_engine engine.
1251 * The underlying engine is default constructed as well.
1253 shuffle_order_engine()
1255 { _M_initialize(); }
1258 * @brief Copy constructs a %shuffle_order_engine engine.
1260 * Copies an existing base class random number generator.
1261 * @param rng An existing (base class) engine object.
1264 shuffle_order_engine(const _RandomNumberEngine& __rne)
1266 { _M_initialize(); }
1269 * @brief Move constructs a %shuffle_order_engine engine.
1271 * Copies an existing base class random number generator.
1272 * @param rng An existing (base class) engine object.
1275 shuffle_order_engine(_RandomNumberEngine&& __rne)
1276 : _M_b(std::move(__rne))
1277 { _M_initialize(); }
1280 * @brief Seed constructs a %shuffle_order_engine engine.
1282 * Constructs the underlying generator engine seeded with @p __s.
1283 * @param __s A seed value for the base class engine.
1286 shuffle_order_engine(result_type __s)
1288 { _M_initialize(); }
1291 * @brief Generator construct a %shuffle_order_engine engine.
1293 * @param __q A seed sequence.
1295 template<typename _Sseq, typename = typename
1296 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1297 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1300 shuffle_order_engine(_Sseq& __q)
1302 { _M_initialize(); }
1305 * @brief Reseeds the %shuffle_order_engine object with the default seed
1306 for the underlying base class generator engine.
1316 * @brief Reseeds the %shuffle_order_engine object with the default seed
1317 * for the underlying base class generator engine.
1320 seed(result_type __s)
1327 * @brief Reseeds the %shuffle_order_engine object with the given seed
1329 * @param __q A seed generator function.
1331 template<typename _Sseq>
1340 * Gets a const reference to the underlying generator engine object.
1342 const _RandomNumberEngine&
1347 * Gets the minimum value in the generated random number range.
1349 * @todo This should be constexpr.
1353 { return _M_b.min(); }
1356 * Gets the maximum value in the generated random number range.
1358 * @todo This should be constexpr.
1362 { return _M_b.max(); }
1365 * Discard a sequence of random numbers.
1367 * @todo Look for a faster way to do discard.
1370 discard(unsigned long long __z)
1372 for (; __z != 0ULL; --__z)
1377 * Gets the next value in the generated random number sequence.
1383 * Compares two %shuffle_order_engine random number generator objects
1384 * of the same type for equality.
1386 * @param __lhs A %shuffle_order_engine random number generator object.
1387 * @param __rhs Another %shuffle_order_engine random number generator
1390 * @returns true if the infinite sequences of generated values
1391 * would be equal, false otherwise.
1394 operator==(const shuffle_order_engine& __lhs,
1395 const shuffle_order_engine& __rhs)
1396 { return __lhs._M_b == __rhs._M_b; }
1399 * @brief Inserts the current state of a %shuffle_order_engine random
1400 * number generator engine @p __x into the output stream
1403 * @param __os An output stream.
1404 * @param __x A %shuffle_order_engine random number generator engine.
1406 * @returns The output stream with the state of @p __x inserted or in
1409 template<typename _RandomNumberEngine1, size_t __k1,
1410 typename _CharT, typename _Traits>
1411 friend std::basic_ostream<_CharT, _Traits>&
1412 operator<<(std::basic_ostream<_CharT, _Traits>&,
1413 const std::shuffle_order_engine<_RandomNumberEngine1,
1417 * @brief Extracts the current state of a % subtract_with_carry_engine
1418 * random number generator engine @p __x from the input stream
1421 * @param __is An input stream.
1422 * @param __x A %shuffle_order_engine random number generator engine.
1424 * @returns The input stream with the state of @p __x extracted or in
1427 template<typename _RandomNumberEngine1, size_t __k1,
1428 typename _CharT, typename _Traits>
1429 friend std::basic_istream<_CharT, _Traits>&
1430 operator>>(std::basic_istream<_CharT, _Traits>&,
1431 std::shuffle_order_engine<_RandomNumberEngine1, __k1>&);
1434 void _M_initialize()
1436 for (size_t __i = 0; __i < __k; ++__i)
1441 _RandomNumberEngine _M_b;
1442 result_type _M_v[__k];
1447 * Compares two %shuffle_order_engine random number generator objects
1448 * of the same type for inequality.
1450 * @param __lhs A %shuffle_order_engine random number generator object.
1451 * @param __rhs Another %shuffle_order_engine random number generator
1454 * @returns true if the infinite sequences of generated values
1455 * would be different, false otherwise.
1457 template<typename _RandomNumberEngine, size_t __k>
1459 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1461 const std::shuffle_order_engine<_RandomNumberEngine,
1463 { return !(__lhs == __rhs); }
1467 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1469 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1473 * An alternative LCR (Lehmer Generator function).
1475 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1479 * The classic Mersenne Twister.
1482 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1483 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1484 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1486 typedef mersenne_twister_engine<
1492 0xefc60000UL, 18, 1812433253UL> mt19937;
1495 * An alternative Mersenne Twister.
1497 typedef mersenne_twister_engine<
1500 0xb5026f5aa96619e9ULL, 29,
1501 0x5555555555555555ULL, 17,
1502 0x71d67fffeda60000ULL, 37,
1503 0xfff7eee000000000ULL, 43,
1504 6364136223846793005ULL> mt19937_64;
1506 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1509 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1512 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1514 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1516 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1518 typedef minstd_rand0 default_random_engine;
1521 * A standard interface to a platform-specific non-deterministic
1522 * random number generator (if any are available).
1527 /** The type of the generated random value. */
1528 typedef unsigned int result_type;
1530 // constructors, destructors and member functions
1532 #ifdef _GLIBCXX_USE_RANDOM_TR1
1535 random_device(const std::string& __token = "/dev/urandom")
1537 if ((__token != "/dev/urandom" && __token != "/dev/random")
1538 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1539 std::__throw_runtime_error(__N("random_device::"
1540 "random_device(const std::string&)"));
1544 { std::fclose(_M_file); }
1549 random_device(const std::string& __token = "mt19937")
1550 : _M_mt(_M_strtoul(__token)) { }
1553 static unsigned long
1554 _M_strtoul(const std::string& __str)
1556 unsigned long __ret = 5489UL;
1557 if (__str != "mt19937")
1559 const char* __nptr = __str.c_str();
1561 __ret = std::strtoul(__nptr, &__endptr, 0);
1562 if (*__nptr == '\0' || *__endptr != '\0')
1563 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1564 "(const std::string&)"));
1575 { return std::numeric_limits<result_type>::min(); }
1579 { return std::numeric_limits<result_type>::max(); }
1588 #ifdef _GLIBCXX_USE_RANDOM_TR1
1590 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1598 // No copy functions.
1599 random_device(const random_device&) = delete;
1600 void operator=(const random_device&) = delete;
1604 #ifdef _GLIBCXX_USE_RANDOM_TR1
1611 /* @} */ // group random_generators
1614 * @addtogroup random_distributions Random Number Distributions
1620 * @addtogroup random_distributions_uniform Uniform
1621 * @ingroup random_distributions
1626 * @brief Uniform discrete distribution for random numbers.
1627 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1628 * probability throughout the range.
1630 template<typename _IntType = int>
1631 class uniform_int_distribution
1633 static_assert(std::is_integral<_IntType>::value,
1634 "template argument not an integral type");
1637 /** The type of the range of the distribution. */
1638 typedef _IntType result_type;
1639 /** Parameter type. */
1642 typedef uniform_int_distribution<_IntType> distribution_type;
1645 param_type(_IntType __a = 0,
1646 _IntType __b = std::numeric_limits<_IntType>::max())
1647 : _M_a(__a), _M_b(__b)
1649 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1661 operator==(const param_type& __p1, const param_type& __p2)
1662 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1671 * @brief Constructs a uniform distribution object.
1674 uniform_int_distribution(_IntType __a = 0,
1675 _IntType __b = std::numeric_limits<_IntType>::max())
1676 : _M_param(__a, __b)
1680 uniform_int_distribution(const param_type& __p)
1685 * @brief Resets the distribution state.
1687 * Does nothing for the uniform integer distribution.
1694 { return _M_param.a(); }
1698 { return _M_param.b(); }
1701 * @brief Returns the parameter set of the distribution.
1705 { return _M_param; }
1708 * @brief Sets the parameter set of the distribution.
1709 * @param __param The new parameter set of the distribution.
1712 param(const param_type& __param)
1713 { _M_param = __param; }
1716 * @brief Returns the inclusive lower bound of the distribution range.
1720 { return this->a(); }
1723 * @brief Returns the inclusive upper bound of the distribution range.
1727 { return this->b(); }
1730 * @brief Generating functions.
1732 template<typename _UniformRandomNumberGenerator>
1734 operator()(_UniformRandomNumberGenerator& __urng)
1735 { return this->operator()(__urng, this->param()); }
1737 template<typename _UniformRandomNumberGenerator>
1739 operator()(_UniformRandomNumberGenerator& __urng,
1740 const param_type& __p);
1742 param_type _M_param;
1746 * @brief Return true if two uniform integer distributions have
1747 * the same parameters.
1749 template<typename _IntType>
1751 operator==(const std::uniform_int_distribution<_IntType>& __d1,
1752 const std::uniform_int_distribution<_IntType>& __d2)
1753 { return __d1.param() == __d2.param(); }
1756 * @brief Return true if two uniform integer distributions have
1757 * different parameters.
1759 template<typename _IntType>
1761 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1762 const std::uniform_int_distribution<_IntType>& __d2)
1763 { return !(__d1 == __d2); }
1766 * @brief Inserts a %uniform_int_distribution random number
1767 * distribution @p __x into the output stream @p os.
1769 * @param __os An output stream.
1770 * @param __x A %uniform_int_distribution random number distribution.
1772 * @returns The output stream with the state of @p __x inserted or in
1775 template<typename _IntType, typename _CharT, typename _Traits>
1776 std::basic_ostream<_CharT, _Traits>&
1777 operator<<(std::basic_ostream<_CharT, _Traits>&,
1778 const std::uniform_int_distribution<_IntType>&);
1781 * @brief Extracts a %uniform_int_distribution random number distribution
1782 * @p __x from the input stream @p __is.
1784 * @param __is An input stream.
1785 * @param __x A %uniform_int_distribution random number generator engine.
1787 * @returns The input stream with @p __x extracted or in an error state.
1789 template<typename _IntType, typename _CharT, typename _Traits>
1790 std::basic_istream<_CharT, _Traits>&
1791 operator>>(std::basic_istream<_CharT, _Traits>&,
1792 std::uniform_int_distribution<_IntType>&);
1796 * @brief Uniform continuous distribution for random numbers.
1798 * A continuous random distribution on the range [min, max) with equal
1799 * probability throughout the range. The URNG should be real-valued and
1800 * deliver number in the range [0, 1).
1802 template<typename _RealType = double>
1803 class uniform_real_distribution
1805 static_assert(std::is_floating_point<_RealType>::value,
1806 "template argument not a floating point type");
1809 /** The type of the range of the distribution. */
1810 typedef _RealType result_type;
1811 /** Parameter type. */
1814 typedef uniform_real_distribution<_RealType> distribution_type;
1817 param_type(_RealType __a = _RealType(0),
1818 _RealType __b = _RealType(1))
1819 : _M_a(__a), _M_b(__b)
1821 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1833 operator==(const param_type& __p1, const param_type& __p2)
1834 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1843 * @brief Constructs a uniform_real_distribution object.
1845 * @param __min [IN] The lower bound of the distribution.
1846 * @param __max [IN] The upper bound of the distribution.
1849 uniform_real_distribution(_RealType __a = _RealType(0),
1850 _RealType __b = _RealType(1))
1851 : _M_param(__a, __b)
1855 uniform_real_distribution(const param_type& __p)
1860 * @brief Resets the distribution state.
1862 * Does nothing for the uniform real distribution.
1869 { return _M_param.a(); }
1873 { return _M_param.b(); }
1876 * @brief Returns the parameter set of the distribution.
1880 { return _M_param; }
1883 * @brief Sets the parameter set of the distribution.
1884 * @param __param The new parameter set of the distribution.
1887 param(const param_type& __param)
1888 { _M_param = __param; }
1891 * @brief Returns the inclusive lower bound of the distribution range.
1895 { return this->a(); }
1898 * @brief Returns the inclusive upper bound of the distribution range.
1902 { return this->b(); }
1905 * @brief Generating functions.
1907 template<typename _UniformRandomNumberGenerator>
1909 operator()(_UniformRandomNumberGenerator& __urng)
1910 { return this->operator()(__urng, this->param()); }
1912 template<typename _UniformRandomNumberGenerator>
1914 operator()(_UniformRandomNumberGenerator& __urng,
1915 const param_type& __p)
1917 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1919 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1923 param_type _M_param;
1927 * @brief Return true if two uniform real distributions have
1928 * the same parameters.
1930 template<typename _IntType>
1932 operator==(const std::uniform_real_distribution<_IntType>& __d1,
1933 const std::uniform_real_distribution<_IntType>& __d2)
1934 { return __d1.param() == __d2.param(); }
1937 * @brief Return true if two uniform real distributions have
1938 * different parameters.
1940 template<typename _IntType>
1942 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1943 const std::uniform_real_distribution<_IntType>& __d2)
1944 { return !(__d1 == __d2); }
1947 * @brief Inserts a %uniform_real_distribution random number
1948 * distribution @p __x into the output stream @p __os.
1950 * @param __os An output stream.
1951 * @param __x A %uniform_real_distribution random number distribution.
1953 * @returns The output stream with the state of @p __x inserted or in
1956 template<typename _RealType, typename _CharT, typename _Traits>
1957 std::basic_ostream<_CharT, _Traits>&
1958 operator<<(std::basic_ostream<_CharT, _Traits>&,
1959 const std::uniform_real_distribution<_RealType>&);
1962 * @brief Extracts a %uniform_real_distribution random number distribution
1963 * @p __x from the input stream @p __is.
1965 * @param __is An input stream.
1966 * @param __x A %uniform_real_distribution random number generator engine.
1968 * @returns The input stream with @p __x extracted or in an error state.
1970 template<typename _RealType, typename _CharT, typename _Traits>
1971 std::basic_istream<_CharT, _Traits>&
1972 operator>>(std::basic_istream<_CharT, _Traits>&,
1973 std::uniform_real_distribution<_RealType>&);
1975 /* @} */ // group random_distributions_uniform
1978 * @addtogroup random_distributions_normal Normal
1979 * @ingroup random_distributions
1984 * @brief A normal continuous distribution for random numbers.
1986 * The formula for the normal probability density function is
1988 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1989 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1992 template<typename _RealType = double>
1993 class normal_distribution
1995 static_assert(std::is_floating_point<_RealType>::value,
1996 "template argument not a floating point type");
1999 /** The type of the range of the distribution. */
2000 typedef _RealType result_type;
2001 /** Parameter type. */
2004 typedef normal_distribution<_RealType> distribution_type;
2007 param_type(_RealType __mean = _RealType(0),
2008 _RealType __stddev = _RealType(1))
2009 : _M_mean(__mean), _M_stddev(__stddev)
2011 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
2020 { return _M_stddev; }
2023 operator==(const param_type& __p1, const param_type& __p2)
2024 { return (__p1._M_mean == __p2._M_mean
2025 && __p1._M_stddev == __p2._M_stddev); }
2029 _RealType _M_stddev;
2034 * Constructs a normal distribution with parameters @f$mean@f$ and
2035 * standard deviation.
2038 normal_distribution(result_type __mean = result_type(0),
2039 result_type __stddev = result_type(1))
2040 : _M_param(__mean, __stddev), _M_saved_available(false)
2044 normal_distribution(const param_type& __p)
2045 : _M_param(__p), _M_saved_available(false)
2049 * @brief Resets the distribution state.
2053 { _M_saved_available = false; }
2056 * @brief Returns the mean of the distribution.
2060 { return _M_param.mean(); }
2063 * @brief Returns the standard deviation of the distribution.
2067 { return _M_param.stddev(); }
2070 * @brief Returns the parameter set of the distribution.
2074 { return _M_param; }
2077 * @brief Sets the parameter set of the distribution.
2078 * @param __param The new parameter set of the distribution.
2081 param(const param_type& __param)
2082 { _M_param = __param; }
2085 * @brief Returns the greatest lower bound value of the distribution.
2089 { return std::numeric_limits<result_type>::min(); }
2092 * @brief Returns the least upper bound value of the distribution.
2096 { return std::numeric_limits<result_type>::max(); }
2099 * @brief Generating functions.
2101 template<typename _UniformRandomNumberGenerator>
2103 operator()(_UniformRandomNumberGenerator& __urng)
2104 { return this->operator()(__urng, this->param()); }
2106 template<typename _UniformRandomNumberGenerator>
2108 operator()(_UniformRandomNumberGenerator& __urng,
2109 const param_type& __p);
2112 * @brief Return true if two normal distributions have
2113 * the same parameters and the sequences that would
2114 * be generated are equal.
2116 template<typename _RealType1>
2118 operator==(const std::normal_distribution<_RealType1>& __d1,
2119 const std::normal_distribution<_RealType1>& __d2);
2122 * @brief Inserts a %normal_distribution random number distribution
2123 * @p __x into the output stream @p __os.
2125 * @param __os An output stream.
2126 * @param __x A %normal_distribution random number distribution.
2128 * @returns The output stream with the state of @p __x inserted or in
2131 template<typename _RealType1, typename _CharT, typename _Traits>
2132 friend std::basic_ostream<_CharT, _Traits>&
2133 operator<<(std::basic_ostream<_CharT, _Traits>&,
2134 const std::normal_distribution<_RealType1>&);
2137 * @brief Extracts a %normal_distribution random number distribution
2138 * @p __x from the input stream @p __is.
2140 * @param __is An input stream.
2141 * @param __x A %normal_distribution random number generator engine.
2143 * @returns The input stream with @p __x extracted or in an error
2146 template<typename _RealType1, typename _CharT, typename _Traits>
2147 friend std::basic_istream<_CharT, _Traits>&
2148 operator>>(std::basic_istream<_CharT, _Traits>&,
2149 std::normal_distribution<_RealType1>&);
2152 param_type _M_param;
2153 result_type _M_saved;
2154 bool _M_saved_available;
2158 * @brief Return true if two normal distributions are different.
2160 template<typename _RealType>
2162 operator!=(const std::normal_distribution<_RealType>& __d1,
2163 const std::normal_distribution<_RealType>& __d2)
2164 { return !(__d1 == __d2); }
2168 * @brief A lognormal_distribution random number distribution.
2170 * The formula for the normal probability mass function is
2172 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2173 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2176 template<typename _RealType = double>
2177 class lognormal_distribution
2179 static_assert(std::is_floating_point<_RealType>::value,
2180 "template argument not a floating point type");
2183 /** The type of the range of the distribution. */
2184 typedef _RealType result_type;
2185 /** Parameter type. */
2188 typedef lognormal_distribution<_RealType> distribution_type;
2191 param_type(_RealType __m = _RealType(0),
2192 _RealType __s = _RealType(1))
2193 : _M_m(__m), _M_s(__s)
2205 operator==(const param_type& __p1, const param_type& __p2)
2206 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2214 lognormal_distribution(_RealType __m = _RealType(0),
2215 _RealType __s = _RealType(1))
2216 : _M_param(__m, __s), _M_nd()
2220 lognormal_distribution(const param_type& __p)
2221 : _M_param(__p), _M_nd()
2225 * Resets the distribution state.
2236 { return _M_param.m(); }
2240 { return _M_param.s(); }
2243 * @brief Returns the parameter set of the distribution.
2247 { return _M_param; }
2250 * @brief Sets the parameter set of the distribution.
2251 * @param __param The new parameter set of the distribution.
2254 param(const param_type& __param)
2255 { _M_param = __param; }
2258 * @brief Returns the greatest lower bound value of the distribution.
2262 { return result_type(0); }
2265 * @brief Returns the least upper bound value of the distribution.
2269 { return std::numeric_limits<result_type>::max(); }
2272 * @brief Generating functions.
2274 template<typename _UniformRandomNumberGenerator>
2276 operator()(_UniformRandomNumberGenerator& __urng)
2277 { return this->operator()(__urng, this->param()); }
2279 template<typename _UniformRandomNumberGenerator>
2281 operator()(_UniformRandomNumberGenerator& __urng,
2282 const param_type& __p)
2283 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2286 * @brief Return true if two lognormal distributions have
2287 * the same parameters and the sequences that would
2288 * be generated are equal.
2290 template<typename _RealType1>
2292 operator==(const std::lognormal_distribution<_RealType1>& __d1,
2293 const std::lognormal_distribution<_RealType1>& __d2)
2294 { return (__d1.param() == __d2.param()
2295 && __d1._M_nd == __d2._M_nd); }
2298 * @brief Inserts a %lognormal_distribution random number distribution
2299 * @p __x into the output stream @p __os.
2301 * @param __os An output stream.
2302 * @param __x A %lognormal_distribution random number distribution.
2304 * @returns The output stream with the state of @p __x inserted or in
2307 template<typename _RealType1, typename _CharT, typename _Traits>
2308 friend std::basic_ostream<_CharT, _Traits>&
2309 operator<<(std::basic_ostream<_CharT, _Traits>&,
2310 const std::lognormal_distribution<_RealType1>&);
2313 * @brief Extracts a %lognormal_distribution random number distribution
2314 * @p __x from the input stream @p __is.
2316 * @param __is An input stream.
2317 * @param __x A %lognormal_distribution random number
2320 * @returns The input stream with @p __x extracted or in an error state.
2322 template<typename _RealType1, typename _CharT, typename _Traits>
2323 friend std::basic_istream<_CharT, _Traits>&
2324 operator>>(std::basic_istream<_CharT, _Traits>&,
2325 std::lognormal_distribution<_RealType1>&);
2328 param_type _M_param;
2330 std::normal_distribution<result_type> _M_nd;
2334 * @brief Return true if two lognormal distributions are different.
2336 template<typename _RealType>
2338 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2339 const std::lognormal_distribution<_RealType>& __d2)
2340 { return !(__d1 == __d2); }
2344 * @brief A gamma continuous distribution for random numbers.
2346 * The formula for the gamma probability density function is:
2348 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2349 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2352 template<typename _RealType = double>
2353 class gamma_distribution
2355 static_assert(std::is_floating_point<_RealType>::value,
2356 "template argument not a floating point type");
2359 /** The type of the range of the distribution. */
2360 typedef _RealType result_type;
2361 /** Parameter type. */
2364 typedef gamma_distribution<_RealType> distribution_type;
2365 friend class gamma_distribution<_RealType>;
2368 param_type(_RealType __alpha_val = _RealType(1),
2369 _RealType __beta_val = _RealType(1))
2370 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2372 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2378 { return _M_alpha; }
2385 operator==(const param_type& __p1, const param_type& __p2)
2386 { return (__p1._M_alpha == __p2._M_alpha
2387 && __p1._M_beta == __p2._M_beta); }
2396 _RealType _M_malpha, _M_a2;
2401 * @brief Constructs a gamma distribution with parameters
2402 * @f$\alpha@f$ and @f$\beta@f$.
2405 gamma_distribution(_RealType __alpha_val = _RealType(1),
2406 _RealType __beta_val = _RealType(1))
2407 : _M_param(__alpha_val, __beta_val), _M_nd()
2411 gamma_distribution(const param_type& __p)
2412 : _M_param(__p), _M_nd()
2416 * @brief Resets the distribution state.
2423 * @brief Returns the @f$\alpha@f$ of the distribution.
2427 { return _M_param.alpha(); }
2430 * @brief Returns the @f$\beta@f$ of the distribution.
2434 { return _M_param.beta(); }
2437 * @brief Returns the parameter set of the distribution.
2441 { return _M_param; }
2444 * @brief Sets the parameter set of the distribution.
2445 * @param __param The new parameter set of the distribution.
2448 param(const param_type& __param)
2449 { _M_param = __param; }
2452 * @brief Returns the greatest lower bound value of the distribution.
2456 { return result_type(0); }
2459 * @brief Returns the least upper bound value of the distribution.
2463 { return std::numeric_limits<result_type>::max(); }
2466 * @brief Generating functions.
2468 template<typename _UniformRandomNumberGenerator>
2470 operator()(_UniformRandomNumberGenerator& __urng)
2471 { return this->operator()(__urng, this->param()); }
2473 template<typename _UniformRandomNumberGenerator>
2475 operator()(_UniformRandomNumberGenerator& __urng,
2476 const param_type& __p);
2479 * @brief Return true if two gamma distributions have the same
2480 * parameters and the sequences that would be generated
2483 template<typename _RealType1>
2485 operator==(const std::gamma_distribution<_RealType1>& __d1,
2486 const std::gamma_distribution<_RealType1>& __d2)
2487 { return (__d1.param() == __d2.param()
2488 && __d1._M_nd == __d2._M_nd); }
2491 * @brief Inserts a %gamma_distribution random number distribution
2492 * @p __x into the output stream @p __os.
2494 * @param __os An output stream.
2495 * @param __x A %gamma_distribution random number distribution.
2497 * @returns The output stream with the state of @p __x inserted or in
2500 template<typename _RealType1, typename _CharT, typename _Traits>
2501 friend std::basic_ostream<_CharT, _Traits>&
2502 operator<<(std::basic_ostream<_CharT, _Traits>&,
2503 const std::gamma_distribution<_RealType1>&);
2506 * @brief Extracts a %gamma_distribution random number distribution
2507 * @p __x from the input stream @p __is.
2509 * @param __is An input stream.
2510 * @param __x A %gamma_distribution random number generator engine.
2512 * @returns The input stream with @p __x extracted or in an error state.
2514 template<typename _RealType1, typename _CharT, typename _Traits>
2515 friend std::basic_istream<_CharT, _Traits>&
2516 operator>>(std::basic_istream<_CharT, _Traits>&,
2517 std::gamma_distribution<_RealType1>&);
2520 param_type _M_param;
2522 std::normal_distribution<result_type> _M_nd;
2526 * @brief Return true if two gamma distributions are different.
2528 template<typename _RealType>
2530 operator!=(const std::gamma_distribution<_RealType>& __d1,
2531 const std::gamma_distribution<_RealType>& __d2)
2532 { return !(__d1 == __d2); }
2536 * @brief A chi_squared_distribution random number distribution.
2538 * The formula for the normal probability mass function is
2539 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2541 template<typename _RealType = double>
2542 class chi_squared_distribution
2544 static_assert(std::is_floating_point<_RealType>::value,
2545 "template argument not a floating point type");
2548 /** The type of the range of the distribution. */
2549 typedef _RealType result_type;
2550 /** Parameter type. */
2553 typedef chi_squared_distribution<_RealType> distribution_type;
2556 param_type(_RealType __n = _RealType(1))
2565 operator==(const param_type& __p1, const param_type& __p2)
2566 { return __p1._M_n == __p2._M_n; }
2573 chi_squared_distribution(_RealType __n = _RealType(1))
2574 : _M_param(__n), _M_gd(__n / 2)
2578 chi_squared_distribution(const param_type& __p)
2579 : _M_param(__p), _M_gd(__p.n() / 2)
2583 * @brief Resets the distribution state.
2594 { return _M_param.n(); }
2597 * @brief Returns the parameter set of the distribution.
2601 { return _M_param; }
2604 * @brief Sets the parameter set of the distribution.
2605 * @param __param The new parameter set of the distribution.
2608 param(const param_type& __param)
2609 { _M_param = __param; }
2612 * @brief Returns the greatest lower bound value of the distribution.
2616 { return result_type(0); }
2619 * @brief Returns the least upper bound value of the distribution.
2623 { return std::numeric_limits<result_type>::max(); }
2626 * @brief Generating functions.
2628 template<typename _UniformRandomNumberGenerator>
2630 operator()(_UniformRandomNumberGenerator& __urng)
2631 { return 2 * _M_gd(__urng); }
2633 template<typename _UniformRandomNumberGenerator>
2635 operator()(_UniformRandomNumberGenerator& __urng,
2636 const param_type& __p)
2638 typedef typename std::gamma_distribution<result_type>::param_type
2640 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2644 * @brief Return true if two Chi-squared distributions have
2645 * the same parameters and the sequences that would be
2646 * generated are equal.
2648 template<typename _RealType1>
2650 operator==(const std::chi_squared_distribution<_RealType1>& __d1,
2651 const std::chi_squared_distribution<_RealType1>& __d2)
2652 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2655 * @brief Inserts a %chi_squared_distribution random number distribution
2656 * @p __x into the output stream @p __os.
2658 * @param __os An output stream.
2659 * @param __x A %chi_squared_distribution random number distribution.
2661 * @returns The output stream with the state of @p __x inserted or in
2664 template<typename _RealType1, typename _CharT, typename _Traits>
2665 friend std::basic_ostream<_CharT, _Traits>&
2666 operator<<(std::basic_ostream<_CharT, _Traits>&,
2667 const std::chi_squared_distribution<_RealType1>&);
2670 * @brief Extracts a %chi_squared_distribution random number distribution
2671 * @p __x from the input stream @p __is.
2673 * @param __is An input stream.
2674 * @param __x A %chi_squared_distribution random number
2677 * @returns The input stream with @p __x extracted or in an error state.
2679 template<typename _RealType1, typename _CharT, typename _Traits>
2680 friend std::basic_istream<_CharT, _Traits>&
2681 operator>>(std::basic_istream<_CharT, _Traits>&,
2682 std::chi_squared_distribution<_RealType1>&);
2685 param_type _M_param;
2687 std::gamma_distribution<result_type> _M_gd;
2691 * @brief Return true if two Chi-squared distributions are different.
2693 template<typename _RealType>
2695 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2696 const std::chi_squared_distribution<_RealType>& __d2)
2697 { return !(__d1 == __d2); }
2701 * @brief A cauchy_distribution random number distribution.
2703 * The formula for the normal probability mass function is
2704 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2706 template<typename _RealType = double>
2707 class cauchy_distribution
2709 static_assert(std::is_floating_point<_RealType>::value,
2710 "template argument not a floating point type");
2713 /** The type of the range of the distribution. */
2714 typedef _RealType result_type;
2715 /** Parameter type. */
2718 typedef cauchy_distribution<_RealType> distribution_type;
2721 param_type(_RealType __a = _RealType(0),
2722 _RealType __b = _RealType(1))
2723 : _M_a(__a), _M_b(__b)
2735 operator==(const param_type& __p1, const param_type& __p2)
2736 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2744 cauchy_distribution(_RealType __a = _RealType(0),
2745 _RealType __b = _RealType(1))
2746 : _M_param(__a, __b)
2750 cauchy_distribution(const param_type& __p)
2755 * @brief Resets the distribution state.
2766 { return _M_param.a(); }
2770 { return _M_param.b(); }
2773 * @brief Returns the parameter set of the distribution.
2777 { return _M_param; }
2780 * @brief Sets the parameter set of the distribution.
2781 * @param __param The new parameter set of the distribution.
2784 param(const param_type& __param)
2785 { _M_param = __param; }
2788 * @brief Returns the greatest lower bound value of the distribution.
2792 { return std::numeric_limits<result_type>::min(); }
2795 * @brief Returns the least upper bound value of the distribution.
2799 { return std::numeric_limits<result_type>::max(); }
2802 * @brief Generating functions.
2804 template<typename _UniformRandomNumberGenerator>
2806 operator()(_UniformRandomNumberGenerator& __urng)
2807 { return this->operator()(__urng, this->param()); }
2809 template<typename _UniformRandomNumberGenerator>
2811 operator()(_UniformRandomNumberGenerator& __urng,
2812 const param_type& __p);
2815 param_type _M_param;
2819 * @brief Return true if two Cauchy distributions have
2820 * the same parameters.
2822 template<typename _RealType>
2824 operator==(const std::cauchy_distribution<_RealType>& __d1,
2825 const std::cauchy_distribution<_RealType>& __d2)
2826 { return __d1.param() == __d2.param(); }
2829 * @brief Return true if two Cauchy distributions have
2830 * different parameters.
2832 template<typename _RealType>
2834 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2835 const std::cauchy_distribution<_RealType>& __d2)
2836 { return !(__d1 == __d2); }
2839 * @brief Inserts a %cauchy_distribution random number distribution
2840 * @p __x into the output stream @p __os.
2842 * @param __os An output stream.
2843 * @param __x A %cauchy_distribution random number distribution.
2845 * @returns The output stream with the state of @p __x inserted or in
2848 template<typename _RealType, typename _CharT, typename _Traits>
2849 std::basic_ostream<_CharT, _Traits>&
2850 operator<<(std::basic_ostream<_CharT, _Traits>&,
2851 const std::cauchy_distribution<_RealType>&);
2854 * @brief Extracts a %cauchy_distribution random number distribution
2855 * @p __x from the input stream @p __is.
2857 * @param __is An input stream.
2858 * @param __x A %cauchy_distribution random number
2861 * @returns The input stream with @p __x extracted or in an error state.
2863 template<typename _RealType, typename _CharT, typename _Traits>
2864 std::basic_istream<_CharT, _Traits>&
2865 operator>>(std::basic_istream<_CharT, _Traits>&,
2866 std::cauchy_distribution<_RealType>&);
2870 * @brief A fisher_f_distribution random number distribution.
2872 * The formula for the normal probability mass function is
2874 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2875 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2876 * (1 + \frac{mx}{n})^{-(m+n)/2}
2879 template<typename _RealType = double>
2880 class fisher_f_distribution
2882 static_assert(std::is_floating_point<_RealType>::value,
2883 "template argument not a floating point type");
2886 /** The type of the range of the distribution. */
2887 typedef _RealType result_type;
2888 /** Parameter type. */
2891 typedef fisher_f_distribution<_RealType> distribution_type;
2894 param_type(_RealType __m = _RealType(1),
2895 _RealType __n = _RealType(1))
2896 : _M_m(__m), _M_n(__n)
2908 operator==(const param_type& __p1, const param_type& __p2)
2909 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2917 fisher_f_distribution(_RealType __m = _RealType(1),
2918 _RealType __n = _RealType(1))
2919 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2923 fisher_f_distribution(const param_type& __p)
2924 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2928 * @brief Resets the distribution state.
2942 { return _M_param.m(); }
2946 { return _M_param.n(); }
2949 * @brief Returns the parameter set of the distribution.
2953 { return _M_param; }
2956 * @brief Sets the parameter set of the distribution.
2957 * @param __param The new parameter set of the distribution.
2960 param(const param_type& __param)
2961 { _M_param = __param; }
2964 * @brief Returns the greatest lower bound value of the distribution.
2968 { return result_type(0); }
2971 * @brief Returns the least upper bound value of the distribution.
2975 { return std::numeric_limits<result_type>::max(); }
2978 * @brief Generating functions.
2980 template<typename _UniformRandomNumberGenerator>
2982 operator()(_UniformRandomNumberGenerator& __urng)
2983 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2985 template<typename _UniformRandomNumberGenerator>
2987 operator()(_UniformRandomNumberGenerator& __urng,
2988 const param_type& __p)
2990 typedef typename std::gamma_distribution<result_type>::param_type
2992 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2993 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2997 * @brief Return true if two Fisher f distributions have
2998 * the same parameters and the sequences that would
2999 * be generated are equal.
3001 template<typename _RealType1>
3003 operator==(const std::fisher_f_distribution<_RealType1>& __d1,
3004 const std::fisher_f_distribution<_RealType1>& __d2)
3005 { return (__d1.param() == __d2.param()
3006 && __d1._M_gd_x == __d2._M_gd_x
3007 && __d1._M_gd_y == __d2._M_gd_y); }
3010 * @brief Inserts a %fisher_f_distribution random number distribution
3011 * @p __x into the output stream @p __os.
3013 * @param __os An output stream.
3014 * @param __x A %fisher_f_distribution random number distribution.
3016 * @returns The output stream with the state of @p __x inserted or in
3019 template<typename _RealType1, typename _CharT, typename _Traits>
3020 friend std::basic_ostream<_CharT, _Traits>&
3021 operator<<(std::basic_ostream<_CharT, _Traits>&,
3022 const std::fisher_f_distribution<_RealType1>&);
3025 * @brief Extracts a %fisher_f_distribution random number distribution
3026 * @p __x from the input stream @p __is.
3028 * @param __is An input stream.
3029 * @param __x A %fisher_f_distribution random number
3032 * @returns The input stream with @p __x extracted or in an error state.
3034 template<typename _RealType1, typename _CharT, typename _Traits>
3035 friend std::basic_istream<_CharT, _Traits>&
3036 operator>>(std::basic_istream<_CharT, _Traits>&,
3037 std::fisher_f_distribution<_RealType1>&);
3040 param_type _M_param;
3042 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3046 * @brief Return true if two Fisher f distributions are diferent.
3048 template<typename _RealType>
3050 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3051 const std::fisher_f_distribution<_RealType>& __d2)
3052 { return !(__d1 == __d2); }
3055 * @brief A student_t_distribution random number distribution.
3057 * The formula for the normal probability mass function is:
3059 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3060 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3063 template<typename _RealType = double>
3064 class student_t_distribution
3066 static_assert(std::is_floating_point<_RealType>::value,
3067 "template argument not a floating point type");
3070 /** The type of the range of the distribution. */
3071 typedef _RealType result_type;
3072 /** Parameter type. */
3075 typedef student_t_distribution<_RealType> distribution_type;
3078 param_type(_RealType __n = _RealType(1))
3087 operator==(const param_type& __p1, const param_type& __p2)
3088 { return __p1._M_n == __p2._M_n; }
3095 student_t_distribution(_RealType __n = _RealType(1))
3096 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3100 student_t_distribution(const param_type& __p)
3101 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3105 * @brief Resets the distribution state.
3119 { return _M_param.n(); }
3122 * @brief Returns the parameter set of the distribution.
3126 { return _M_param; }
3129 * @brief Sets the parameter set of the distribution.
3130 * @param __param The new parameter set of the distribution.
3133 param(const param_type& __param)
3134 { _M_param = __param; }
3137 * @brief Returns the greatest lower bound value of the distribution.
3141 { return std::numeric_limits<result_type>::min(); }
3144 * @brief Returns the least upper bound value of the distribution.
3148 { return std::numeric_limits<result_type>::max(); }
3151 * @brief Generating functions.
3153 template<typename _UniformRandomNumberGenerator>
3155 operator()(_UniformRandomNumberGenerator& __urng)
3156 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3158 template<typename _UniformRandomNumberGenerator>
3160 operator()(_UniformRandomNumberGenerator& __urng,
3161 const param_type& __p)
3163 typedef typename std::gamma_distribution<result_type>::param_type
3166 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3167 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3171 * @brief Return true if two Student t distributions have
3172 * the same parameters and the sequences that would
3173 * be generated are equal.
3175 template<typename _RealType1>
3177 operator==(const std::student_t_distribution<_RealType1>& __d1,
3178 const std::student_t_distribution<_RealType1>& __d2)
3179 { return (__d1.param() == __d2.param()
3180 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3183 * @brief Inserts a %student_t_distribution random number distribution
3184 * @p __x into the output stream @p __os.
3186 * @param __os An output stream.
3187 * @param __x A %student_t_distribution random number distribution.
3189 * @returns The output stream with the state of @p __x inserted or in
3192 template<typename _RealType1, typename _CharT, typename _Traits>
3193 friend std::basic_ostream<_CharT, _Traits>&
3194 operator<<(std::basic_ostream<_CharT, _Traits>&,
3195 const std::student_t_distribution<_RealType1>&);
3198 * @brief Extracts a %student_t_distribution random number distribution
3199 * @p __x from the input stream @p __is.
3201 * @param __is An input stream.
3202 * @param __x A %student_t_distribution random number
3205 * @returns The input stream with @p __x extracted or in an error state.
3207 template<typename _RealType1, typename _CharT, typename _Traits>
3208 friend std::basic_istream<_CharT, _Traits>&
3209 operator>>(std::basic_istream<_CharT, _Traits>&,
3210 std::student_t_distribution<_RealType1>&);
3213 param_type _M_param;
3215 std::normal_distribution<result_type> _M_nd;
3216 std::gamma_distribution<result_type> _M_gd;
3220 * @brief Return true if two Student t distributions are different.
3222 template<typename _RealType>
3224 operator!=(const std::student_t_distribution<_RealType>& __d1,
3225 const std::student_t_distribution<_RealType>& __d2)
3226 { return !(__d1 == __d2); }
3229 /* @} */ // group random_distributions_normal
3232 * @addtogroup random_distributions_bernoulli Bernoulli
3233 * @ingroup random_distributions
3238 * @brief A Bernoulli random number distribution.
3240 * Generates a sequence of true and false values with likelihood @f$p@f$
3241 * that true will come up and @f$(1 - p)@f$ that false will appear.
3243 class bernoulli_distribution
3246 /** The type of the range of the distribution. */
3247 typedef bool result_type;
3248 /** Parameter type. */
3251 typedef bernoulli_distribution distribution_type;
3254 param_type(double __p = 0.5)
3257 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3265 operator==(const param_type& __p1, const param_type& __p2)
3266 { return __p1._M_p == __p2._M_p; }
3274 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3276 * @param __p [IN] The likelihood of a true result being returned.
3277 * Must be in the interval @f$[0, 1]@f$.
3280 bernoulli_distribution(double __p = 0.5)
3285 bernoulli_distribution(const param_type& __p)
3290 * @brief Resets the distribution state.
3292 * Does nothing for a Bernoulli distribution.
3298 * @brief Returns the @p p parameter of the distribution.
3302 { return _M_param.p(); }
3305 * @brief Returns the parameter set of the distribution.
3309 { return _M_param; }
3312 * @brief Sets the parameter set of the distribution.
3313 * @param __param The new parameter set of the distribution.
3316 param(const param_type& __param)
3317 { _M_param = __param; }
3320 * @brief Returns the greatest lower bound value of the distribution.
3324 { return std::numeric_limits<result_type>::min(); }
3327 * @brief Returns the least upper bound value of the distribution.
3331 { return std::numeric_limits<result_type>::max(); }
3334 * @brief Generating functions.
3336 template<typename _UniformRandomNumberGenerator>
3338 operator()(_UniformRandomNumberGenerator& __urng)
3339 { return this->operator()(__urng, this->param()); }
3341 template<typename _UniformRandomNumberGenerator>
3343 operator()(_UniformRandomNumberGenerator& __urng,
3344 const param_type& __p)
3346 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3348 if ((__aurng() - __aurng.min())
3349 < __p.p() * (__aurng.max() - __aurng.min()))
3355 param_type _M_param;
3359 * @brief Return true if two Bernoulli distributions have
3360 * the same parameters.
3363 operator==(const std::bernoulli_distribution& __d1,
3364 const std::bernoulli_distribution& __d2)
3365 { return __d1.param() == __d2.param(); }
3368 * @brief Return true if two Bernoulli distributions have
3369 * different parameters.
3372 operator!=(const std::bernoulli_distribution& __d1,
3373 const std::bernoulli_distribution& __d2)
3374 { return !(__d1 == __d2); }
3377 * @brief Inserts a %bernoulli_distribution random number distribution
3378 * @p __x into the output stream @p __os.
3380 * @param __os An output stream.
3381 * @param __x A %bernoulli_distribution random number distribution.
3383 * @returns The output stream with the state of @p __x inserted or in
3386 template<typename _CharT, typename _Traits>
3387 std::basic_ostream<_CharT, _Traits>&
3388 operator<<(std::basic_ostream<_CharT, _Traits>&,
3389 const std::bernoulli_distribution&);
3392 * @brief Extracts a %bernoulli_distribution random number distribution
3393 * @p __x from the input stream @p __is.
3395 * @param __is An input stream.
3396 * @param __x A %bernoulli_distribution random number generator engine.
3398 * @returns The input stream with @p __x extracted or in an error state.
3400 template<typename _CharT, typename _Traits>
3401 std::basic_istream<_CharT, _Traits>&
3402 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3403 std::bernoulli_distribution& __x)
3407 __x.param(bernoulli_distribution::param_type(__p));
3413 * @brief A discrete binomial random number distribution.
3415 * The formula for the binomial probability density function is
3416 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3417 * and @f$p@f$ are the parameters of the distribution.
3419 template<typename _IntType = int>
3420 class binomial_distribution
3422 static_assert(std::is_integral<_IntType>::value,
3423 "template argument not an integral type");
3426 /** The type of the range of the distribution. */
3427 typedef _IntType result_type;
3428 /** Parameter type. */
3431 typedef binomial_distribution<_IntType> distribution_type;
3432 friend class binomial_distribution<_IntType>;
3435 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3436 : _M_t(__t), _M_p(__p)
3438 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3453 operator==(const param_type& __p1, const param_type& __p2)
3454 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3464 #if _GLIBCXX_USE_C99_MATH_TR1
3465 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3466 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3471 // constructors and member function
3473 binomial_distribution(_IntType __t = _IntType(1),
3475 : _M_param(__t, __p), _M_nd()
3479 binomial_distribution(const param_type& __p)
3480 : _M_param(__p), _M_nd()
3484 * @brief Resets the distribution state.
3491 * @brief Returns the distribution @p t parameter.
3495 { return _M_param.t(); }
3498 * @brief Returns the distribution @p p parameter.
3502 { return _M_param.p(); }
3505 * @brief Returns the parameter set of the distribution.
3509 { return _M_param; }
3512 * @brief Sets the parameter set of the distribution.
3513 * @param __param The new parameter set of the distribution.
3516 param(const param_type& __param)
3517 { _M_param = __param; }
3520 * @brief Returns the greatest lower bound value of the distribution.
3527 * @brief Returns the least upper bound value of the distribution.
3531 { return _M_param.t(); }
3534 * @brief Generating functions.
3536 template<typename _UniformRandomNumberGenerator>
3538 operator()(_UniformRandomNumberGenerator& __urng)
3539 { return this->operator()(__urng, this->param()); }
3541 template<typename _UniformRandomNumberGenerator>
3543 operator()(_UniformRandomNumberGenerator& __urng,
3544 const param_type& __p);
3547 * @brief Return true if two binomial distributions have
3548 * the same parameters and the sequences that would
3549 * be generated are equal.
3551 template<typename _IntType1>
3553 operator==(const std::binomial_distribution<_IntType1>& __d1,
3554 const std::binomial_distribution<_IntType1>& __d2)
3555 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3556 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3558 { return __d1.param() == __d2.param(); }
3562 * @brief Inserts a %binomial_distribution random number distribution
3563 * @p __x into the output stream @p __os.
3565 * @param __os An output stream.
3566 * @param __x A %binomial_distribution random number distribution.
3568 * @returns The output stream with the state of @p __x inserted or in
3571 template<typename _IntType1,
3572 typename _CharT, typename _Traits>
3573 friend std::basic_ostream<_CharT, _Traits>&
3574 operator<<(std::basic_ostream<_CharT, _Traits>&,
3575 const std::binomial_distribution<_IntType1>&);
3578 * @brief Extracts a %binomial_distribution random number distribution
3579 * @p __x from the input stream @p __is.
3581 * @param __is An input stream.
3582 * @param __x A %binomial_distribution random number generator engine.
3584 * @returns The input stream with @p __x extracted or in an error
3587 template<typename _IntType1,
3588 typename _CharT, typename _Traits>
3589 friend std::basic_istream<_CharT, _Traits>&
3590 operator>>(std::basic_istream<_CharT, _Traits>&,
3591 std::binomial_distribution<_IntType1>&);
3594 template<typename _UniformRandomNumberGenerator>
3596 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3598 param_type _M_param;
3600 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3601 std::normal_distribution<double> _M_nd;
3605 * @brief Return true if two binomial distributions are different.
3607 template<typename _IntType>
3609 operator!=(const std::binomial_distribution<_IntType>& __d1,
3610 const std::binomial_distribution<_IntType>& __d2)
3611 { return !(__d1 == __d2); }
3615 * @brief A discrete geometric random number distribution.
3617 * The formula for the geometric probability density function is
3618 * @f$p(i|p) = (1 - p)p^{i-1}@f$ where @f$p@f$ is the parameter of the
3621 template<typename _IntType = int>
3622 class geometric_distribution
3624 static_assert(std::is_integral<_IntType>::value,
3625 "template argument not an integral type");
3628 /** The type of the range of the distribution. */
3629 typedef _IntType result_type;
3630 /** Parameter type. */
3633 typedef geometric_distribution<_IntType> distribution_type;
3634 friend class geometric_distribution<_IntType>;
3637 param_type(double __p = 0.5)
3640 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
3650 operator==(const param_type& __p1, const param_type& __p2)
3651 { return __p1._M_p == __p2._M_p; }
3656 { _M_log_p = std::log(_M_p); }
3663 // constructors and member function
3665 geometric_distribution(double __p = 0.5)
3670 geometric_distribution(const param_type& __p)
3675 * @brief Resets the distribution state.
3677 * Does nothing for the geometric distribution.
3683 * @brief Returns the distribution parameter @p p.
3687 { return _M_param.p(); }
3690 * @brief Returns the parameter set of the distribution.
3694 { return _M_param; }
3697 * @brief Sets the parameter set of the distribution.
3698 * @param __param The new parameter set of the distribution.
3701 param(const param_type& __param)
3702 { _M_param = __param; }
3705 * @brief Returns the greatest lower bound value of the distribution.
3712 * @brief Returns the least upper bound value of the distribution.
3716 { return std::numeric_limits<result_type>::max(); }
3719 * @brief Generating functions.
3721 template<typename _UniformRandomNumberGenerator>
3723 operator()(_UniformRandomNumberGenerator& __urng)
3724 { return this->operator()(__urng, this->param()); }
3726 template<typename _UniformRandomNumberGenerator>
3728 operator()(_UniformRandomNumberGenerator& __urng,
3729 const param_type& __p);
3732 param_type _M_param;
3736 * @brief Return true if two geometric distributions have
3737 * the same parameters.
3739 template<typename _IntType>
3741 operator==(const std::geometric_distribution<_IntType>& __d1,
3742 const std::geometric_distribution<_IntType>& __d2)
3743 { return __d1.param() == __d2.param(); }
3746 * @brief Return true if two geometric distributions have
3747 * different parameters.
3749 template<typename _IntType>
3751 operator!=(const std::geometric_distribution<_IntType>& __d1,
3752 const std::geometric_distribution<_IntType>& __d2)
3753 { return !(__d1 == __d2); }
3756 * @brief Inserts a %geometric_distribution random number distribution
3757 * @p __x into the output stream @p __os.
3759 * @param __os An output stream.
3760 * @param __x A %geometric_distribution random number distribution.
3762 * @returns The output stream with the state of @p __x inserted or in
3765 template<typename _IntType,
3766 typename _CharT, typename _Traits>
3767 std::basic_ostream<_CharT, _Traits>&
3768 operator<<(std::basic_ostream<_CharT, _Traits>&,
3769 const std::geometric_distribution<_IntType>&);
3772 * @brief Extracts a %geometric_distribution random number distribution
3773 * @p __x from the input stream @p __is.
3775 * @param __is An input stream.
3776 * @param __x A %geometric_distribution random number generator engine.
3778 * @returns The input stream with @p __x extracted or in an error state.
3780 template<typename _IntType,
3781 typename _CharT, typename _Traits>
3782 std::basic_istream<_CharT, _Traits>&
3783 operator>>(std::basic_istream<_CharT, _Traits>&,
3784 std::geometric_distribution<_IntType>&);
3788 * @brief A negative_binomial_distribution random number distribution.
3790 * The formula for the negative binomial probability mass function is
3791 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3792 * and @f$p@f$ are the parameters of the distribution.
3794 template<typename _IntType = int>
3795 class negative_binomial_distribution
3797 static_assert(std::is_integral<_IntType>::value,
3798 "template argument not an integral type");
3801 /** The type of the range of the distribution. */
3802 typedef _IntType result_type;
3803 /** Parameter type. */
3806 typedef negative_binomial_distribution<_IntType> distribution_type;
3809 param_type(_IntType __k = 1, double __p = 0.5)
3810 : _M_k(__k), _M_p(__p)
3822 operator==(const param_type& __p1, const param_type& __p2)
3823 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3831 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3832 : _M_param(__k, __p), _M_gd(__k, __p / (1.0 - __p))
3836 negative_binomial_distribution(const param_type& __p)
3837 : _M_param(__p), _M_gd(__p.k(), __p.p() / (1.0 - __p.p()))
3841 * @brief Resets the distribution state.
3848 * @brief Return the @f$k@f$ parameter of the distribution.
3852 { return _M_param.k(); }
3855 * @brief Return the @f$p@f$ parameter of the distribution.
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.
3881 { return result_type(0); }
3884 * @brief Returns the least upper bound value of the distribution.
3888 { return std::numeric_limits<result_type>::max(); }
3891 * @brief Generating functions.
3893 template<typename _UniformRandomNumberGenerator>
3895 operator()(_UniformRandomNumberGenerator& __urng);
3897 template<typename _UniformRandomNumberGenerator>
3899 operator()(_UniformRandomNumberGenerator& __urng,
3900 const param_type& __p);
3903 * @brief Return true if two negative binomial distributions have
3904 * the same parameters and the sequences that would be
3905 * generated are equal.
3907 template<typename _IntType1>
3909 operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
3910 const std::negative_binomial_distribution<_IntType1>& __d2)
3911 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3914 * @brief Inserts a %negative_binomial_distribution random
3915 * number distribution @p __x into the output stream @p __os.
3917 * @param __os An output stream.
3918 * @param __x A %negative_binomial_distribution random number
3921 * @returns The output stream with the state of @p __x inserted or in
3924 template<typename _IntType1, typename _CharT, typename _Traits>
3925 friend std::basic_ostream<_CharT, _Traits>&
3926 operator<<(std::basic_ostream<_CharT, _Traits>&,
3927 const std::negative_binomial_distribution<_IntType1>&);
3930 * @brief Extracts a %negative_binomial_distribution random number
3931 * distribution @p __x from the input stream @p __is.
3933 * @param __is An input stream.
3934 * @param __x A %negative_binomial_distribution random number
3937 * @returns The input stream with @p __x extracted or in an error state.
3939 template<typename _IntType1, typename _CharT, typename _Traits>
3940 friend std::basic_istream<_CharT, _Traits>&
3941 operator>>(std::basic_istream<_CharT, _Traits>&,
3942 std::negative_binomial_distribution<_IntType1>&);
3945 param_type _M_param;
3947 std::gamma_distribution<double> _M_gd;
3951 * @brief Return true if two negative binomial distributions are different.
3953 template<typename _IntType>
3955 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3956 const std::negative_binomial_distribution<_IntType>& __d2)
3957 { return !(__d1 == __d2); }
3960 /* @} */ // group random_distributions_bernoulli
3963 * @addtogroup random_distributions_poisson Poisson
3964 * @ingroup random_distributions
3969 * @brief A discrete Poisson random number distribution.
3971 * The formula for the Poisson probability density function is
3972 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3973 * parameter of the distribution.
3975 template<typename _IntType = int>
3976 class poisson_distribution
3978 static_assert(std::is_integral<_IntType>::value,
3979 "template argument not an integral type");
3982 /** The type of the range of the distribution. */
3983 typedef _IntType result_type;
3984 /** Parameter type. */
3987 typedef poisson_distribution<_IntType> distribution_type;
3988 friend class poisson_distribution<_IntType>;
3991 param_type(double __mean = 1.0)
3994 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
4003 operator==(const param_type& __p1, const param_type& __p2)
4004 { return __p1._M_mean == __p2._M_mean; }
4007 // Hosts either log(mean) or the threshold of the simple method.
4014 #if _GLIBCXX_USE_C99_MATH_TR1
4015 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4019 // constructors and member function
4021 poisson_distribution(double __mean = 1.0)
4022 : _M_param(__mean), _M_nd()
4026 poisson_distribution(const param_type& __p)
4027 : _M_param(__p), _M_nd()
4031 * @brief Resets the distribution state.
4038 * @brief Returns the distribution parameter @p mean.
4042 { return _M_param.mean(); }
4045 * @brief Returns the parameter set of the distribution.
4049 { return _M_param; }
4052 * @brief Sets the parameter set of the distribution.
4053 * @param __param The new parameter set of the distribution.
4056 param(const param_type& __param)
4057 { _M_param = __param; }
4060 * @brief Returns the greatest lower bound value of the distribution.
4067 * @brief Returns the least upper bound value of the distribution.
4071 { return std::numeric_limits<result_type>::max(); }
4074 * @brief Generating functions.
4076 template<typename _UniformRandomNumberGenerator>
4078 operator()(_UniformRandomNumberGenerator& __urng)
4079 { return this->operator()(__urng, this->param()); }
4081 template<typename _UniformRandomNumberGenerator>
4083 operator()(_UniformRandomNumberGenerator& __urng,
4084 const param_type& __p);
4087 * @brief Return true if two Poisson distributions have the same
4088 * parameters and the sequences that would be generated
4091 template<typename _IntType1>
4093 operator==(const std::poisson_distribution<_IntType1>& __d1,
4094 const std::poisson_distribution<_IntType1>& __d2)
4095 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4096 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4098 { return __d1.param() == __d2.param(); }
4102 * @brief Inserts a %poisson_distribution random number distribution
4103 * @p __x into the output stream @p __os.
4105 * @param __os An output stream.
4106 * @param __x A %poisson_distribution random number distribution.
4108 * @returns The output stream with the state of @p __x inserted or in
4111 template<typename _IntType1, typename _CharT, typename _Traits>
4112 friend std::basic_ostream<_CharT, _Traits>&
4113 operator<<(std::basic_ostream<_CharT, _Traits>&,
4114 const std::poisson_distribution<_IntType1>&);
4117 * @brief Extracts a %poisson_distribution random number distribution
4118 * @p __x from the input stream @p __is.
4120 * @param __is An input stream.
4121 * @param __x A %poisson_distribution random number generator engine.
4123 * @returns The input stream with @p __x extracted or in an error
4126 template<typename _IntType1, typename _CharT, typename _Traits>
4127 friend std::basic_istream<_CharT, _Traits>&
4128 operator>>(std::basic_istream<_CharT, _Traits>&,
4129 std::poisson_distribution<_IntType1>&);
4132 param_type _M_param;
4134 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4135 std::normal_distribution<double> _M_nd;
4139 * @brief Return true if two Poisson distributions are different.
4141 template<typename _IntType>
4143 operator!=(const std::poisson_distribution<_IntType>& __d1,
4144 const std::poisson_distribution<_IntType>& __d2)
4145 { return !(__d1 == __d2); }
4149 * @brief An exponential continuous distribution for random numbers.
4151 * The formula for the exponential probability density function is
4152 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4154 * <table border=1 cellpadding=10 cellspacing=0>
4155 * <caption align=top>Distribution Statistics</caption>
4156 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4157 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4158 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4159 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4160 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4163 template<typename _RealType = double>
4164 class exponential_distribution
4166 static_assert(std::is_floating_point<_RealType>::value,
4167 "template argument not a floating point type");
4170 /** The type of the range of the distribution. */
4171 typedef _RealType result_type;
4172 /** Parameter type. */
4175 typedef exponential_distribution<_RealType> distribution_type;
4178 param_type(_RealType __lambda = _RealType(1))
4179 : _M_lambda(__lambda)
4181 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4186 { return _M_lambda; }
4189 operator==(const param_type& __p1, const param_type& __p2)
4190 { return __p1._M_lambda == __p2._M_lambda; }
4193 _RealType _M_lambda;
4198 * @brief Constructs an exponential distribution with inverse scale
4199 * parameter @f$\lambda@f$.
4202 exponential_distribution(const result_type& __lambda = result_type(1))
4203 : _M_param(__lambda)
4207 exponential_distribution(const param_type& __p)
4212 * @brief Resets the distribution state.
4214 * Has no effect on exponential distributions.
4220 * @brief Returns the inverse scale parameter of the distribution.
4224 { return _M_param.lambda(); }
4227 * @brief Returns the parameter set of the distribution.
4231 { return _M_param; }
4234 * @brief Sets the parameter set of the distribution.
4235 * @param __param The new parameter set of the distribution.
4238 param(const param_type& __param)
4239 { _M_param = __param; }
4242 * @brief Returns the greatest lower bound value of the distribution.
4246 { return result_type(0); }
4249 * @brief Returns the least upper bound value of the distribution.
4253 { return std::numeric_limits<result_type>::max(); }
4256 * @brief Generating functions.
4258 template<typename _UniformRandomNumberGenerator>
4260 operator()(_UniformRandomNumberGenerator& __urng)
4261 { return this->operator()(__urng, this->param()); }
4263 template<typename _UniformRandomNumberGenerator>
4265 operator()(_UniformRandomNumberGenerator& __urng,
4266 const param_type& __p)
4268 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4270 return -std::log(__aurng()) / __p.lambda();
4274 param_type _M_param;
4278 * @brief Return true if two exponential distributions have the same
4281 template<typename _RealType>
4283 operator==(const std::exponential_distribution<_RealType>& __d1,
4284 const std::exponential_distribution<_RealType>& __d2)
4285 { return __d1.param() == __d2.param(); }
4288 * @brief Return true if two exponential distributions have different
4291 template<typename _RealType>
4293 operator!=(const std::exponential_distribution<_RealType>& __d1,
4294 const std::exponential_distribution<_RealType>& __d2)
4295 { return !(__d1 == __d2); }
4298 * @brief Inserts a %exponential_distribution random number distribution
4299 * @p __x into the output stream @p __os.
4301 * @param __os An output stream.
4302 * @param __x A %exponential_distribution random number distribution.
4304 * @returns The output stream with the state of @p __x inserted or in
4307 template<typename _RealType, typename _CharT, typename _Traits>
4308 std::basic_ostream<_CharT, _Traits>&
4309 operator<<(std::basic_ostream<_CharT, _Traits>&,
4310 const std::exponential_distribution<_RealType>&);
4313 * @brief Extracts a %exponential_distribution random number distribution
4314 * @p __x from the input stream @p __is.
4316 * @param __is An input stream.
4317 * @param __x A %exponential_distribution random number
4320 * @returns The input stream with @p __x extracted or in an error state.
4322 template<typename _RealType, typename _CharT, typename _Traits>
4323 std::basic_istream<_CharT, _Traits>&
4324 operator>>(std::basic_istream<_CharT, _Traits>&,
4325 std::exponential_distribution<_RealType>&);
4329 * @brief A weibull_distribution random number distribution.
4331 * The formula for the normal probability density function is:
4333 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4334 * \exp{(-(\frac{x}{\beta})^\alpha)}
4337 template<typename _RealType = double>
4338 class weibull_distribution
4340 static_assert(std::is_floating_point<_RealType>::value,
4341 "template argument not a floating point type");
4344 /** The type of the range of the distribution. */
4345 typedef _RealType result_type;
4346 /** Parameter type. */
4349 typedef weibull_distribution<_RealType> distribution_type;
4352 param_type(_RealType __a = _RealType(1),
4353 _RealType __b = _RealType(1))
4354 : _M_a(__a), _M_b(__b)
4366 operator==(const param_type& __p1, const param_type& __p2)
4367 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4375 weibull_distribution(_RealType __a = _RealType(1),
4376 _RealType __b = _RealType(1))
4377 : _M_param(__a, __b)
4381 weibull_distribution(const param_type& __p)
4386 * @brief Resets the distribution state.
4393 * @brief Return the @f$a@f$ parameter of the distribution.
4397 { return _M_param.a(); }
4400 * @brief Return the @f$b@f$ parameter of the distribution.
4404 { return _M_param.b(); }
4407 * @brief Returns the parameter set of the distribution.
4411 { return _M_param; }
4414 * @brief Sets the parameter set of the distribution.
4415 * @param __param The new parameter set of the distribution.
4418 param(const param_type& __param)
4419 { _M_param = __param; }
4422 * @brief Returns the greatest lower bound value of the distribution.
4426 { return result_type(0); }
4429 * @brief Returns the least upper bound value of the distribution.
4433 { return std::numeric_limits<result_type>::max(); }
4436 * @brief Generating functions.
4438 template<typename _UniformRandomNumberGenerator>
4440 operator()(_UniformRandomNumberGenerator& __urng)
4441 { return this->operator()(__urng, this->param()); }
4443 template<typename _UniformRandomNumberGenerator>
4445 operator()(_UniformRandomNumberGenerator& __urng,
4446 const param_type& __p);
4449 param_type _M_param;
4453 * @brief Return true if two Weibull distributions have the same
4456 template<typename _RealType>
4458 operator==(const std::weibull_distribution<_RealType>& __d1,
4459 const std::weibull_distribution<_RealType>& __d2)
4460 { return __d1.param() == __d2.param(); }
4463 * @brief Return true if two Weibull distributions have different
4466 template<typename _RealType>
4468 operator!=(const std::weibull_distribution<_RealType>& __d1,
4469 const std::weibull_distribution<_RealType>& __d2)
4470 { return !(__d1 == __d2); }
4473 * @brief Inserts a %weibull_distribution random number distribution
4474 * @p __x into the output stream @p __os.
4476 * @param __os An output stream.
4477 * @param __x A %weibull_distribution random number distribution.
4479 * @returns The output stream with the state of @p __x inserted or in
4482 template<typename _RealType, typename _CharT, typename _Traits>
4483 std::basic_ostream<_CharT, _Traits>&
4484 operator<<(std::basic_ostream<_CharT, _Traits>&,
4485 const std::weibull_distribution<_RealType>&);
4488 * @brief Extracts a %weibull_distribution random number distribution
4489 * @p __x from the input stream @p __is.
4491 * @param __is An input stream.
4492 * @param __x A %weibull_distribution random number
4495 * @returns The input stream with @p __x extracted or in an error state.
4497 template<typename _RealType, typename _CharT, typename _Traits>
4498 std::basic_istream<_CharT, _Traits>&
4499 operator>>(std::basic_istream<_CharT, _Traits>&,
4500 std::weibull_distribution<_RealType>&);
4504 * @brief A extreme_value_distribution random number distribution.
4506 * The formula for the normal probability mass function is
4508 * p(x|a,b) = \frac{1}{b}
4509 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4512 template<typename _RealType = double>
4513 class extreme_value_distribution
4515 static_assert(std::is_floating_point<_RealType>::value,
4516 "template argument not a floating point type");
4519 /** The type of the range of the distribution. */
4520 typedef _RealType result_type;
4521 /** Parameter type. */
4524 typedef extreme_value_distribution<_RealType> distribution_type;
4527 param_type(_RealType __a = _RealType(0),
4528 _RealType __b = _RealType(1))
4529 : _M_a(__a), _M_b(__b)
4541 operator==(const param_type& __p1, const param_type& __p2)
4542 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4550 extreme_value_distribution(_RealType __a = _RealType(0),
4551 _RealType __b = _RealType(1))
4552 : _M_param(__a, __b)
4556 extreme_value_distribution(const param_type& __p)
4561 * @brief Resets the distribution state.
4568 * @brief Return the @f$a@f$ parameter of the distribution.
4572 { return _M_param.a(); }
4575 * @brief Return the @f$b@f$ parameter of the distribution.
4579 { return _M_param.b(); }
4582 * @brief Returns the parameter set of the distribution.
4586 { return _M_param; }
4589 * @brief Sets the parameter set of the distribution.
4590 * @param __param The new parameter set of the distribution.
4593 param(const param_type& __param)
4594 { _M_param = __param; }
4597 * @brief Returns the greatest lower bound value of the distribution.
4601 { return std::numeric_limits<result_type>::min(); }
4604 * @brief Returns the least upper bound value of the distribution.
4608 { return std::numeric_limits<result_type>::max(); }
4611 * @brief Generating functions.
4613 template<typename _UniformRandomNumberGenerator>
4615 operator()(_UniformRandomNumberGenerator& __urng)
4616 { return this->operator()(__urng, this->param()); }
4618 template<typename _UniformRandomNumberGenerator>
4620 operator()(_UniformRandomNumberGenerator& __urng,
4621 const param_type& __p);
4624 param_type _M_param;
4628 * @brief Return true if two extreme value distributions have the same
4631 template<typename _RealType>
4633 operator==(const std::extreme_value_distribution<_RealType>& __d1,
4634 const std::extreme_value_distribution<_RealType>& __d2)
4635 { return __d1.param() == __d2.param(); }
4638 * @brief Return true if two extreme value distributions have different
4641 template<typename _RealType>
4643 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4644 const std::extreme_value_distribution<_RealType>& __d2)
4645 { return !(__d1 == __d2); }
4648 * @brief Inserts a %extreme_value_distribution random number distribution
4649 * @p __x into the output stream @p __os.
4651 * @param __os An output stream.
4652 * @param __x A %extreme_value_distribution random number distribution.
4654 * @returns The output stream with the state of @p __x inserted or in
4657 template<typename _RealType, typename _CharT, typename _Traits>
4658 std::basic_ostream<_CharT, _Traits>&
4659 operator<<(std::basic_ostream<_CharT, _Traits>&,
4660 const std::extreme_value_distribution<_RealType>&);
4663 * @brief Extracts a %extreme_value_distribution random number
4664 * distribution @p __x from the input stream @p __is.
4666 * @param __is An input stream.
4667 * @param __x A %extreme_value_distribution random number
4670 * @returns The input stream with @p __x extracted or in an error state.
4672 template<typename _RealType, typename _CharT, typename _Traits>
4673 std::basic_istream<_CharT, _Traits>&
4674 operator>>(std::basic_istream<_CharT, _Traits>&,
4675 std::extreme_value_distribution<_RealType>&);
4679 * @brief A discrete_distribution random number distribution.
4681 * The formula for the discrete probability mass function is
4684 template<typename _IntType = int>
4685 class discrete_distribution
4687 static_assert(std::is_integral<_IntType>::value,
4688 "template argument not an integral type");
4691 /** The type of the range of the distribution. */
4692 typedef _IntType result_type;
4693 /** Parameter type. */
4696 typedef discrete_distribution<_IntType> distribution_type;
4697 friend class discrete_distribution<_IntType>;
4700 : _M_prob(1, 1.0), _M_cp()
4703 template<typename _InputIterator>
4704 param_type(_InputIterator __wbegin,
4705 _InputIterator __wend)
4706 : _M_prob(__wbegin, __wend), _M_cp()
4707 { _M_initialize(); }
4709 param_type(initializer_list<double> __wil)
4710 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4711 { _M_initialize(); }
4713 template<typename _Func>
4714 param_type(size_t __nw, double __xmin, double __xmax,
4717 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4718 param_type(const param_type&) = default;
4719 param_type& operator=(const param_type&) = default;
4722 probabilities() const
4726 operator==(const param_type& __p1, const param_type& __p2)
4727 { return __p1._M_prob == __p2._M_prob; }
4733 std::vector<double> _M_prob;
4734 std::vector<double> _M_cp;
4737 discrete_distribution()
4741 template<typename _InputIterator>
4742 discrete_distribution(_InputIterator __wbegin,
4743 _InputIterator __wend)
4744 : _M_param(__wbegin, __wend)
4747 discrete_distribution(initializer_list<double> __wl)
4751 template<typename _Func>
4752 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4754 : _M_param(__nw, __xmin, __xmax, __fw)
4758 discrete_distribution(const param_type& __p)
4763 * @brief Resets the distribution state.
4770 * @brief Returns the probabilities of the distribution.
4773 probabilities() const
4774 { return _M_param.probabilities(); }
4777 * @brief Returns the parameter set of the distribution.
4781 { return _M_param; }
4784 * @brief Sets the parameter set of the distribution.
4785 * @param __param The new parameter set of the distribution.
4788 param(const param_type& __param)
4789 { _M_param = __param; }
4792 * @brief Returns the greatest lower bound value of the distribution.
4796 { return result_type(0); }
4799 * @brief Returns the least upper bound value of the distribution.
4803 { return this->_M_param._M_prob.size() - 1; }
4806 * @brief Generating functions.
4808 template<typename _UniformRandomNumberGenerator>
4810 operator()(_UniformRandomNumberGenerator& __urng)
4811 { return this->operator()(__urng, this->param()); }
4813 template<typename _UniformRandomNumberGenerator>
4815 operator()(_UniformRandomNumberGenerator& __urng,
4816 const param_type& __p);
4819 * @brief Inserts a %discrete_distribution random number distribution
4820 * @p __x into the output stream @p __os.
4822 * @param __os An output stream.
4823 * @param __x A %discrete_distribution random number distribution.
4825 * @returns The output stream with the state of @p __x inserted or in
4828 template<typename _IntType1, typename _CharT, typename _Traits>
4829 friend std::basic_ostream<_CharT, _Traits>&
4830 operator<<(std::basic_ostream<_CharT, _Traits>&,
4831 const std::discrete_distribution<_IntType1>&);
4834 * @brief Extracts a %discrete_distribution random number distribution
4835 * @p __x from the input stream @p __is.
4837 * @param __is An input stream.
4838 * @param __x A %discrete_distribution random number
4841 * @returns The input stream with @p __x extracted or in an error
4844 template<typename _IntType1, typename _CharT, typename _Traits>
4845 friend std::basic_istream<_CharT, _Traits>&
4846 operator>>(std::basic_istream<_CharT, _Traits>&,
4847 std::discrete_distribution<_IntType1>&);
4850 param_type _M_param;
4854 * @brief Return true if two discrete distributions have the same
4857 template<typename _IntType>
4859 operator==(const std::discrete_distribution<_IntType>& __d1,
4860 const std::discrete_distribution<_IntType>& __d2)
4861 { return __d1.param() == __d2.param(); }
4864 * @brief Return true if two discrete distributions have different
4867 template<typename _IntType>
4869 operator!=(const std::discrete_distribution<_IntType>& __d1,
4870 const std::discrete_distribution<_IntType>& __d2)
4871 { return !(__d1 == __d2); }
4875 * @brief A piecewise_constant_distribution random number distribution.
4877 * The formula for the piecewise constant probability mass function is
4880 template<typename _RealType = double>
4881 class piecewise_constant_distribution
4883 static_assert(std::is_floating_point<_RealType>::value,
4884 "template argument not a floating point type");
4887 /** The type of the range of the distribution. */
4888 typedef _RealType result_type;
4889 /** Parameter type. */
4892 typedef piecewise_constant_distribution<_RealType> distribution_type;
4893 friend class piecewise_constant_distribution<_RealType>;
4896 : _M_int(2), _M_den(1, 1.0), _M_cp()
4897 { _M_int[1] = _RealType(1); }
4899 template<typename _InputIteratorB, typename _InputIteratorW>
4900 param_type(_InputIteratorB __bfirst,
4901 _InputIteratorB __bend,
4902 _InputIteratorW __wbegin);
4904 template<typename _Func>
4905 param_type(initializer_list<_RealType> __bi, _Func __fw);
4907 template<typename _Func>
4908 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4911 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4912 param_type(const param_type&) = default;
4913 param_type& operator=(const param_type&) = default;
4915 std::vector<_RealType>
4924 operator==(const param_type& __p1, const param_type& __p2)
4925 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4931 std::vector<_RealType> _M_int;
4932 std::vector<double> _M_den;
4933 std::vector<double> _M_cp;
4937 piecewise_constant_distribution()
4941 template<typename _InputIteratorB, typename _InputIteratorW>
4942 piecewise_constant_distribution(_InputIteratorB __bfirst,
4943 _InputIteratorB __bend,
4944 _InputIteratorW __wbegin)
4945 : _M_param(__bfirst, __bend, __wbegin)
4948 template<typename _Func>
4949 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4951 : _M_param(__bl, __fw)
4954 template<typename _Func>
4955 piecewise_constant_distribution(size_t __nw,
4956 _RealType __xmin, _RealType __xmax,
4958 : _M_param(__nw, __xmin, __xmax, __fw)
4962 piecewise_constant_distribution(const param_type& __p)
4967 * @brief Resets the distribution state.
4974 * @brief Returns a vector of the intervals.
4976 std::vector<_RealType>
4978 { return _M_param.intervals(); }
4981 * @brief Returns a vector of the probability densities.
4985 { return _M_param.densities(); }
4988 * @brief Returns the parameter set of the distribution.
4992 { return _M_param; }
4995 * @brief Sets the parameter set of the distribution.
4996 * @param __param The new parameter set of the distribution.
4999 param(const param_type& __param)
5000 { _M_param = __param; }
5003 * @brief Returns the greatest lower bound value of the distribution.
5007 { return this->_M_param._M_int.front(); }
5010 * @brief Returns the least upper bound value of the distribution.
5014 { return this->_M_param._M_int.back(); }
5017 * @brief Generating functions.
5019 template<typename _UniformRandomNumberGenerator>
5021 operator()(_UniformRandomNumberGenerator& __urng)
5022 { return this->operator()(__urng, this->param()); }
5024 template<typename _UniformRandomNumberGenerator>
5026 operator()(_UniformRandomNumberGenerator& __urng,
5027 const param_type& __p);
5030 * @brief Inserts a %piecewise_constan_distribution random
5031 * number distribution @p __x into the output stream @p __os.
5033 * @param __os An output stream.
5034 * @param __x A %piecewise_constan_distribution random number
5037 * @returns The output stream with the state of @p __x inserted or in
5040 template<typename _RealType1, typename _CharT, typename _Traits>
5041 friend std::basic_ostream<_CharT, _Traits>&
5042 operator<<(std::basic_ostream<_CharT, _Traits>&,
5043 const std::piecewise_constant_distribution<_RealType1>&);
5046 * @brief Extracts a %piecewise_constan_distribution random
5047 * number distribution @p __x from the input stream @p __is.
5049 * @param __is An input stream.
5050 * @param __x A %piecewise_constan_distribution random number
5053 * @returns The input stream with @p __x extracted or in an error
5056 template<typename _RealType1, typename _CharT, typename _Traits>
5057 friend std::basic_istream<_CharT, _Traits>&
5058 operator>>(std::basic_istream<_CharT, _Traits>&,
5059 std::piecewise_constant_distribution<_RealType1>&);
5062 param_type _M_param;
5066 * @brief Return true if two piecewise constant distributions have the
5069 template<typename _RealType>
5071 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
5072 const std::piecewise_constant_distribution<_RealType>& __d2)
5073 { return __d1.param() == __d2.param(); }
5076 * @brief Return true if two piecewise constant distributions have
5077 * different parameters.
5079 template<typename _RealType>
5081 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5082 const std::piecewise_constant_distribution<_RealType>& __d2)
5083 { return !(__d1 == __d2); }
5087 * @brief A piecewise_linear_distribution random number distribution.
5089 * The formula for the piecewise linear probability mass function is
5092 template<typename _RealType = double>
5093 class piecewise_linear_distribution
5095 static_assert(std::is_floating_point<_RealType>::value,
5096 "template argument not a floating point type");
5099 /** The type of the range of the distribution. */
5100 typedef _RealType result_type;
5101 /** Parameter type. */
5104 typedef piecewise_linear_distribution<_RealType> distribution_type;
5105 friend class piecewise_linear_distribution<_RealType>;
5108 : _M_int(2), _M_den(2, 1.0), _M_cp(), _M_m()
5109 { _M_int[1] = _RealType(1); }
5111 template<typename _InputIteratorB, typename _InputIteratorW>
5112 param_type(_InputIteratorB __bfirst,
5113 _InputIteratorB __bend,
5114 _InputIteratorW __wbegin);
5116 template<typename _Func>
5117 param_type(initializer_list<_RealType> __bl, _Func __fw);
5119 template<typename _Func>
5120 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5123 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5124 param_type(const param_type&) = default;
5125 param_type& operator=(const param_type&) = default;
5127 std::vector<_RealType>
5136 operator==(const param_type& __p1, const param_type& __p2)
5137 { return (__p1._M_int == __p2._M_int
5138 && __p1._M_den == __p2._M_den); }
5144 std::vector<_RealType> _M_int;
5145 std::vector<double> _M_den;
5146 std::vector<double> _M_cp;
5147 std::vector<double> _M_m;
5151 piecewise_linear_distribution()
5155 template<typename _InputIteratorB, typename _InputIteratorW>
5156 piecewise_linear_distribution(_InputIteratorB __bfirst,
5157 _InputIteratorB __bend,
5158 _InputIteratorW __wbegin)
5159 : _M_param(__bfirst, __bend, __wbegin)
5162 template<typename _Func>
5163 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5165 : _M_param(__bl, __fw)
5168 template<typename _Func>
5169 piecewise_linear_distribution(size_t __nw,
5170 _RealType __xmin, _RealType __xmax,
5172 : _M_param(__nw, __xmin, __xmax, __fw)
5176 piecewise_linear_distribution(const param_type& __p)
5181 * Resets the distribution state.
5188 * @brief Return the intervals of the distribution.
5190 std::vector<_RealType>
5192 { return _M_param.intervals(); }
5195 * @brief Return a vector of the probability densities of the
5200 { return _M_param.densities(); }
5203 * @brief Returns the parameter set of the distribution.
5207 { return _M_param; }
5210 * @brief Sets the parameter set of the distribution.
5211 * @param __param The new parameter set of the distribution.
5214 param(const param_type& __param)
5215 { _M_param = __param; }
5218 * @brief Returns the greatest lower bound value of the distribution.
5222 { return this->_M_param._M_int.front(); }
5225 * @brief Returns the least upper bound value of the distribution.
5229 { return this->_M_param._M_int.back(); }
5232 * @brief Generating functions.
5234 template<typename _UniformRandomNumberGenerator>
5236 operator()(_UniformRandomNumberGenerator& __urng)
5237 { return this->operator()(__urng, this->param()); }
5239 template<typename _UniformRandomNumberGenerator>
5241 operator()(_UniformRandomNumberGenerator& __urng,
5242 const param_type& __p);
5245 * @brief Inserts a %piecewise_linear_distribution random number
5246 * distribution @p __x into the output stream @p __os.
5248 * @param __os An output stream.
5249 * @param __x A %piecewise_linear_distribution random number
5252 * @returns The output stream with the state of @p __x inserted or in
5255 template<typename _RealType1, typename _CharT, typename _Traits>
5256 friend std::basic_ostream<_CharT, _Traits>&
5257 operator<<(std::basic_ostream<_CharT, _Traits>&,
5258 const std::piecewise_linear_distribution<_RealType1>&);
5261 * @brief Extracts a %piecewise_linear_distribution random number
5262 * distribution @p __x from the input stream @p __is.
5264 * @param __is An input stream.
5265 * @param __x A %piecewise_linear_distribution random number
5268 * @returns The input stream with @p __x extracted or in an error
5271 template<typename _RealType1, typename _CharT, typename _Traits>
5272 friend std::basic_istream<_CharT, _Traits>&
5273 operator>>(std::basic_istream<_CharT, _Traits>&,
5274 std::piecewise_linear_distribution<_RealType1>&);
5277 param_type _M_param;
5281 * @brief Return true if two piecewise linear distributions have the
5284 template<typename _RealType>
5286 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
5287 const std::piecewise_linear_distribution<_RealType>& __d2)
5288 { return __d1.param() == __d2.param(); }
5291 * @brief Return true if two piecewise linear distributions have
5292 * different parameters.
5294 template<typename _RealType>
5296 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5297 const std::piecewise_linear_distribution<_RealType>& __d2)
5298 { return !(__d1 == __d2); }
5301 /* @} */ // group random_distributions_poisson
5303 /* @} */ // group random_distributions
5306 * @addtogroup random_utilities Random Number Utilities
5312 * @brief The seed_seq class generates sequences of seeds for random
5313 * number generators.
5319 /** The type of the seed vales. */
5320 typedef uint_least32_t result_type;
5322 /** Default constructor. */
5327 template<typename _IntType>
5328 seed_seq(std::initializer_list<_IntType> il);
5330 template<typename _InputIterator>
5331 seed_seq(_InputIterator __begin, _InputIterator __end);
5333 // generating functions
5334 template<typename _RandomAccessIterator>
5336 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5338 // property functions
5340 { return _M_v.size(); }
5342 template<typename OutputIterator>
5344 param(OutputIterator __dest) const
5345 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5349 std::vector<result_type> _M_v;
5352 /* @} */ // group random_utilities
5354 /* @} */ // group random