1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2012 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 // [26.4] Random number generation
43 * @defgroup random Random Number Generation
46 * A facility for generating random numbers on selected distributions.
51 * @brief A function template for converting the output of a (integral)
52 * uniform random number generator to a floatng point result in the range
55 template<typename _RealType, size_t __bits,
56 typename _UniformRandomNumberGenerator>
58 generate_canonical(_UniformRandomNumberGenerator& __g);
60 _GLIBCXX_END_NAMESPACE_VERSION
63 * Implementation-space details.
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _UIntType, size_t __w,
70 bool = __w < static_cast<size_t>
71 (std::numeric_limits<_UIntType>::digits)>
73 { static const _UIntType __value = 0; };
75 template<typename _UIntType, size_t __w>
76 struct _Shift<_UIntType, __w, true>
77 { static const _UIntType __value = _UIntType(1) << __w; };
79 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
82 // Dispatch based on modulus value to prevent divide-by-zero compile-time
83 // errors when m == 0.
84 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
87 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
90 * An adaptor class for converting the output of any Generator into
91 * the input for a specific Distribution.
93 template<typename _Engine, typename _DInputType>
98 _Adaptor(_Engine& __g)
103 { return _DInputType(0); }
107 { return _DInputType(1); }
110 * Converts a value generated by the adapted random number generator
111 * into a value in the input domain for the dependent random number
117 return std::generate_canonical<_DInputType,
118 std::numeric_limits<_DInputType>::digits,
126 _GLIBCXX_END_NAMESPACE_VERSION
127 } // namespace __detail
129 _GLIBCXX_BEGIN_NAMESPACE_VERSION
132 * @addtogroup random_generators Random Number Generators
135 * These classes define objects which provide random or pseudorandom
136 * numbers, either from a discrete or a continuous interval. The
137 * random number generator supplied as a part of this library are
138 * all uniform random number generators which provide a sequence of
139 * random number uniformly distributed over their range.
141 * A number generator is a function object with an operator() that
142 * takes zero arguments and returns a number.
144 * A compliant random number generator must satisfy the following
145 * requirements. <table border=1 cellpadding=10 cellspacing=0>
146 * <caption align=top>Random Number Generator Requirements</caption>
147 * <tr><td>To be documented.</td></tr> </table>
153 * @brief A model of a linear congruential random number generator.
155 * A random number generator that produces pseudorandom numbers via
158 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
161 * The template parameter @p _UIntType must be an unsigned integral type
162 * large enough to store values up to (__m-1). If the template parameter
163 * @p __m is 0, the modulus @p __m used is
164 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
165 * parameters @p __a and @p __c must be less than @p __m.
167 * The size of the state is @f$1@f$.
169 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
170 class linear_congruential_engine
172 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
173 "substituting _UIntType not an unsigned integral type");
174 static_assert(__m == 0u || (__a < __m && __c < __m),
175 "template argument substituting __m out of bounds");
178 // _Mod::__calc should handle correctly __m % __a >= __m / __a too.
179 static_assert(__m % __a < __m / __a,
180 "sorry, not implemented yet: try a smaller 'a' constant");
183 /** The type of the generated random value. */
184 typedef _UIntType result_type;
186 /** The multiplier. */
187 static constexpr result_type multiplier = __a;
189 static constexpr result_type increment = __c;
191 static constexpr result_type modulus = __m;
192 static constexpr result_type default_seed = 1u;
195 * @brief Constructs a %linear_congruential_engine random number
196 * generator engine with seed @p __s. The default seed value
199 * @param __s The initial seed value.
202 linear_congruential_engine(result_type __s = default_seed)
206 * @brief Constructs a %linear_congruential_engine random number
207 * generator engine seeded from the seed sequence @p __q.
209 * @param __q the seed sequence.
211 template<typename _Sseq, typename = typename
212 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
215 linear_congruential_engine(_Sseq& __q)
219 * @brief Reseeds the %linear_congruential_engine random number generator
220 * engine sequence to the seed @p __s.
222 * @param __s The new seed.
225 seed(result_type __s = default_seed);
228 * @brief Reseeds the %linear_congruential_engine random number generator
230 * sequence using values from the seed sequence @p __q.
232 * @param __q the seed sequence.
234 template<typename _Sseq>
235 typename std::enable_if<std::is_class<_Sseq>::value>::type
239 * @brief Gets the smallest possible value in the output range.
241 * The minimum depends on the @p __c parameter: if it is zero, the
242 * minimum generated must be > 0, otherwise 0 is allowed.
244 static constexpr result_type
246 { return __c == 0u ? 1u : 0u; }
249 * @brief Gets the largest possible value in the output range.
251 static constexpr result_type
256 * @brief Discard a sequence of random numbers.
259 discard(unsigned long long __z)
261 for (; __z != 0ULL; --__z)
266 * @brief Gets the next random number in the sequence.
271 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
276 * @brief Compares two linear congruential random number generator
277 * objects of the same type for equality.
279 * @param __lhs A linear congruential random number generator object.
280 * @param __rhs Another linear congruential random number generator
283 * @returns true if the infinite sequences of generated values
284 * would be equal, false otherwise.
287 operator==(const linear_congruential_engine& __lhs,
288 const linear_congruential_engine& __rhs)
289 { return __lhs._M_x == __rhs._M_x; }
292 * @brief Writes the textual representation of the state x(i) of x to
295 * @param __os The output stream.
296 * @param __lcr A % linear_congruential_engine random number generator.
299 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
300 _UIntType1 __m1, typename _CharT, typename _Traits>
301 friend std::basic_ostream<_CharT, _Traits>&
302 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
303 const std::linear_congruential_engine<_UIntType1,
304 __a1, __c1, __m1>& __lcr);
307 * @brief Sets the state of the engine by reading its textual
308 * representation from @p __is.
310 * The textual representation must have been previously written using
311 * an output stream whose imbued locale and whose type's template
312 * specialization arguments _CharT and _Traits were the same as those
315 * @param __is The input stream.
316 * @param __lcr A % linear_congruential_engine random number generator.
319 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
320 _UIntType1 __m1, typename _CharT, typename _Traits>
321 friend std::basic_istream<_CharT, _Traits>&
322 operator>>(std::basic_istream<_CharT, _Traits>& __is,
323 std::linear_congruential_engine<_UIntType1, __a1,
331 * @brief Compares two linear congruential random number generator
332 * objects of the same type for inequality.
334 * @param __lhs A linear congruential random number generator object.
335 * @param __rhs Another linear congruential random number generator
338 * @returns true if the infinite sequences of generated values
339 * would be different, false otherwise.
341 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
343 operator!=(const std::linear_congruential_engine<_UIntType, __a,
345 const std::linear_congruential_engine<_UIntType, __a,
347 { return !(__lhs == __rhs); }
351 * A generalized feedback shift register discrete random number generator.
353 * This algorithm avoids multiplication and division and is designed to be
354 * friendly to a pipelined architecture. If the parameters are chosen
355 * correctly, this generator will produce numbers with a very long period and
356 * fairly good apparent entropy, although still not cryptographically strong.
358 * The best way to use this generator is with the predefined mt19937 class.
360 * This algorithm was originally invented by Makoto Matsumoto and
363 * @tparam __w Word size, the number of bits in each element of
365 * @tparam __n The degree of recursion.
366 * @tparam __m The period parameter.
367 * @tparam __r The separation point bit index.
368 * @tparam __a The last row of the twist matrix.
369 * @tparam __u The first right-shift tempering matrix parameter.
370 * @tparam __d The first right-shift tempering matrix mask.
371 * @tparam __s The first left-shift tempering matrix parameter.
372 * @tparam __b The first left-shift tempering matrix mask.
373 * @tparam __t The second left-shift tempering matrix parameter.
374 * @tparam __c The second left-shift tempering matrix mask.
375 * @tparam __l The second right-shift tempering matrix parameter.
376 * @tparam __f Initialization multiplier.
378 template<typename _UIntType, size_t __w,
379 size_t __n, size_t __m, size_t __r,
380 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
381 _UIntType __b, size_t __t,
382 _UIntType __c, size_t __l, _UIntType __f>
383 class mersenne_twister_engine
385 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
386 "substituting _UIntType not an unsigned integral type");
387 static_assert(1u <= __m && __m <= __n,
388 "template argument substituting __m out of bounds");
389 static_assert(__r <= __w, "template argument substituting "
391 static_assert(__u <= __w, "template argument substituting "
393 static_assert(__s <= __w, "template argument substituting "
395 static_assert(__t <= __w, "template argument substituting "
397 static_assert(__l <= __w, "template argument substituting "
399 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
400 "template argument substituting __w out of bound");
401 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
402 "template argument substituting __a out of bound");
403 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
404 "template argument substituting __b out of bound");
405 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
406 "template argument substituting __c out of bound");
407 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
408 "template argument substituting __d out of bound");
409 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
410 "template argument substituting __f out of bound");
413 /** The type of the generated random value. */
414 typedef _UIntType result_type;
417 static constexpr size_t word_size = __w;
418 static constexpr size_t state_size = __n;
419 static constexpr size_t shift_size = __m;
420 static constexpr size_t mask_bits = __r;
421 static constexpr result_type xor_mask = __a;
422 static constexpr size_t tempering_u = __u;
423 static constexpr result_type tempering_d = __d;
424 static constexpr size_t tempering_s = __s;
425 static constexpr result_type tempering_b = __b;
426 static constexpr size_t tempering_t = __t;
427 static constexpr result_type tempering_c = __c;
428 static constexpr size_t tempering_l = __l;
429 static constexpr result_type initialization_multiplier = __f;
430 static constexpr result_type default_seed = 5489u;
432 // constructors and member function
434 mersenne_twister_engine(result_type __sd = default_seed)
438 * @brief Constructs a %mersenne_twister_engine random number generator
439 * engine seeded from the seed sequence @p __q.
441 * @param __q the seed sequence.
443 template<typename _Sseq, typename = typename
444 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
447 mersenne_twister_engine(_Sseq& __q)
451 seed(result_type __sd = default_seed);
453 template<typename _Sseq>
454 typename std::enable_if<std::is_class<_Sseq>::value>::type
458 * @brief Gets the smallest possible value in the output range.
460 static constexpr result_type
465 * @brief Gets the largest possible value in the output range.
467 static constexpr result_type
469 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
472 * @brief Discard a sequence of random numbers.
475 discard(unsigned long long __z)
477 for (; __z != 0ULL; --__z)
485 * @brief Compares two % mersenne_twister_engine random number generator
486 * objects of the same type for equality.
488 * @param __lhs A % mersenne_twister_engine random number generator
490 * @param __rhs Another % mersenne_twister_engine random number
493 * @returns true if the infinite sequences of generated values
494 * would be equal, false otherwise.
497 operator==(const mersenne_twister_engine& __lhs,
498 const mersenne_twister_engine& __rhs)
499 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
500 && __lhs._M_p == __rhs._M_p); }
503 * @brief Inserts the current state of a % mersenne_twister_engine
504 * random number generator engine @p __x into the output stream
507 * @param __os An output stream.
508 * @param __x A % mersenne_twister_engine random number generator
511 * @returns The output stream with the state of @p __x inserted or in
514 template<typename _UIntType1,
515 size_t __w1, size_t __n1,
516 size_t __m1, size_t __r1,
517 _UIntType1 __a1, size_t __u1,
518 _UIntType1 __d1, size_t __s1,
519 _UIntType1 __b1, size_t __t1,
520 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
521 typename _CharT, typename _Traits>
522 friend std::basic_ostream<_CharT, _Traits>&
523 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
524 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
525 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
529 * @brief Extracts the current state of a % mersenne_twister_engine
530 * random number generator engine @p __x from the input stream
533 * @param __is An input stream.
534 * @param __x A % mersenne_twister_engine random number generator
537 * @returns The input stream with the state of @p __x extracted or in
540 template<typename _UIntType1,
541 size_t __w1, size_t __n1,
542 size_t __m1, size_t __r1,
543 _UIntType1 __a1, size_t __u1,
544 _UIntType1 __d1, size_t __s1,
545 _UIntType1 __b1, size_t __t1,
546 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
547 typename _CharT, typename _Traits>
548 friend std::basic_istream<_CharT, _Traits>&
549 operator>>(std::basic_istream<_CharT, _Traits>& __is,
550 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
551 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
555 _UIntType _M_x[state_size];
560 * @brief Compares two % mersenne_twister_engine random number generator
561 * objects of the same type for inequality.
563 * @param __lhs A % mersenne_twister_engine random number generator
565 * @param __rhs Another % mersenne_twister_engine random number
568 * @returns true if the infinite sequences of generated values
569 * would be different, false otherwise.
571 template<typename _UIntType, size_t __w,
572 size_t __n, size_t __m, size_t __r,
573 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
574 _UIntType __b, size_t __t,
575 _UIntType __c, size_t __l, _UIntType __f>
577 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
578 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
579 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
580 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
581 { return !(__lhs == __rhs); }
585 * @brief The Marsaglia-Zaman generator.
587 * This is a model of a Generalized Fibonacci discrete random number
588 * generator, sometimes referred to as the SWC generator.
590 * A discrete random number generator that produces pseudorandom
593 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
596 * The size of the state is @f$r@f$
597 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
599 * @var _M_x The state of the generator. This is a ring buffer.
600 * @var _M_carry The carry.
601 * @var _M_p Current index of x(i - r).
603 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
604 class subtract_with_carry_engine
606 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
607 "substituting _UIntType not an unsigned integral type");
608 static_assert(0u < __s && __s < __r,
609 "template argument substituting __s out of bounds");
610 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
611 "template argument substituting __w out of bounds");
614 /** The type of the generated random value. */
615 typedef _UIntType result_type;
618 static constexpr size_t word_size = __w;
619 static constexpr size_t short_lag = __s;
620 static constexpr size_t long_lag = __r;
621 static constexpr result_type default_seed = 19780503u;
624 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
625 * random number generator.
628 subtract_with_carry_engine(result_type __sd = default_seed)
632 * @brief Constructs a %subtract_with_carry_engine random number engine
633 * seeded from the seed sequence @p __q.
635 * @param __q the seed sequence.
637 template<typename _Sseq, typename = typename
638 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
641 subtract_with_carry_engine(_Sseq& __q)
645 * @brief Seeds the initial state @f$x_0@f$ of the random number
648 * N1688[4.19] modifies this as follows. If @p __value == 0,
649 * sets value to 19780503. In any case, with a linear
650 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
651 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
652 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
653 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
654 * set carry to 1, otherwise sets carry to 0.
657 seed(result_type __sd = default_seed);
660 * @brief Seeds the initial state @f$x_0@f$ of the
661 * % subtract_with_carry_engine random number generator.
663 template<typename _Sseq>
664 typename std::enable_if<std::is_class<_Sseq>::value>::type
668 * @brief Gets the inclusive minimum value of the range of random
669 * integers returned by this generator.
671 static constexpr result_type
676 * @brief Gets the inclusive maximum value of the range of random
677 * integers returned by this generator.
679 static constexpr result_type
681 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
684 * @brief Discard a sequence of random numbers.
687 discard(unsigned long long __z)
689 for (; __z != 0ULL; --__z)
694 * @brief Gets the next random number in the sequence.
700 * @brief Compares two % subtract_with_carry_engine random number
701 * generator objects of the same type for equality.
703 * @param __lhs A % subtract_with_carry_engine random number generator
705 * @param __rhs Another % subtract_with_carry_engine random number
708 * @returns true if the infinite sequences of generated values
709 * would be equal, false otherwise.
712 operator==(const subtract_with_carry_engine& __lhs,
713 const subtract_with_carry_engine& __rhs)
714 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
715 && __lhs._M_carry == __rhs._M_carry
716 && __lhs._M_p == __rhs._M_p); }
719 * @brief Inserts the current state of a % subtract_with_carry_engine
720 * random number generator engine @p __x into the output stream
723 * @param __os An output stream.
724 * @param __x A % subtract_with_carry_engine random number generator
727 * @returns The output stream with the state of @p __x inserted or in
730 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
731 typename _CharT, typename _Traits>
732 friend std::basic_ostream<_CharT, _Traits>&
733 operator<<(std::basic_ostream<_CharT, _Traits>&,
734 const std::subtract_with_carry_engine<_UIntType1, __w1,
738 * @brief Extracts the current state of a % subtract_with_carry_engine
739 * random number generator engine @p __x from the input stream
742 * @param __is An input stream.
743 * @param __x A % subtract_with_carry_engine random number generator
746 * @returns The input stream with the state of @p __x extracted or in
749 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
750 typename _CharT, typename _Traits>
751 friend std::basic_istream<_CharT, _Traits>&
752 operator>>(std::basic_istream<_CharT, _Traits>&,
753 std::subtract_with_carry_engine<_UIntType1, __w1,
757 _UIntType _M_x[long_lag];
763 * @brief Compares two % subtract_with_carry_engine random number
764 * generator objects of the same type for inequality.
766 * @param __lhs A % subtract_with_carry_engine random number generator
768 * @param __rhs Another % subtract_with_carry_engine random number
771 * @returns true if the infinite sequences of generated values
772 * would be different, false otherwise.
774 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
776 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
778 const std::subtract_with_carry_engine<_UIntType, __w,
780 { return !(__lhs == __rhs); }
784 * Produces random numbers from some base engine by discarding blocks of
787 * 0 <= @p __r <= @p __p
789 template<typename _RandomNumberEngine, size_t __p, size_t __r>
790 class discard_block_engine
792 static_assert(1 <= __r && __r <= __p,
793 "template argument substituting __r out of bounds");
796 /** The type of the generated random value. */
797 typedef typename _RandomNumberEngine::result_type result_type;
800 static constexpr size_t block_size = __p;
801 static constexpr size_t used_block = __r;
804 * @brief Constructs a default %discard_block_engine engine.
806 * The underlying engine is default constructed as well.
808 discard_block_engine()
809 : _M_b(), _M_n(0) { }
812 * @brief Copy constructs a %discard_block_engine engine.
814 * Copies an existing base class random number generator.
815 * @param __rng An existing (base class) engine object.
818 discard_block_engine(const _RandomNumberEngine& __rng)
819 : _M_b(__rng), _M_n(0) { }
822 * @brief Move constructs a %discard_block_engine engine.
824 * Copies an existing base class random number generator.
825 * @param __rng An existing (base class) engine object.
828 discard_block_engine(_RandomNumberEngine&& __rng)
829 : _M_b(std::move(__rng)), _M_n(0) { }
832 * @brief Seed constructs a %discard_block_engine engine.
834 * Constructs the underlying generator engine seeded with @p __s.
835 * @param __s A seed value for the base class engine.
838 discard_block_engine(result_type __s)
839 : _M_b(__s), _M_n(0) { }
842 * @brief Generator construct a %discard_block_engine engine.
844 * @param __q A seed sequence.
846 template<typename _Sseq, typename = typename
847 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
848 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
851 discard_block_engine(_Sseq& __q)
856 * @brief Reseeds the %discard_block_engine object with the default
857 * seed for the underlying base class generator engine.
867 * @brief Reseeds the %discard_block_engine object with the default
868 * seed for the underlying base class generator engine.
871 seed(result_type __s)
878 * @brief Reseeds the %discard_block_engine object with the given seed
880 * @param __q A seed generator function.
882 template<typename _Sseq>
891 * @brief Gets a const reference to the underlying generator engine
894 const _RandomNumberEngine&
895 base() const noexcept
899 * @brief Gets the minimum value in the generated random number range.
901 static constexpr result_type
903 { return _RandomNumberEngine::min(); }
906 * @brief Gets the maximum value in the generated random number range.
908 static constexpr result_type
910 { return _RandomNumberEngine::max(); }
913 * @brief Discard a sequence of random numbers.
916 discard(unsigned long long __z)
918 for (; __z != 0ULL; --__z)
923 * @brief Gets the next value in the generated random number sequence.
929 * @brief Compares two %discard_block_engine random number generator
930 * objects of the same type for equality.
932 * @param __lhs A %discard_block_engine random number generator object.
933 * @param __rhs Another %discard_block_engine random number generator
936 * @returns true if the infinite sequences of generated values
937 * would be equal, false otherwise.
940 operator==(const discard_block_engine& __lhs,
941 const discard_block_engine& __rhs)
942 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
945 * @brief Inserts the current state of a %discard_block_engine random
946 * number generator engine @p __x into the output stream
949 * @param __os An output stream.
950 * @param __x A %discard_block_engine random number generator engine.
952 * @returns The output stream with the state of @p __x inserted or in
955 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
956 typename _CharT, typename _Traits>
957 friend std::basic_ostream<_CharT, _Traits>&
958 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
959 const std::discard_block_engine<_RandomNumberEngine1,
963 * @brief Extracts the current state of a % subtract_with_carry_engine
964 * random number generator engine @p __x from the input stream
967 * @param __is An input stream.
968 * @param __x A %discard_block_engine random number generator engine.
970 * @returns The input stream with the state of @p __x extracted or in
973 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
974 typename _CharT, typename _Traits>
975 friend std::basic_istream<_CharT, _Traits>&
976 operator>>(std::basic_istream<_CharT, _Traits>& __is,
977 std::discard_block_engine<_RandomNumberEngine1,
981 _RandomNumberEngine _M_b;
986 * @brief Compares two %discard_block_engine random number generator
987 * objects of the same type for inequality.
989 * @param __lhs A %discard_block_engine random number generator object.
990 * @param __rhs Another %discard_block_engine random number generator
993 * @returns true if the infinite sequences of generated values
994 * would be different, false otherwise.
996 template<typename _RandomNumberEngine, size_t __p, size_t __r>
998 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1000 const std::discard_block_engine<_RandomNumberEngine, __p,
1002 { return !(__lhs == __rhs); }
1006 * Produces random numbers by combining random numbers from some base
1007 * engine to produce random numbers with a specifies number of bits @p __w.
1009 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1010 class independent_bits_engine
1012 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1013 "substituting _UIntType not an unsigned integral type");
1014 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1015 "template argument substituting __w out of bounds");
1018 /** The type of the generated random value. */
1019 typedef _UIntType result_type;
1022 * @brief Constructs a default %independent_bits_engine engine.
1024 * The underlying engine is default constructed as well.
1026 independent_bits_engine()
1030 * @brief Copy constructs a %independent_bits_engine engine.
1032 * Copies an existing base class random number generator.
1033 * @param __rng An existing (base class) engine object.
1036 independent_bits_engine(const _RandomNumberEngine& __rng)
1040 * @brief Move constructs a %independent_bits_engine engine.
1042 * Copies an existing base class random number generator.
1043 * @param __rng An existing (base class) engine object.
1046 independent_bits_engine(_RandomNumberEngine&& __rng)
1047 : _M_b(std::move(__rng)) { }
1050 * @brief Seed constructs a %independent_bits_engine engine.
1052 * Constructs the underlying generator engine seeded with @p __s.
1053 * @param __s A seed value for the base class engine.
1056 independent_bits_engine(result_type __s)
1060 * @brief Generator construct a %independent_bits_engine engine.
1062 * @param __q A seed sequence.
1064 template<typename _Sseq, typename = typename
1065 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1066 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1069 independent_bits_engine(_Sseq& __q)
1074 * @brief Reseeds the %independent_bits_engine object with the default
1075 * seed for the underlying base class generator engine.
1082 * @brief Reseeds the %independent_bits_engine object with the default
1083 * seed for the underlying base class generator engine.
1086 seed(result_type __s)
1090 * @brief Reseeds the %independent_bits_engine object with the given
1092 * @param __q A seed generator function.
1094 template<typename _Sseq>
1100 * @brief Gets a const reference to the underlying generator engine
1103 const _RandomNumberEngine&
1104 base() const noexcept
1108 * @brief Gets the minimum value in the generated random number range.
1110 static constexpr result_type
1115 * @brief Gets the maximum value in the generated random number range.
1117 static constexpr result_type
1119 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1122 * @brief Discard a sequence of random numbers.
1125 discard(unsigned long long __z)
1127 for (; __z != 0ULL; --__z)
1132 * @brief Gets the next value in the generated random number sequence.
1138 * @brief Compares two %independent_bits_engine random number generator
1139 * objects of the same type for equality.
1141 * @param __lhs A %independent_bits_engine random number generator
1143 * @param __rhs Another %independent_bits_engine random number generator
1146 * @returns true if the infinite sequences of generated values
1147 * would be equal, false otherwise.
1150 operator==(const independent_bits_engine& __lhs,
1151 const independent_bits_engine& __rhs)
1152 { return __lhs._M_b == __rhs._M_b; }
1155 * @brief Extracts the current state of a % subtract_with_carry_engine
1156 * random number generator engine @p __x from the input stream
1159 * @param __is An input stream.
1160 * @param __x A %independent_bits_engine random number generator
1163 * @returns The input stream with the state of @p __x extracted or in
1166 template<typename _CharT, typename _Traits>
1167 friend std::basic_istream<_CharT, _Traits>&
1168 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1169 std::independent_bits_engine<_RandomNumberEngine,
1170 __w, _UIntType>& __x)
1177 _RandomNumberEngine _M_b;
1181 * @brief Compares two %independent_bits_engine random number generator
1182 * objects of the same type for inequality.
1184 * @param __lhs A %independent_bits_engine random number generator
1186 * @param __rhs Another %independent_bits_engine random number generator
1189 * @returns true if the infinite sequences of generated values
1190 * would be different, false otherwise.
1192 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1194 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1196 const std::independent_bits_engine<_RandomNumberEngine, __w,
1198 { return !(__lhs == __rhs); }
1201 * @brief Inserts the current state of a %independent_bits_engine random
1202 * number generator engine @p __x into the output stream @p __os.
1204 * @param __os An output stream.
1205 * @param __x A %independent_bits_engine random number generator engine.
1207 * @returns The output stream with the state of @p __x inserted or in
1210 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1211 typename _CharT, typename _Traits>
1212 std::basic_ostream<_CharT, _Traits>&
1213 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1214 const std::independent_bits_engine<_RandomNumberEngine,
1215 __w, _UIntType>& __x)
1223 * @brief Produces random numbers by combining random numbers from some
1224 * base engine to produce random numbers with a specifies number of bits
1227 template<typename _RandomNumberEngine, size_t __k>
1228 class shuffle_order_engine
1230 static_assert(1u <= __k, "template argument substituting "
1231 "__k out of bound");
1234 /** The type of the generated random value. */
1235 typedef typename _RandomNumberEngine::result_type result_type;
1237 static constexpr size_t table_size = __k;
1240 * @brief Constructs a default %shuffle_order_engine engine.
1242 * The underlying engine is default constructed as well.
1244 shuffle_order_engine()
1246 { _M_initialize(); }
1249 * @brief Copy constructs a %shuffle_order_engine engine.
1251 * Copies an existing base class random number generator.
1252 * @param __rng An existing (base class) engine object.
1255 shuffle_order_engine(const _RandomNumberEngine& __rng)
1257 { _M_initialize(); }
1260 * @brief Move constructs a %shuffle_order_engine engine.
1262 * Copies an existing base class random number generator.
1263 * @param __rng An existing (base class) engine object.
1266 shuffle_order_engine(_RandomNumberEngine&& __rng)
1267 : _M_b(std::move(__rng))
1268 { _M_initialize(); }
1271 * @brief Seed constructs a %shuffle_order_engine engine.
1273 * Constructs the underlying generator engine seeded with @p __s.
1274 * @param __s A seed value for the base class engine.
1277 shuffle_order_engine(result_type __s)
1279 { _M_initialize(); }
1282 * @brief Generator construct a %shuffle_order_engine engine.
1284 * @param __q A seed sequence.
1286 template<typename _Sseq, typename = typename
1287 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1288 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1291 shuffle_order_engine(_Sseq& __q)
1293 { _M_initialize(); }
1296 * @brief Reseeds the %shuffle_order_engine object with the default seed
1297 for the underlying base class generator engine.
1307 * @brief Reseeds the %shuffle_order_engine object with the default seed
1308 * for the underlying base class generator engine.
1311 seed(result_type __s)
1318 * @brief Reseeds the %shuffle_order_engine object with the given seed
1320 * @param __q A seed generator function.
1322 template<typename _Sseq>
1331 * Gets a const reference to the underlying generator engine object.
1333 const _RandomNumberEngine&
1334 base() const noexcept
1338 * Gets the minimum value in the generated random number range.
1340 static constexpr result_type
1342 { return _RandomNumberEngine::min(); }
1345 * Gets the maximum value in the generated random number range.
1347 static constexpr result_type
1349 { return _RandomNumberEngine::max(); }
1352 * Discard a sequence of random numbers.
1355 discard(unsigned long long __z)
1357 for (; __z != 0ULL; --__z)
1362 * Gets the next value in the generated random number sequence.
1368 * Compares two %shuffle_order_engine random number generator objects
1369 * of the same type for equality.
1371 * @param __lhs A %shuffle_order_engine random number generator object.
1372 * @param __rhs Another %shuffle_order_engine random number generator
1375 * @returns true if the infinite sequences of generated values
1376 * would be equal, false otherwise.
1379 operator==(const shuffle_order_engine& __lhs,
1380 const shuffle_order_engine& __rhs)
1381 { return (__lhs._M_b == __rhs._M_b
1382 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1383 && __lhs._M_y == __rhs._M_y); }
1386 * @brief Inserts the current state of a %shuffle_order_engine random
1387 * number generator engine @p __x into the output stream
1390 * @param __os An output stream.
1391 * @param __x A %shuffle_order_engine random number generator engine.
1393 * @returns The output stream with the state of @p __x inserted or in
1396 template<typename _RandomNumberEngine1, size_t __k1,
1397 typename _CharT, typename _Traits>
1398 friend std::basic_ostream<_CharT, _Traits>&
1399 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1400 const std::shuffle_order_engine<_RandomNumberEngine1,
1404 * @brief Extracts the current state of a % subtract_with_carry_engine
1405 * random number generator engine @p __x from the input stream
1408 * @param __is An input stream.
1409 * @param __x A %shuffle_order_engine random number generator engine.
1411 * @returns The input stream with the state of @p __x extracted or in
1414 template<typename _RandomNumberEngine1, size_t __k1,
1415 typename _CharT, typename _Traits>
1416 friend std::basic_istream<_CharT, _Traits>&
1417 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1418 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
1421 void _M_initialize()
1423 for (size_t __i = 0; __i < __k; ++__i)
1428 _RandomNumberEngine _M_b;
1429 result_type _M_v[__k];
1434 * Compares two %shuffle_order_engine random number generator objects
1435 * of the same type for inequality.
1437 * @param __lhs A %shuffle_order_engine random number generator object.
1438 * @param __rhs Another %shuffle_order_engine random number generator
1441 * @returns true if the infinite sequences of generated values
1442 * would be different, false otherwise.
1444 template<typename _RandomNumberEngine, size_t __k>
1446 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1448 const std::shuffle_order_engine<_RandomNumberEngine,
1450 { return !(__lhs == __rhs); }
1454 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1456 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1460 * An alternative LCR (Lehmer Generator function).
1462 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1466 * The classic Mersenne Twister.
1469 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1470 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1471 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1473 typedef mersenne_twister_engine<
1479 0xefc60000UL, 18, 1812433253UL> mt19937;
1482 * An alternative Mersenne Twister.
1484 typedef mersenne_twister_engine<
1487 0xb5026f5aa96619e9ULL, 29,
1488 0x5555555555555555ULL, 17,
1489 0x71d67fffeda60000ULL, 37,
1490 0xfff7eee000000000ULL, 43,
1491 6364136223846793005ULL> mt19937_64;
1493 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1496 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1499 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1501 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1503 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1505 typedef minstd_rand0 default_random_engine;
1508 * A standard interface to a platform-specific non-deterministic
1509 * random number generator (if any are available).
1514 /** The type of the generated random value. */
1515 typedef unsigned int result_type;
1517 // constructors, destructors and member functions
1519 #ifdef _GLIBCXX_USE_RANDOM_TR1
1522 random_device(const std::string& __token = "/dev/urandom")
1524 if ((__token != "/dev/urandom" && __token != "/dev/random")
1525 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1526 std::__throw_runtime_error(__N("random_device::"
1527 "random_device(const std::string&)"));
1531 { std::fclose(_M_file); }
1536 random_device(const std::string& __token = "mt19937")
1537 : _M_mt(_M_strtoul(__token)) { }
1540 static unsigned long
1541 _M_strtoul(const std::string& __str)
1543 unsigned long __ret = 5489UL;
1544 if (__str != "mt19937")
1546 const char* __nptr = __str.c_str();
1548 __ret = std::strtoul(__nptr, &__endptr, 0);
1549 if (*__nptr == '\0' || *__endptr != '\0')
1550 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1551 "(const std::string&)"));
1560 static constexpr result_type
1562 { return std::numeric_limits<result_type>::min(); }
1564 static constexpr result_type
1566 { return std::numeric_limits<result_type>::max(); }
1569 entropy() const noexcept
1575 #ifdef _GLIBCXX_USE_RANDOM_TR1
1577 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1585 // No copy functions.
1586 random_device(const random_device&) = delete;
1587 void operator=(const random_device&) = delete;
1591 #ifdef _GLIBCXX_USE_RANDOM_TR1
1598 /* @} */ // group random_generators
1601 * @addtogroup random_distributions Random Number Distributions
1607 * @addtogroup random_distributions_uniform Uniform Distributions
1608 * @ingroup random_distributions
1613 * @brief Uniform discrete distribution for random numbers.
1614 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1615 * probability throughout the range.
1617 template<typename _IntType = int>
1618 class uniform_int_distribution
1620 static_assert(std::is_integral<_IntType>::value,
1621 "template argument not an integral type");
1624 /** The type of the range of the distribution. */
1625 typedef _IntType result_type;
1626 /** Parameter type. */
1629 typedef uniform_int_distribution<_IntType> distribution_type;
1632 param_type(_IntType __a = 0,
1633 _IntType __b = std::numeric_limits<_IntType>::max())
1634 : _M_a(__a), _M_b(__b)
1636 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1648 operator==(const param_type& __p1, const param_type& __p2)
1649 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1658 * @brief Constructs a uniform distribution object.
1661 uniform_int_distribution(_IntType __a = 0,
1662 _IntType __b = std::numeric_limits<_IntType>::max())
1663 : _M_param(__a, __b)
1667 uniform_int_distribution(const param_type& __p)
1672 * @brief Resets the distribution state.
1674 * Does nothing for the uniform integer distribution.
1681 { return _M_param.a(); }
1685 { return _M_param.b(); }
1688 * @brief Returns the parameter set of the distribution.
1692 { return _M_param; }
1695 * @brief Sets the parameter set of the distribution.
1696 * @param __param The new parameter set of the distribution.
1699 param(const param_type& __param)
1700 { _M_param = __param; }
1703 * @brief Returns the inclusive lower bound of the distribution range.
1707 { return this->a(); }
1710 * @brief Returns the inclusive upper bound of the distribution range.
1714 { return this->b(); }
1717 * @brief Generating functions.
1719 template<typename _UniformRandomNumberGenerator>
1721 operator()(_UniformRandomNumberGenerator& __urng)
1722 { return this->operator()(__urng, _M_param); }
1724 template<typename _UniformRandomNumberGenerator>
1726 operator()(_UniformRandomNumberGenerator& __urng,
1727 const param_type& __p);
1730 * @brief Return true if two uniform integer distributions have
1731 * the same parameters.
1734 operator==(const uniform_int_distribution& __d1,
1735 const uniform_int_distribution& __d2)
1736 { return __d1._M_param == __d2._M_param; }
1739 param_type _M_param;
1743 * @brief Return true if two uniform integer distributions have
1744 * different parameters.
1746 template<typename _IntType>
1748 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1749 const std::uniform_int_distribution<_IntType>& __d2)
1750 { return !(__d1 == __d2); }
1753 * @brief Inserts a %uniform_int_distribution random number
1754 * distribution @p __x into the output stream @p os.
1756 * @param __os An output stream.
1757 * @param __x A %uniform_int_distribution random number distribution.
1759 * @returns The output stream with the state of @p __x inserted or in
1762 template<typename _IntType, typename _CharT, typename _Traits>
1763 std::basic_ostream<_CharT, _Traits>&
1764 operator<<(std::basic_ostream<_CharT, _Traits>&,
1765 const std::uniform_int_distribution<_IntType>&);
1768 * @brief Extracts a %uniform_int_distribution random number distribution
1769 * @p __x from the input stream @p __is.
1771 * @param __is An input stream.
1772 * @param __x A %uniform_int_distribution random number generator engine.
1774 * @returns The input stream with @p __x extracted or in an error state.
1776 template<typename _IntType, typename _CharT, typename _Traits>
1777 std::basic_istream<_CharT, _Traits>&
1778 operator>>(std::basic_istream<_CharT, _Traits>&,
1779 std::uniform_int_distribution<_IntType>&);
1783 * @brief Uniform continuous distribution for random numbers.
1785 * A continuous random distribution on the range [min, max) with equal
1786 * probability throughout the range. The URNG should be real-valued and
1787 * deliver number in the range [0, 1).
1789 template<typename _RealType = double>
1790 class uniform_real_distribution
1792 static_assert(std::is_floating_point<_RealType>::value,
1793 "template argument not a floating point type");
1796 /** The type of the range of the distribution. */
1797 typedef _RealType result_type;
1798 /** Parameter type. */
1801 typedef uniform_real_distribution<_RealType> distribution_type;
1804 param_type(_RealType __a = _RealType(0),
1805 _RealType __b = _RealType(1))
1806 : _M_a(__a), _M_b(__b)
1808 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1820 operator==(const param_type& __p1, const param_type& __p2)
1821 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1830 * @brief Constructs a uniform_real_distribution object.
1832 * @param __a [IN] The lower bound of the distribution.
1833 * @param __b [IN] The upper bound of the distribution.
1836 uniform_real_distribution(_RealType __a = _RealType(0),
1837 _RealType __b = _RealType(1))
1838 : _M_param(__a, __b)
1842 uniform_real_distribution(const param_type& __p)
1847 * @brief Resets the distribution state.
1849 * Does nothing for the uniform real distribution.
1856 { return _M_param.a(); }
1860 { return _M_param.b(); }
1863 * @brief Returns the parameter set of the distribution.
1867 { return _M_param; }
1870 * @brief Sets the parameter set of the distribution.
1871 * @param __param The new parameter set of the distribution.
1874 param(const param_type& __param)
1875 { _M_param = __param; }
1878 * @brief Returns the inclusive lower bound of the distribution range.
1882 { return this->a(); }
1885 * @brief Returns the inclusive upper bound of the distribution range.
1889 { return this->b(); }
1892 * @brief Generating functions.
1894 template<typename _UniformRandomNumberGenerator>
1896 operator()(_UniformRandomNumberGenerator& __urng)
1897 { return this->operator()(__urng, _M_param); }
1899 template<typename _UniformRandomNumberGenerator>
1901 operator()(_UniformRandomNumberGenerator& __urng,
1902 const param_type& __p)
1904 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1906 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1910 * @brief Return true if two uniform real distributions have
1911 * the same parameters.
1914 operator==(const uniform_real_distribution& __d1,
1915 const uniform_real_distribution& __d2)
1916 { return __d1._M_param == __d2._M_param; }
1919 param_type _M_param;
1923 * @brief Return true if two uniform real distributions have
1924 * different parameters.
1926 template<typename _IntType>
1928 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1929 const std::uniform_real_distribution<_IntType>& __d2)
1930 { return !(__d1 == __d2); }
1933 * @brief Inserts a %uniform_real_distribution random number
1934 * distribution @p __x into the output stream @p __os.
1936 * @param __os An output stream.
1937 * @param __x A %uniform_real_distribution random number distribution.
1939 * @returns The output stream with the state of @p __x inserted or in
1942 template<typename _RealType, typename _CharT, typename _Traits>
1943 std::basic_ostream<_CharT, _Traits>&
1944 operator<<(std::basic_ostream<_CharT, _Traits>&,
1945 const std::uniform_real_distribution<_RealType>&);
1948 * @brief Extracts a %uniform_real_distribution random number distribution
1949 * @p __x from the input stream @p __is.
1951 * @param __is An input stream.
1952 * @param __x A %uniform_real_distribution random number generator engine.
1954 * @returns The input stream with @p __x extracted or in an error state.
1956 template<typename _RealType, typename _CharT, typename _Traits>
1957 std::basic_istream<_CharT, _Traits>&
1958 operator>>(std::basic_istream<_CharT, _Traits>&,
1959 std::uniform_real_distribution<_RealType>&);
1961 /* @} */ // group random_distributions_uniform
1964 * @addtogroup random_distributions_normal Normal Distributions
1965 * @ingroup random_distributions
1970 * @brief A normal continuous distribution for random numbers.
1972 * The formula for the normal probability density function is
1974 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1975 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1978 template<typename _RealType = double>
1979 class normal_distribution
1981 static_assert(std::is_floating_point<_RealType>::value,
1982 "template argument not a floating point type");
1985 /** The type of the range of the distribution. */
1986 typedef _RealType result_type;
1987 /** Parameter type. */
1990 typedef normal_distribution<_RealType> distribution_type;
1993 param_type(_RealType __mean = _RealType(0),
1994 _RealType __stddev = _RealType(1))
1995 : _M_mean(__mean), _M_stddev(__stddev)
1997 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
2006 { return _M_stddev; }
2009 operator==(const param_type& __p1, const param_type& __p2)
2010 { return (__p1._M_mean == __p2._M_mean
2011 && __p1._M_stddev == __p2._M_stddev); }
2015 _RealType _M_stddev;
2020 * Constructs a normal distribution with parameters @f$mean@f$ and
2021 * standard deviation.
2024 normal_distribution(result_type __mean = result_type(0),
2025 result_type __stddev = result_type(1))
2026 : _M_param(__mean, __stddev), _M_saved_available(false)
2030 normal_distribution(const param_type& __p)
2031 : _M_param(__p), _M_saved_available(false)
2035 * @brief Resets the distribution state.
2039 { _M_saved_available = false; }
2042 * @brief Returns the mean of the distribution.
2046 { return _M_param.mean(); }
2049 * @brief Returns the standard deviation of the distribution.
2053 { return _M_param.stddev(); }
2056 * @brief Returns the parameter set of the distribution.
2060 { return _M_param; }
2063 * @brief Sets the parameter set of the distribution.
2064 * @param __param The new parameter set of the distribution.
2067 param(const param_type& __param)
2068 { _M_param = __param; }
2071 * @brief Returns the greatest lower bound value of the distribution.
2075 { return std::numeric_limits<result_type>::min(); }
2078 * @brief Returns the least upper bound value of the distribution.
2082 { return std::numeric_limits<result_type>::max(); }
2085 * @brief Generating functions.
2087 template<typename _UniformRandomNumberGenerator>
2089 operator()(_UniformRandomNumberGenerator& __urng)
2090 { return this->operator()(__urng, _M_param); }
2092 template<typename _UniformRandomNumberGenerator>
2094 operator()(_UniformRandomNumberGenerator& __urng,
2095 const param_type& __p);
2098 * @brief Return true if two normal distributions have
2099 * the same parameters and the sequences that would
2100 * be generated are equal.
2102 template<typename _RealType1>
2104 operator==(const std::normal_distribution<_RealType1>& __d1,
2105 const std::normal_distribution<_RealType1>& __d2);
2108 * @brief Inserts a %normal_distribution random number distribution
2109 * @p __x into the output stream @p __os.
2111 * @param __os An output stream.
2112 * @param __x A %normal_distribution random number distribution.
2114 * @returns The output stream with the state of @p __x inserted or in
2117 template<typename _RealType1, typename _CharT, typename _Traits>
2118 friend std::basic_ostream<_CharT, _Traits>&
2119 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2120 const std::normal_distribution<_RealType1>& __x);
2123 * @brief Extracts a %normal_distribution random number distribution
2124 * @p __x from the input stream @p __is.
2126 * @param __is An input stream.
2127 * @param __x A %normal_distribution random number generator engine.
2129 * @returns The input stream with @p __x extracted or in an error
2132 template<typename _RealType1, typename _CharT, typename _Traits>
2133 friend std::basic_istream<_CharT, _Traits>&
2134 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2135 std::normal_distribution<_RealType1>& __x);
2138 param_type _M_param;
2139 result_type _M_saved;
2140 bool _M_saved_available;
2144 * @brief Return true if two normal distributions are different.
2146 template<typename _RealType>
2148 operator!=(const std::normal_distribution<_RealType>& __d1,
2149 const std::normal_distribution<_RealType>& __d2)
2150 { return !(__d1 == __d2); }
2154 * @brief A lognormal_distribution random number distribution.
2156 * The formula for the normal probability mass function is
2158 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2159 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2162 template<typename _RealType = double>
2163 class lognormal_distribution
2165 static_assert(std::is_floating_point<_RealType>::value,
2166 "template argument not a floating point type");
2169 /** The type of the range of the distribution. */
2170 typedef _RealType result_type;
2171 /** Parameter type. */
2174 typedef lognormal_distribution<_RealType> distribution_type;
2177 param_type(_RealType __m = _RealType(0),
2178 _RealType __s = _RealType(1))
2179 : _M_m(__m), _M_s(__s)
2191 operator==(const param_type& __p1, const param_type& __p2)
2192 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2200 lognormal_distribution(_RealType __m = _RealType(0),
2201 _RealType __s = _RealType(1))
2202 : _M_param(__m, __s), _M_nd()
2206 lognormal_distribution(const param_type& __p)
2207 : _M_param(__p), _M_nd()
2211 * Resets the distribution state.
2222 { return _M_param.m(); }
2226 { return _M_param.s(); }
2229 * @brief Returns the parameter set of the distribution.
2233 { return _M_param; }
2236 * @brief Sets the parameter set of the distribution.
2237 * @param __param The new parameter set of the distribution.
2240 param(const param_type& __param)
2241 { _M_param = __param; }
2244 * @brief Returns the greatest lower bound value of the distribution.
2248 { return result_type(0); }
2251 * @brief Returns the least upper bound value of the distribution.
2255 { return std::numeric_limits<result_type>::max(); }
2258 * @brief Generating functions.
2260 template<typename _UniformRandomNumberGenerator>
2262 operator()(_UniformRandomNumberGenerator& __urng)
2263 { return this->operator()(__urng, _M_param); }
2265 template<typename _UniformRandomNumberGenerator>
2267 operator()(_UniformRandomNumberGenerator& __urng,
2268 const param_type& __p)
2269 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2272 * @brief Return true if two lognormal distributions have
2273 * the same parameters and the sequences that would
2274 * be generated are equal.
2277 operator==(const lognormal_distribution& __d1,
2278 const lognormal_distribution& __d2)
2279 { return (__d1._M_param == __d2._M_param
2280 && __d1._M_nd == __d2._M_nd); }
2283 * @brief Inserts a %lognormal_distribution random number distribution
2284 * @p __x into the output stream @p __os.
2286 * @param __os An output stream.
2287 * @param __x A %lognormal_distribution random number distribution.
2289 * @returns The output stream with the state of @p __x inserted or in
2292 template<typename _RealType1, typename _CharT, typename _Traits>
2293 friend std::basic_ostream<_CharT, _Traits>&
2294 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2295 const std::lognormal_distribution<_RealType1>& __x);
2298 * @brief Extracts a %lognormal_distribution random number distribution
2299 * @p __x from the input stream @p __is.
2301 * @param __is An input stream.
2302 * @param __x A %lognormal_distribution random number
2305 * @returns The input stream with @p __x extracted or in an error state.
2307 template<typename _RealType1, typename _CharT, typename _Traits>
2308 friend std::basic_istream<_CharT, _Traits>&
2309 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2310 std::lognormal_distribution<_RealType1>& __x);
2313 param_type _M_param;
2315 std::normal_distribution<result_type> _M_nd;
2319 * @brief Return true if two lognormal distributions are different.
2321 template<typename _RealType>
2323 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2324 const std::lognormal_distribution<_RealType>& __d2)
2325 { return !(__d1 == __d2); }
2329 * @brief A gamma continuous distribution for random numbers.
2331 * The formula for the gamma probability density function is:
2333 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2334 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2337 template<typename _RealType = double>
2338 class gamma_distribution
2340 static_assert(std::is_floating_point<_RealType>::value,
2341 "template argument not a floating point type");
2344 /** The type of the range of the distribution. */
2345 typedef _RealType result_type;
2346 /** Parameter type. */
2349 typedef gamma_distribution<_RealType> distribution_type;
2350 friend class gamma_distribution<_RealType>;
2353 param_type(_RealType __alpha_val = _RealType(1),
2354 _RealType __beta_val = _RealType(1))
2355 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2357 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2363 { return _M_alpha; }
2370 operator==(const param_type& __p1, const param_type& __p2)
2371 { return (__p1._M_alpha == __p2._M_alpha
2372 && __p1._M_beta == __p2._M_beta); }
2381 _RealType _M_malpha, _M_a2;
2386 * @brief Constructs a gamma distribution with parameters
2387 * @f$\alpha@f$ and @f$\beta@f$.
2390 gamma_distribution(_RealType __alpha_val = _RealType(1),
2391 _RealType __beta_val = _RealType(1))
2392 : _M_param(__alpha_val, __beta_val), _M_nd()
2396 gamma_distribution(const param_type& __p)
2397 : _M_param(__p), _M_nd()
2401 * @brief Resets the distribution state.
2408 * @brief Returns the @f$\alpha@f$ of the distribution.
2412 { return _M_param.alpha(); }
2415 * @brief Returns the @f$\beta@f$ of the distribution.
2419 { return _M_param.beta(); }
2422 * @brief Returns the parameter set of the distribution.
2426 { return _M_param; }
2429 * @brief Sets the parameter set of the distribution.
2430 * @param __param The new parameter set of the distribution.
2433 param(const param_type& __param)
2434 { _M_param = __param; }
2437 * @brief Returns the greatest lower bound value of the distribution.
2441 { return result_type(0); }
2444 * @brief Returns the least upper bound value of the distribution.
2448 { return std::numeric_limits<result_type>::max(); }
2451 * @brief Generating functions.
2453 template<typename _UniformRandomNumberGenerator>
2455 operator()(_UniformRandomNumberGenerator& __urng)
2456 { return this->operator()(__urng, _M_param); }
2458 template<typename _UniformRandomNumberGenerator>
2460 operator()(_UniformRandomNumberGenerator& __urng,
2461 const param_type& __p);
2464 * @brief Return true if two gamma distributions have the same
2465 * parameters and the sequences that would be generated
2469 operator==(const gamma_distribution& __d1,
2470 const gamma_distribution& __d2)
2471 { return (__d1._M_param == __d2._M_param
2472 && __d1._M_nd == __d2._M_nd); }
2475 * @brief Inserts a %gamma_distribution random number distribution
2476 * @p __x into the output stream @p __os.
2478 * @param __os An output stream.
2479 * @param __x A %gamma_distribution random number distribution.
2481 * @returns The output stream with the state of @p __x inserted or in
2484 template<typename _RealType1, typename _CharT, typename _Traits>
2485 friend std::basic_ostream<_CharT, _Traits>&
2486 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2487 const std::gamma_distribution<_RealType1>& __x);
2490 * @brief Extracts a %gamma_distribution random number distribution
2491 * @p __x from the input stream @p __is.
2493 * @param __is An input stream.
2494 * @param __x A %gamma_distribution random number generator engine.
2496 * @returns The input stream with @p __x extracted or in an error state.
2498 template<typename _RealType1, typename _CharT, typename _Traits>
2499 friend std::basic_istream<_CharT, _Traits>&
2500 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2501 std::gamma_distribution<_RealType1>& __x);
2504 param_type _M_param;
2506 std::normal_distribution<result_type> _M_nd;
2510 * @brief Return true if two gamma distributions are different.
2512 template<typename _RealType>
2514 operator!=(const std::gamma_distribution<_RealType>& __d1,
2515 const std::gamma_distribution<_RealType>& __d2)
2516 { return !(__d1 == __d2); }
2520 * @brief A chi_squared_distribution random number distribution.
2522 * The formula for the normal probability mass function is
2523 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2525 template<typename _RealType = double>
2526 class chi_squared_distribution
2528 static_assert(std::is_floating_point<_RealType>::value,
2529 "template argument not a floating point type");
2532 /** The type of the range of the distribution. */
2533 typedef _RealType result_type;
2534 /** Parameter type. */
2537 typedef chi_squared_distribution<_RealType> distribution_type;
2540 param_type(_RealType __n = _RealType(1))
2549 operator==(const param_type& __p1, const param_type& __p2)
2550 { return __p1._M_n == __p2._M_n; }
2557 chi_squared_distribution(_RealType __n = _RealType(1))
2558 : _M_param(__n), _M_gd(__n / 2)
2562 chi_squared_distribution(const param_type& __p)
2563 : _M_param(__p), _M_gd(__p.n() / 2)
2567 * @brief Resets the distribution state.
2578 { return _M_param.n(); }
2581 * @brief Returns the parameter set of the distribution.
2585 { return _M_param; }
2588 * @brief Sets the parameter set of the distribution.
2589 * @param __param The new parameter set of the distribution.
2592 param(const param_type& __param)
2593 { _M_param = __param; }
2596 * @brief Returns the greatest lower bound value of the distribution.
2600 { return result_type(0); }
2603 * @brief Returns the least upper bound value of the distribution.
2607 { return std::numeric_limits<result_type>::max(); }
2610 * @brief Generating functions.
2612 template<typename _UniformRandomNumberGenerator>
2614 operator()(_UniformRandomNumberGenerator& __urng)
2615 { return 2 * _M_gd(__urng); }
2617 template<typename _UniformRandomNumberGenerator>
2619 operator()(_UniformRandomNumberGenerator& __urng,
2620 const param_type& __p)
2622 typedef typename std::gamma_distribution<result_type>::param_type
2624 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2628 * @brief Return true if two Chi-squared distributions have
2629 * the same parameters and the sequences that would be
2630 * generated are equal.
2633 operator==(const chi_squared_distribution& __d1,
2634 const chi_squared_distribution& __d2)
2635 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
2638 * @brief Inserts a %chi_squared_distribution random number distribution
2639 * @p __x into the output stream @p __os.
2641 * @param __os An output stream.
2642 * @param __x A %chi_squared_distribution random number distribution.
2644 * @returns The output stream with the state of @p __x inserted or in
2647 template<typename _RealType1, typename _CharT, typename _Traits>
2648 friend std::basic_ostream<_CharT, _Traits>&
2649 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2650 const std::chi_squared_distribution<_RealType1>& __x);
2653 * @brief Extracts a %chi_squared_distribution random number distribution
2654 * @p __x from the input stream @p __is.
2656 * @param __is An input stream.
2657 * @param __x A %chi_squared_distribution random number
2660 * @returns The input stream with @p __x extracted or in an error state.
2662 template<typename _RealType1, typename _CharT, typename _Traits>
2663 friend std::basic_istream<_CharT, _Traits>&
2664 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2665 std::chi_squared_distribution<_RealType1>& __x);
2668 param_type _M_param;
2670 std::gamma_distribution<result_type> _M_gd;
2674 * @brief Return true if two Chi-squared distributions are different.
2676 template<typename _RealType>
2678 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2679 const std::chi_squared_distribution<_RealType>& __d2)
2680 { return !(__d1 == __d2); }
2684 * @brief A cauchy_distribution random number distribution.
2686 * The formula for the normal probability mass function is
2687 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2689 template<typename _RealType = double>
2690 class cauchy_distribution
2692 static_assert(std::is_floating_point<_RealType>::value,
2693 "template argument not a floating point type");
2696 /** The type of the range of the distribution. */
2697 typedef _RealType result_type;
2698 /** Parameter type. */
2701 typedef cauchy_distribution<_RealType> distribution_type;
2704 param_type(_RealType __a = _RealType(0),
2705 _RealType __b = _RealType(1))
2706 : _M_a(__a), _M_b(__b)
2718 operator==(const param_type& __p1, const param_type& __p2)
2719 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2727 cauchy_distribution(_RealType __a = _RealType(0),
2728 _RealType __b = _RealType(1))
2729 : _M_param(__a, __b)
2733 cauchy_distribution(const param_type& __p)
2738 * @brief Resets the distribution state.
2749 { return _M_param.a(); }
2753 { return _M_param.b(); }
2756 * @brief Returns the parameter set of the distribution.
2760 { return _M_param; }
2763 * @brief Sets the parameter set of the distribution.
2764 * @param __param The new parameter set of the distribution.
2767 param(const param_type& __param)
2768 { _M_param = __param; }
2771 * @brief Returns the greatest lower bound value of the distribution.
2775 { return std::numeric_limits<result_type>::min(); }
2778 * @brief Returns the least upper bound value of the distribution.
2782 { return std::numeric_limits<result_type>::max(); }
2785 * @brief Generating functions.
2787 template<typename _UniformRandomNumberGenerator>
2789 operator()(_UniformRandomNumberGenerator& __urng)
2790 { return this->operator()(__urng, _M_param); }
2792 template<typename _UniformRandomNumberGenerator>
2794 operator()(_UniformRandomNumberGenerator& __urng,
2795 const param_type& __p);
2798 * @brief Return true if two Cauchy distributions have
2799 * the same parameters.
2802 operator==(const cauchy_distribution& __d1,
2803 const cauchy_distribution& __d2)
2804 { return __d1._M_param == __d2._M_param; }
2807 param_type _M_param;
2811 * @brief Return true if two Cauchy distributions have
2812 * different parameters.
2814 template<typename _RealType>
2816 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2817 const std::cauchy_distribution<_RealType>& __d2)
2818 { return !(__d1 == __d2); }
2821 * @brief Inserts a %cauchy_distribution random number distribution
2822 * @p __x into the output stream @p __os.
2824 * @param __os An output stream.
2825 * @param __x A %cauchy_distribution random number distribution.
2827 * @returns The output stream with the state of @p __x inserted or in
2830 template<typename _RealType, typename _CharT, typename _Traits>
2831 std::basic_ostream<_CharT, _Traits>&
2832 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2833 const std::cauchy_distribution<_RealType>& __x);
2836 * @brief Extracts a %cauchy_distribution random number distribution
2837 * @p __x from the input stream @p __is.
2839 * @param __is An input stream.
2840 * @param __x A %cauchy_distribution random number
2843 * @returns The input stream with @p __x extracted or in an error state.
2845 template<typename _RealType, typename _CharT, typename _Traits>
2846 std::basic_istream<_CharT, _Traits>&
2847 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2848 std::cauchy_distribution<_RealType>& __x);
2852 * @brief A fisher_f_distribution random number distribution.
2854 * The formula for the normal probability mass function is
2856 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2857 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2858 * (1 + \frac{mx}{n})^{-(m+n)/2}
2861 template<typename _RealType = double>
2862 class fisher_f_distribution
2864 static_assert(std::is_floating_point<_RealType>::value,
2865 "template argument not a floating point type");
2868 /** The type of the range of the distribution. */
2869 typedef _RealType result_type;
2870 /** Parameter type. */
2873 typedef fisher_f_distribution<_RealType> distribution_type;
2876 param_type(_RealType __m = _RealType(1),
2877 _RealType __n = _RealType(1))
2878 : _M_m(__m), _M_n(__n)
2890 operator==(const param_type& __p1, const param_type& __p2)
2891 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2899 fisher_f_distribution(_RealType __m = _RealType(1),
2900 _RealType __n = _RealType(1))
2901 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2905 fisher_f_distribution(const param_type& __p)
2906 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2910 * @brief Resets the distribution state.
2924 { return _M_param.m(); }
2928 { return _M_param.n(); }
2931 * @brief Returns the parameter set of the distribution.
2935 { return _M_param; }
2938 * @brief Sets the parameter set of the distribution.
2939 * @param __param The new parameter set of the distribution.
2942 param(const param_type& __param)
2943 { _M_param = __param; }
2946 * @brief Returns the greatest lower bound value of the distribution.
2950 { return result_type(0); }
2953 * @brief Returns the least upper bound value of the distribution.
2957 { return std::numeric_limits<result_type>::max(); }
2960 * @brief Generating functions.
2962 template<typename _UniformRandomNumberGenerator>
2964 operator()(_UniformRandomNumberGenerator& __urng)
2965 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2967 template<typename _UniformRandomNumberGenerator>
2969 operator()(_UniformRandomNumberGenerator& __urng,
2970 const param_type& __p)
2972 typedef typename std::gamma_distribution<result_type>::param_type
2974 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2975 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2979 * @brief Return true if two Fisher f distributions have
2980 * the same parameters and the sequences that would
2981 * be generated are equal.
2984 operator==(const fisher_f_distribution& __d1,
2985 const fisher_f_distribution& __d2)
2986 { return (__d1._M_param == __d2._M_param
2987 && __d1._M_gd_x == __d2._M_gd_x
2988 && __d1._M_gd_y == __d2._M_gd_y); }
2991 * @brief Inserts a %fisher_f_distribution random number distribution
2992 * @p __x into the output stream @p __os.
2994 * @param __os An output stream.
2995 * @param __x A %fisher_f_distribution random number distribution.
2997 * @returns The output stream with the state of @p __x inserted or in
3000 template<typename _RealType1, typename _CharT, typename _Traits>
3001 friend std::basic_ostream<_CharT, _Traits>&
3002 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3003 const std::fisher_f_distribution<_RealType1>& __x);
3006 * @brief Extracts a %fisher_f_distribution random number distribution
3007 * @p __x from the input stream @p __is.
3009 * @param __is An input stream.
3010 * @param __x A %fisher_f_distribution random number
3013 * @returns The input stream with @p __x extracted or in an error state.
3015 template<typename _RealType1, typename _CharT, typename _Traits>
3016 friend std::basic_istream<_CharT, _Traits>&
3017 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3018 std::fisher_f_distribution<_RealType1>& __x);
3021 param_type _M_param;
3023 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3027 * @brief Return true if two Fisher f distributions are diferent.
3029 template<typename _RealType>
3031 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3032 const std::fisher_f_distribution<_RealType>& __d2)
3033 { return !(__d1 == __d2); }
3036 * @brief A student_t_distribution random number distribution.
3038 * The formula for the normal probability mass function is:
3040 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3041 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3044 template<typename _RealType = double>
3045 class student_t_distribution
3047 static_assert(std::is_floating_point<_RealType>::value,
3048 "template argument not a floating point type");
3051 /** The type of the range of the distribution. */
3052 typedef _RealType result_type;
3053 /** Parameter type. */
3056 typedef student_t_distribution<_RealType> distribution_type;
3059 param_type(_RealType __n = _RealType(1))
3068 operator==(const param_type& __p1, const param_type& __p2)
3069 { return __p1._M_n == __p2._M_n; }
3076 student_t_distribution(_RealType __n = _RealType(1))
3077 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3081 student_t_distribution(const param_type& __p)
3082 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3086 * @brief Resets the distribution state.
3100 { return _M_param.n(); }
3103 * @brief Returns the parameter set of the distribution.
3107 { return _M_param; }
3110 * @brief Sets the parameter set of the distribution.
3111 * @param __param The new parameter set of the distribution.
3114 param(const param_type& __param)
3115 { _M_param = __param; }
3118 * @brief Returns the greatest lower bound value of the distribution.
3122 { return std::numeric_limits<result_type>::min(); }
3125 * @brief Returns the least upper bound value of the distribution.
3129 { return std::numeric_limits<result_type>::max(); }
3132 * @brief Generating functions.
3134 template<typename _UniformRandomNumberGenerator>
3136 operator()(_UniformRandomNumberGenerator& __urng)
3137 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3139 template<typename _UniformRandomNumberGenerator>
3141 operator()(_UniformRandomNumberGenerator& __urng,
3142 const param_type& __p)
3144 typedef typename std::gamma_distribution<result_type>::param_type
3147 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3148 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3152 * @brief Return true if two Student t distributions have
3153 * the same parameters and the sequences that would
3154 * be generated are equal.
3157 operator==(const student_t_distribution& __d1,
3158 const student_t_distribution& __d2)
3159 { return (__d1._M_param == __d2._M_param
3160 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3163 * @brief Inserts a %student_t_distribution random number distribution
3164 * @p __x into the output stream @p __os.
3166 * @param __os An output stream.
3167 * @param __x A %student_t_distribution random number distribution.
3169 * @returns The output stream with the state of @p __x inserted or in
3172 template<typename _RealType1, typename _CharT, typename _Traits>
3173 friend std::basic_ostream<_CharT, _Traits>&
3174 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3175 const std::student_t_distribution<_RealType1>& __x);
3178 * @brief Extracts a %student_t_distribution random number distribution
3179 * @p __x from the input stream @p __is.
3181 * @param __is An input stream.
3182 * @param __x A %student_t_distribution random number
3185 * @returns The input stream with @p __x extracted or in an error state.
3187 template<typename _RealType1, typename _CharT, typename _Traits>
3188 friend std::basic_istream<_CharT, _Traits>&
3189 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3190 std::student_t_distribution<_RealType1>& __x);
3193 param_type _M_param;
3195 std::normal_distribution<result_type> _M_nd;
3196 std::gamma_distribution<result_type> _M_gd;
3200 * @brief Return true if two Student t distributions are different.
3202 template<typename _RealType>
3204 operator!=(const std::student_t_distribution<_RealType>& __d1,
3205 const std::student_t_distribution<_RealType>& __d2)
3206 { return !(__d1 == __d2); }
3209 /* @} */ // group random_distributions_normal
3212 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3213 * @ingroup random_distributions
3218 * @brief A Bernoulli random number distribution.
3220 * Generates a sequence of true and false values with likelihood @f$p@f$
3221 * that true will come up and @f$(1 - p)@f$ that false will appear.
3223 class bernoulli_distribution
3226 /** The type of the range of the distribution. */
3227 typedef bool result_type;
3228 /** Parameter type. */
3231 typedef bernoulli_distribution distribution_type;
3234 param_type(double __p = 0.5)
3237 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3245 operator==(const param_type& __p1, const param_type& __p2)
3246 { return __p1._M_p == __p2._M_p; }
3254 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3256 * @param __p [IN] The likelihood of a true result being returned.
3257 * Must be in the interval @f$[0, 1]@f$.
3260 bernoulli_distribution(double __p = 0.5)
3265 bernoulli_distribution(const param_type& __p)
3270 * @brief Resets the distribution state.
3272 * Does nothing for a Bernoulli distribution.
3278 * @brief Returns the @p p parameter of the distribution.
3282 { return _M_param.p(); }
3285 * @brief Returns the parameter set of the distribution.
3289 { return _M_param; }
3292 * @brief Sets the parameter set of the distribution.
3293 * @param __param The new parameter set of the distribution.
3296 param(const param_type& __param)
3297 { _M_param = __param; }
3300 * @brief Returns the greatest lower bound value of the distribution.
3304 { return std::numeric_limits<result_type>::min(); }
3307 * @brief Returns the least upper bound value of the distribution.
3311 { return std::numeric_limits<result_type>::max(); }
3314 * @brief Generating functions.
3316 template<typename _UniformRandomNumberGenerator>
3318 operator()(_UniformRandomNumberGenerator& __urng)
3319 { return this->operator()(__urng, _M_param); }
3321 template<typename _UniformRandomNumberGenerator>
3323 operator()(_UniformRandomNumberGenerator& __urng,
3324 const param_type& __p)
3326 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3328 if ((__aurng() - __aurng.min())
3329 < __p.p() * (__aurng.max() - __aurng.min()))
3335 * @brief Return true if two Bernoulli distributions have
3336 * the same parameters.
3339 operator==(const bernoulli_distribution& __d1,
3340 const bernoulli_distribution& __d2)
3341 { return __d1._M_param == __d2._M_param; }
3344 param_type _M_param;
3348 * @brief Return true if two Bernoulli distributions have
3349 * different parameters.
3352 operator!=(const std::bernoulli_distribution& __d1,
3353 const std::bernoulli_distribution& __d2)
3354 { return !(__d1 == __d2); }
3357 * @brief Inserts a %bernoulli_distribution random number distribution
3358 * @p __x into the output stream @p __os.
3360 * @param __os An output stream.
3361 * @param __x A %bernoulli_distribution random number distribution.
3363 * @returns The output stream with the state of @p __x inserted or in
3366 template<typename _CharT, typename _Traits>
3367 std::basic_ostream<_CharT, _Traits>&
3368 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3369 const std::bernoulli_distribution& __x);
3372 * @brief Extracts a %bernoulli_distribution random number distribution
3373 * @p __x from the input stream @p __is.
3375 * @param __is An input stream.
3376 * @param __x A %bernoulli_distribution random number generator engine.
3378 * @returns The input stream with @p __x extracted or in an error state.
3380 template<typename _CharT, typename _Traits>
3381 std::basic_istream<_CharT, _Traits>&
3382 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3383 std::bernoulli_distribution& __x)
3387 __x.param(bernoulli_distribution::param_type(__p));
3393 * @brief A discrete binomial random number distribution.
3395 * The formula for the binomial probability density function is
3396 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3397 * and @f$p@f$ are the parameters of the distribution.
3399 template<typename _IntType = int>
3400 class binomial_distribution
3402 static_assert(std::is_integral<_IntType>::value,
3403 "template argument not an integral type");
3406 /** The type of the range of the distribution. */
3407 typedef _IntType result_type;
3408 /** Parameter type. */
3411 typedef binomial_distribution<_IntType> distribution_type;
3412 friend class binomial_distribution<_IntType>;
3415 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3416 : _M_t(__t), _M_p(__p)
3418 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3433 operator==(const param_type& __p1, const param_type& __p2)
3434 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3444 #if _GLIBCXX_USE_C99_MATH_TR1
3445 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3446 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3451 // constructors and member function
3453 binomial_distribution(_IntType __t = _IntType(1),
3455 : _M_param(__t, __p), _M_nd()
3459 binomial_distribution(const param_type& __p)
3460 : _M_param(__p), _M_nd()
3464 * @brief Resets the distribution state.
3471 * @brief Returns the distribution @p t parameter.
3475 { return _M_param.t(); }
3478 * @brief Returns the distribution @p p parameter.
3482 { return _M_param.p(); }
3485 * @brief Returns the parameter set of the distribution.
3489 { return _M_param; }
3492 * @brief Sets the parameter set of the distribution.
3493 * @param __param The new parameter set of the distribution.
3496 param(const param_type& __param)
3497 { _M_param = __param; }
3500 * @brief Returns the greatest lower bound value of the distribution.
3507 * @brief Returns the least upper bound value of the distribution.
3511 { return _M_param.t(); }
3514 * @brief Generating functions.
3516 template<typename _UniformRandomNumberGenerator>
3518 operator()(_UniformRandomNumberGenerator& __urng)
3519 { return this->operator()(__urng, _M_param); }
3521 template<typename _UniformRandomNumberGenerator>
3523 operator()(_UniformRandomNumberGenerator& __urng,
3524 const param_type& __p);
3527 * @brief Return true if two binomial distributions have
3528 * the same parameters and the sequences that would
3529 * be generated are equal.
3532 operator==(const binomial_distribution& __d1,
3533 const binomial_distribution& __d2)
3534 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3535 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
3537 { return __d1._M_param == __d2._M_param; }
3541 * @brief Inserts a %binomial_distribution random number distribution
3542 * @p __x into the output stream @p __os.
3544 * @param __os An output stream.
3545 * @param __x A %binomial_distribution random number distribution.
3547 * @returns The output stream with the state of @p __x inserted or in
3550 template<typename _IntType1,
3551 typename _CharT, typename _Traits>
3552 friend std::basic_ostream<_CharT, _Traits>&
3553 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3554 const std::binomial_distribution<_IntType1>& __x);
3557 * @brief Extracts a %binomial_distribution random number distribution
3558 * @p __x from the input stream @p __is.
3560 * @param __is An input stream.
3561 * @param __x A %binomial_distribution random number generator engine.
3563 * @returns The input stream with @p __x extracted or in an error
3566 template<typename _IntType1,
3567 typename _CharT, typename _Traits>
3568 friend std::basic_istream<_CharT, _Traits>&
3569 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3570 std::binomial_distribution<_IntType1>& __x);
3573 template<typename _UniformRandomNumberGenerator>
3575 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3577 param_type _M_param;
3579 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3580 std::normal_distribution<double> _M_nd;
3584 * @brief Return true if two binomial distributions are different.
3586 template<typename _IntType>
3588 operator!=(const std::binomial_distribution<_IntType>& __d1,
3589 const std::binomial_distribution<_IntType>& __d2)
3590 { return !(__d1 == __d2); }
3594 * @brief A discrete geometric random number distribution.
3596 * The formula for the geometric probability density function is
3597 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3600 template<typename _IntType = int>
3601 class geometric_distribution
3603 static_assert(std::is_integral<_IntType>::value,
3604 "template argument not an integral type");
3607 /** The type of the range of the distribution. */
3608 typedef _IntType result_type;
3609 /** Parameter type. */
3612 typedef geometric_distribution<_IntType> distribution_type;
3613 friend class geometric_distribution<_IntType>;
3616 param_type(double __p = 0.5)
3619 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
3628 operator==(const param_type& __p1, const param_type& __p2)
3629 { return __p1._M_p == __p2._M_p; }
3634 { _M_log_1_p = std::log(1.0 - _M_p); }
3641 // constructors and member function
3643 geometric_distribution(double __p = 0.5)
3648 geometric_distribution(const param_type& __p)
3653 * @brief Resets the distribution state.
3655 * Does nothing for the geometric distribution.
3661 * @brief Returns the distribution parameter @p p.
3665 { return _M_param.p(); }
3668 * @brief Returns the parameter set of the distribution.
3672 { return _M_param; }
3675 * @brief Sets the parameter set of the distribution.
3676 * @param __param The new parameter set of the distribution.
3679 param(const param_type& __param)
3680 { _M_param = __param; }
3683 * @brief Returns the greatest lower bound value of the distribution.
3690 * @brief Returns the least upper bound value of the distribution.
3694 { return std::numeric_limits<result_type>::max(); }
3697 * @brief Generating functions.
3699 template<typename _UniformRandomNumberGenerator>
3701 operator()(_UniformRandomNumberGenerator& __urng)
3702 { return this->operator()(__urng, _M_param); }
3704 template<typename _UniformRandomNumberGenerator>
3706 operator()(_UniformRandomNumberGenerator& __urng,
3707 const param_type& __p);
3710 * @brief Return true if two geometric distributions have
3711 * the same parameters.
3714 operator==(const geometric_distribution& __d1,
3715 const geometric_distribution& __d2)
3716 { return __d1._M_param == __d2._M_param; }
3719 param_type _M_param;
3723 * @brief Return true if two geometric distributions have
3724 * different parameters.
3726 template<typename _IntType>
3728 operator!=(const std::geometric_distribution<_IntType>& __d1,
3729 const std::geometric_distribution<_IntType>& __d2)
3730 { return !(__d1 == __d2); }
3733 * @brief Inserts a %geometric_distribution random number distribution
3734 * @p __x into the output stream @p __os.
3736 * @param __os An output stream.
3737 * @param __x A %geometric_distribution random number distribution.
3739 * @returns The output stream with the state of @p __x inserted or in
3742 template<typename _IntType,
3743 typename _CharT, typename _Traits>
3744 std::basic_ostream<_CharT, _Traits>&
3745 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3746 const std::geometric_distribution<_IntType>& __x);
3749 * @brief Extracts a %geometric_distribution random number distribution
3750 * @p __x from the input stream @p __is.
3752 * @param __is An input stream.
3753 * @param __x A %geometric_distribution random number generator engine.
3755 * @returns The input stream with @p __x extracted or in an error state.
3757 template<typename _IntType,
3758 typename _CharT, typename _Traits>
3759 std::basic_istream<_CharT, _Traits>&
3760 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3761 std::geometric_distribution<_IntType>& __x);
3765 * @brief A negative_binomial_distribution random number distribution.
3767 * The formula for the negative binomial probability mass function is
3768 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3769 * and @f$p@f$ are the parameters of the distribution.
3771 template<typename _IntType = int>
3772 class negative_binomial_distribution
3774 static_assert(std::is_integral<_IntType>::value,
3775 "template argument not an integral type");
3778 /** The type of the range of the distribution. */
3779 typedef _IntType result_type;
3780 /** Parameter type. */
3783 typedef negative_binomial_distribution<_IntType> distribution_type;
3786 param_type(_IntType __k = 1, double __p = 0.5)
3787 : _M_k(__k), _M_p(__p)
3789 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
3801 operator==(const param_type& __p1, const param_type& __p2)
3802 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3810 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3811 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
3815 negative_binomial_distribution(const param_type& __p)
3816 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
3820 * @brief Resets the distribution state.
3827 * @brief Return the @f$k@f$ parameter of the distribution.
3831 { return _M_param.k(); }
3834 * @brief Return the @f$p@f$ parameter of the distribution.
3838 { return _M_param.p(); }
3841 * @brief Returns the parameter set of the distribution.
3845 { return _M_param; }
3848 * @brief Sets the parameter set of the distribution.
3849 * @param __param The new parameter set of the distribution.
3852 param(const param_type& __param)
3853 { _M_param = __param; }
3856 * @brief Returns the greatest lower bound value of the distribution.
3860 { return result_type(0); }
3863 * @brief Returns the least upper bound value of the distribution.
3867 { return std::numeric_limits<result_type>::max(); }
3870 * @brief Generating functions.
3872 template<typename _UniformRandomNumberGenerator>
3874 operator()(_UniformRandomNumberGenerator& __urng);
3876 template<typename _UniformRandomNumberGenerator>
3878 operator()(_UniformRandomNumberGenerator& __urng,
3879 const param_type& __p);
3882 * @brief Return true if two negative binomial distributions have
3883 * the same parameters and the sequences that would be
3884 * generated are equal.
3887 operator==(const negative_binomial_distribution& __d1,
3888 const negative_binomial_distribution& __d2)
3889 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
3892 * @brief Inserts a %negative_binomial_distribution random
3893 * number distribution @p __x into the output stream @p __os.
3895 * @param __os An output stream.
3896 * @param __x A %negative_binomial_distribution random number
3899 * @returns The output stream with the state of @p __x inserted or in
3902 template<typename _IntType1, typename _CharT, typename _Traits>
3903 friend std::basic_ostream<_CharT, _Traits>&
3904 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3905 const std::negative_binomial_distribution<_IntType1>& __x);
3908 * @brief Extracts a %negative_binomial_distribution random number
3909 * distribution @p __x from the input stream @p __is.
3911 * @param __is An input stream.
3912 * @param __x A %negative_binomial_distribution random number
3915 * @returns The input stream with @p __x extracted or in an error state.
3917 template<typename _IntType1, typename _CharT, typename _Traits>
3918 friend std::basic_istream<_CharT, _Traits>&
3919 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3920 std::negative_binomial_distribution<_IntType1>& __x);
3923 param_type _M_param;
3925 std::gamma_distribution<double> _M_gd;
3929 * @brief Return true if two negative binomial distributions are different.
3931 template<typename _IntType>
3933 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3934 const std::negative_binomial_distribution<_IntType>& __d2)
3935 { return !(__d1 == __d2); }
3938 /* @} */ // group random_distributions_bernoulli
3941 * @addtogroup random_distributions_poisson Poisson Distributions
3942 * @ingroup random_distributions
3947 * @brief A discrete Poisson random number distribution.
3949 * The formula for the Poisson probability density function is
3950 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3951 * parameter of the distribution.
3953 template<typename _IntType = int>
3954 class poisson_distribution
3956 static_assert(std::is_integral<_IntType>::value,
3957 "template argument not an integral type");
3960 /** The type of the range of the distribution. */
3961 typedef _IntType result_type;
3962 /** Parameter type. */
3965 typedef poisson_distribution<_IntType> distribution_type;
3966 friend class poisson_distribution<_IntType>;
3969 param_type(double __mean = 1.0)
3972 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3981 operator==(const param_type& __p1, const param_type& __p2)
3982 { return __p1._M_mean == __p2._M_mean; }
3985 // Hosts either log(mean) or the threshold of the simple method.
3992 #if _GLIBCXX_USE_C99_MATH_TR1
3993 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3997 // constructors and member function
3999 poisson_distribution(double __mean = 1.0)
4000 : _M_param(__mean), _M_nd()
4004 poisson_distribution(const param_type& __p)
4005 : _M_param(__p), _M_nd()
4009 * @brief Resets the distribution state.
4016 * @brief Returns the distribution parameter @p mean.
4020 { return _M_param.mean(); }
4023 * @brief Returns the parameter set of the distribution.
4027 { return _M_param; }
4030 * @brief Sets the parameter set of the distribution.
4031 * @param __param The new parameter set of the distribution.
4034 param(const param_type& __param)
4035 { _M_param = __param; }
4038 * @brief Returns the greatest lower bound value of the distribution.
4045 * @brief Returns the least upper bound value of the distribution.
4049 { return std::numeric_limits<result_type>::max(); }
4052 * @brief Generating functions.
4054 template<typename _UniformRandomNumberGenerator>
4056 operator()(_UniformRandomNumberGenerator& __urng)
4057 { return this->operator()(__urng, _M_param); }
4059 template<typename _UniformRandomNumberGenerator>
4061 operator()(_UniformRandomNumberGenerator& __urng,
4062 const param_type& __p);
4065 * @brief Return true if two Poisson distributions have the same
4066 * parameters and the sequences that would be generated
4070 operator==(const poisson_distribution& __d1,
4071 const poisson_distribution& __d2)
4072 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4073 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4075 { return __d1._M_param == __d2._M_param; }
4079 * @brief Inserts a %poisson_distribution random number distribution
4080 * @p __x into the output stream @p __os.
4082 * @param __os An output stream.
4083 * @param __x A %poisson_distribution random number distribution.
4085 * @returns The output stream with the state of @p __x inserted or in
4088 template<typename _IntType1, typename _CharT, typename _Traits>
4089 friend std::basic_ostream<_CharT, _Traits>&
4090 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4091 const std::poisson_distribution<_IntType1>& __x);
4094 * @brief Extracts a %poisson_distribution random number distribution
4095 * @p __x from the input stream @p __is.
4097 * @param __is An input stream.
4098 * @param __x A %poisson_distribution random number generator engine.
4100 * @returns The input stream with @p __x extracted or in an error
4103 template<typename _IntType1, typename _CharT, typename _Traits>
4104 friend std::basic_istream<_CharT, _Traits>&
4105 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4106 std::poisson_distribution<_IntType1>& __x);
4109 param_type _M_param;
4111 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4112 std::normal_distribution<double> _M_nd;
4116 * @brief Return true if two Poisson distributions are different.
4118 template<typename _IntType>
4120 operator!=(const std::poisson_distribution<_IntType>& __d1,
4121 const std::poisson_distribution<_IntType>& __d2)
4122 { return !(__d1 == __d2); }
4126 * @brief An exponential continuous distribution for random numbers.
4128 * The formula for the exponential probability density function is
4129 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4131 * <table border=1 cellpadding=10 cellspacing=0>
4132 * <caption align=top>Distribution Statistics</caption>
4133 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4134 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4135 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4136 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4137 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4140 template<typename _RealType = double>
4141 class exponential_distribution
4143 static_assert(std::is_floating_point<_RealType>::value,
4144 "template argument not a floating point type");
4147 /** The type of the range of the distribution. */
4148 typedef _RealType result_type;
4149 /** Parameter type. */
4152 typedef exponential_distribution<_RealType> distribution_type;
4155 param_type(_RealType __lambda = _RealType(1))
4156 : _M_lambda(__lambda)
4158 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4163 { return _M_lambda; }
4166 operator==(const param_type& __p1, const param_type& __p2)
4167 { return __p1._M_lambda == __p2._M_lambda; }
4170 _RealType _M_lambda;
4175 * @brief Constructs an exponential distribution with inverse scale
4176 * parameter @f$\lambda@f$.
4179 exponential_distribution(const result_type& __lambda = result_type(1))
4180 : _M_param(__lambda)
4184 exponential_distribution(const param_type& __p)
4189 * @brief Resets the distribution state.
4191 * Has no effect on exponential distributions.
4197 * @brief Returns the inverse scale parameter of the distribution.
4201 { return _M_param.lambda(); }
4204 * @brief Returns the parameter set of the distribution.
4208 { return _M_param; }
4211 * @brief Sets the parameter set of the distribution.
4212 * @param __param The new parameter set of the distribution.
4215 param(const param_type& __param)
4216 { _M_param = __param; }
4219 * @brief Returns the greatest lower bound value of the distribution.
4223 { return result_type(0); }
4226 * @brief Returns the least upper bound value of the distribution.
4230 { return std::numeric_limits<result_type>::max(); }
4233 * @brief Generating functions.
4235 template<typename _UniformRandomNumberGenerator>
4237 operator()(_UniformRandomNumberGenerator& __urng)
4238 { return this->operator()(__urng, _M_param); }
4240 template<typename _UniformRandomNumberGenerator>
4242 operator()(_UniformRandomNumberGenerator& __urng,
4243 const param_type& __p)
4245 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4247 return -std::log(result_type(1) - __aurng()) / __p.lambda();
4251 * @brief Return true if two exponential distributions have the same
4255 operator==(const exponential_distribution& __d1,
4256 const exponential_distribution& __d2)
4257 { return __d1._M_param == __d2._M_param; }
4260 param_type _M_param;
4264 * @brief Return true if two exponential distributions have different
4267 template<typename _RealType>
4269 operator!=(const std::exponential_distribution<_RealType>& __d1,
4270 const std::exponential_distribution<_RealType>& __d2)
4271 { return !(__d1 == __d2); }
4274 * @brief Inserts a %exponential_distribution random number distribution
4275 * @p __x into the output stream @p __os.
4277 * @param __os An output stream.
4278 * @param __x A %exponential_distribution random number distribution.
4280 * @returns The output stream with the state of @p __x inserted or in
4283 template<typename _RealType, typename _CharT, typename _Traits>
4284 std::basic_ostream<_CharT, _Traits>&
4285 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4286 const std::exponential_distribution<_RealType>& __x);
4289 * @brief Extracts a %exponential_distribution random number distribution
4290 * @p __x from the input stream @p __is.
4292 * @param __is An input stream.
4293 * @param __x A %exponential_distribution random number
4296 * @returns The input stream with @p __x extracted or in an error state.
4298 template<typename _RealType, typename _CharT, typename _Traits>
4299 std::basic_istream<_CharT, _Traits>&
4300 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4301 std::exponential_distribution<_RealType>& __x);
4305 * @brief A weibull_distribution random number distribution.
4307 * The formula for the normal probability density function is:
4309 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4310 * \exp{(-(\frac{x}{\beta})^\alpha)}
4313 template<typename _RealType = double>
4314 class weibull_distribution
4316 static_assert(std::is_floating_point<_RealType>::value,
4317 "template argument not a floating point type");
4320 /** The type of the range of the distribution. */
4321 typedef _RealType result_type;
4322 /** Parameter type. */
4325 typedef weibull_distribution<_RealType> distribution_type;
4328 param_type(_RealType __a = _RealType(1),
4329 _RealType __b = _RealType(1))
4330 : _M_a(__a), _M_b(__b)
4342 operator==(const param_type& __p1, const param_type& __p2)
4343 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4351 weibull_distribution(_RealType __a = _RealType(1),
4352 _RealType __b = _RealType(1))
4353 : _M_param(__a, __b)
4357 weibull_distribution(const param_type& __p)
4362 * @brief Resets the distribution state.
4369 * @brief Return the @f$a@f$ parameter of the distribution.
4373 { return _M_param.a(); }
4376 * @brief Return the @f$b@f$ parameter of the distribution.
4380 { return _M_param.b(); }
4383 * @brief Returns the parameter set of the distribution.
4387 { return _M_param; }
4390 * @brief Sets the parameter set of the distribution.
4391 * @param __param The new parameter set of the distribution.
4394 param(const param_type& __param)
4395 { _M_param = __param; }
4398 * @brief Returns the greatest lower bound value of the distribution.
4402 { return result_type(0); }
4405 * @brief Returns the least upper bound value of the distribution.
4409 { return std::numeric_limits<result_type>::max(); }
4412 * @brief Generating functions.
4414 template<typename _UniformRandomNumberGenerator>
4416 operator()(_UniformRandomNumberGenerator& __urng)
4417 { return this->operator()(__urng, _M_param); }
4419 template<typename _UniformRandomNumberGenerator>
4421 operator()(_UniformRandomNumberGenerator& __urng,
4422 const param_type& __p);
4425 * @brief Return true if two Weibull distributions have the same
4429 operator==(const weibull_distribution& __d1,
4430 const weibull_distribution& __d2)
4431 { return __d1._M_param == __d2._M_param; }
4434 param_type _M_param;
4438 * @brief Return true if two Weibull distributions have different
4441 template<typename _RealType>
4443 operator!=(const std::weibull_distribution<_RealType>& __d1,
4444 const std::weibull_distribution<_RealType>& __d2)
4445 { return !(__d1 == __d2); }
4448 * @brief Inserts a %weibull_distribution random number distribution
4449 * @p __x into the output stream @p __os.
4451 * @param __os An output stream.
4452 * @param __x A %weibull_distribution random number distribution.
4454 * @returns The output stream with the state of @p __x inserted or in
4457 template<typename _RealType, typename _CharT, typename _Traits>
4458 std::basic_ostream<_CharT, _Traits>&
4459 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4460 const std::weibull_distribution<_RealType>& __x);
4463 * @brief Extracts a %weibull_distribution random number distribution
4464 * @p __x from the input stream @p __is.
4466 * @param __is An input stream.
4467 * @param __x A %weibull_distribution random number
4470 * @returns The input stream with @p __x extracted or in an error state.
4472 template<typename _RealType, typename _CharT, typename _Traits>
4473 std::basic_istream<_CharT, _Traits>&
4474 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4475 std::weibull_distribution<_RealType>& __x);
4479 * @brief A extreme_value_distribution random number distribution.
4481 * The formula for the normal probability mass function is
4483 * p(x|a,b) = \frac{1}{b}
4484 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4487 template<typename _RealType = double>
4488 class extreme_value_distribution
4490 static_assert(std::is_floating_point<_RealType>::value,
4491 "template argument not a floating point type");
4494 /** The type of the range of the distribution. */
4495 typedef _RealType result_type;
4496 /** Parameter type. */
4499 typedef extreme_value_distribution<_RealType> distribution_type;
4502 param_type(_RealType __a = _RealType(0),
4503 _RealType __b = _RealType(1))
4504 : _M_a(__a), _M_b(__b)
4516 operator==(const param_type& __p1, const param_type& __p2)
4517 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4525 extreme_value_distribution(_RealType __a = _RealType(0),
4526 _RealType __b = _RealType(1))
4527 : _M_param(__a, __b)
4531 extreme_value_distribution(const param_type& __p)
4536 * @brief Resets the distribution state.
4543 * @brief Return the @f$a@f$ parameter of the distribution.
4547 { return _M_param.a(); }
4550 * @brief Return the @f$b@f$ parameter of the distribution.
4554 { return _M_param.b(); }
4557 * @brief Returns the parameter set of the distribution.
4561 { return _M_param; }
4564 * @brief Sets the parameter set of the distribution.
4565 * @param __param The new parameter set of the distribution.
4568 param(const param_type& __param)
4569 { _M_param = __param; }
4572 * @brief Returns the greatest lower bound value of the distribution.
4576 { return std::numeric_limits<result_type>::min(); }
4579 * @brief Returns the least upper bound value of the distribution.
4583 { return std::numeric_limits<result_type>::max(); }
4586 * @brief Generating functions.
4588 template<typename _UniformRandomNumberGenerator>
4590 operator()(_UniformRandomNumberGenerator& __urng)
4591 { return this->operator()(__urng, _M_param); }
4593 template<typename _UniformRandomNumberGenerator>
4595 operator()(_UniformRandomNumberGenerator& __urng,
4596 const param_type& __p);
4599 * @brief Return true if two extreme value distributions have the same
4603 operator==(const extreme_value_distribution& __d1,
4604 const extreme_value_distribution& __d2)
4605 { return __d1._M_param == __d2._M_param; }
4608 param_type _M_param;
4612 * @brief Return true if two extreme value distributions have different
4615 template<typename _RealType>
4617 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4618 const std::extreme_value_distribution<_RealType>& __d2)
4619 { return !(__d1 == __d2); }
4622 * @brief Inserts a %extreme_value_distribution random number distribution
4623 * @p __x into the output stream @p __os.
4625 * @param __os An output stream.
4626 * @param __x A %extreme_value_distribution random number distribution.
4628 * @returns The output stream with the state of @p __x inserted or in
4631 template<typename _RealType, typename _CharT, typename _Traits>
4632 std::basic_ostream<_CharT, _Traits>&
4633 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4634 const std::extreme_value_distribution<_RealType>& __x);
4637 * @brief Extracts a %extreme_value_distribution random number
4638 * distribution @p __x from the input stream @p __is.
4640 * @param __is An input stream.
4641 * @param __x A %extreme_value_distribution random number
4644 * @returns The input stream with @p __x extracted or in an error state.
4646 template<typename _RealType, typename _CharT, typename _Traits>
4647 std::basic_istream<_CharT, _Traits>&
4648 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4649 std::extreme_value_distribution<_RealType>& __x);
4653 * @brief A discrete_distribution random number distribution.
4655 * The formula for the discrete probability mass function is
4658 template<typename _IntType = int>
4659 class discrete_distribution
4661 static_assert(std::is_integral<_IntType>::value,
4662 "template argument not an integral type");
4665 /** The type of the range of the distribution. */
4666 typedef _IntType result_type;
4667 /** Parameter type. */
4670 typedef discrete_distribution<_IntType> distribution_type;
4671 friend class discrete_distribution<_IntType>;
4674 : _M_prob(), _M_cp()
4677 template<typename _InputIterator>
4678 param_type(_InputIterator __wbegin,
4679 _InputIterator __wend)
4680 : _M_prob(__wbegin, __wend), _M_cp()
4681 { _M_initialize(); }
4683 param_type(initializer_list<double> __wil)
4684 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4685 { _M_initialize(); }
4687 template<typename _Func>
4688 param_type(size_t __nw, double __xmin, double __xmax,
4691 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4692 param_type(const param_type&) = default;
4693 param_type& operator=(const param_type&) = default;
4696 probabilities() const
4697 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4700 operator==(const param_type& __p1, const param_type& __p2)
4701 { return __p1._M_prob == __p2._M_prob; }
4707 std::vector<double> _M_prob;
4708 std::vector<double> _M_cp;
4711 discrete_distribution()
4715 template<typename _InputIterator>
4716 discrete_distribution(_InputIterator __wbegin,
4717 _InputIterator __wend)
4718 : _M_param(__wbegin, __wend)
4721 discrete_distribution(initializer_list<double> __wl)
4725 template<typename _Func>
4726 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4728 : _M_param(__nw, __xmin, __xmax, __fw)
4732 discrete_distribution(const param_type& __p)
4737 * @brief Resets the distribution state.
4744 * @brief Returns the probabilities of the distribution.
4747 probabilities() const
4749 return _M_param._M_prob.empty()
4750 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4754 * @brief Returns the parameter set of the distribution.
4758 { return _M_param; }
4761 * @brief Sets the parameter set of the distribution.
4762 * @param __param The new parameter set of the distribution.
4765 param(const param_type& __param)
4766 { _M_param = __param; }
4769 * @brief Returns the greatest lower bound value of the distribution.
4773 { return result_type(0); }
4776 * @brief Returns the least upper bound value of the distribution.
4781 return _M_param._M_prob.empty()
4782 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4786 * @brief Generating functions.
4788 template<typename _UniformRandomNumberGenerator>
4790 operator()(_UniformRandomNumberGenerator& __urng)
4791 { return this->operator()(__urng, _M_param); }
4793 template<typename _UniformRandomNumberGenerator>
4795 operator()(_UniformRandomNumberGenerator& __urng,
4796 const param_type& __p);
4799 * @brief Return true if two discrete distributions have the same
4803 operator==(const discrete_distribution& __d1,
4804 const discrete_distribution& __d2)
4805 { return __d1._M_param == __d2._M_param; }
4808 * @brief Inserts a %discrete_distribution random number distribution
4809 * @p __x into the output stream @p __os.
4811 * @param __os An output stream.
4812 * @param __x A %discrete_distribution random number distribution.
4814 * @returns The output stream with the state of @p __x inserted or in
4817 template<typename _IntType1, typename _CharT, typename _Traits>
4818 friend std::basic_ostream<_CharT, _Traits>&
4819 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4820 const std::discrete_distribution<_IntType1>& __x);
4823 * @brief Extracts a %discrete_distribution random number distribution
4824 * @p __x from the input stream @p __is.
4826 * @param __is An input stream.
4827 * @param __x A %discrete_distribution random number
4830 * @returns The input stream with @p __x extracted or in an error
4833 template<typename _IntType1, typename _CharT, typename _Traits>
4834 friend std::basic_istream<_CharT, _Traits>&
4835 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4836 std::discrete_distribution<_IntType1>& __x);
4839 param_type _M_param;
4843 * @brief Return true if two discrete distributions have different
4846 template<typename _IntType>
4848 operator!=(const std::discrete_distribution<_IntType>& __d1,
4849 const std::discrete_distribution<_IntType>& __d2)
4850 { return !(__d1 == __d2); }
4854 * @brief A piecewise_constant_distribution random number distribution.
4856 * The formula for the piecewise constant probability mass function is
4859 template<typename _RealType = double>
4860 class piecewise_constant_distribution
4862 static_assert(std::is_floating_point<_RealType>::value,
4863 "template argument not a floating point type");
4866 /** The type of the range of the distribution. */
4867 typedef _RealType result_type;
4868 /** Parameter type. */
4871 typedef piecewise_constant_distribution<_RealType> distribution_type;
4872 friend class piecewise_constant_distribution<_RealType>;
4875 : _M_int(), _M_den(), _M_cp()
4878 template<typename _InputIteratorB, typename _InputIteratorW>
4879 param_type(_InputIteratorB __bfirst,
4880 _InputIteratorB __bend,
4881 _InputIteratorW __wbegin);
4883 template<typename _Func>
4884 param_type(initializer_list<_RealType> __bi, _Func __fw);
4886 template<typename _Func>
4887 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4890 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4891 param_type(const param_type&) = default;
4892 param_type& operator=(const param_type&) = default;
4894 std::vector<_RealType>
4899 std::vector<_RealType> __tmp(2);
4900 __tmp[1] = _RealType(1);
4909 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4912 operator==(const param_type& __p1, const param_type& __p2)
4913 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4919 std::vector<_RealType> _M_int;
4920 std::vector<double> _M_den;
4921 std::vector<double> _M_cp;
4925 piecewise_constant_distribution()
4929 template<typename _InputIteratorB, typename _InputIteratorW>
4930 piecewise_constant_distribution(_InputIteratorB __bfirst,
4931 _InputIteratorB __bend,
4932 _InputIteratorW __wbegin)
4933 : _M_param(__bfirst, __bend, __wbegin)
4936 template<typename _Func>
4937 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4939 : _M_param(__bl, __fw)
4942 template<typename _Func>
4943 piecewise_constant_distribution(size_t __nw,
4944 _RealType __xmin, _RealType __xmax,
4946 : _M_param(__nw, __xmin, __xmax, __fw)
4950 piecewise_constant_distribution(const param_type& __p)
4955 * @brief Resets the distribution state.
4962 * @brief Returns a vector of the intervals.
4964 std::vector<_RealType>
4967 if (_M_param._M_int.empty())
4969 std::vector<_RealType> __tmp(2);
4970 __tmp[1] = _RealType(1);
4974 return _M_param._M_int;
4978 * @brief Returns a vector of the probability densities.
4983 return _M_param._M_den.empty()
4984 ? std::vector<double>(1, 1.0) : _M_param._M_den;
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.
5008 return _M_param._M_int.empty()
5009 ? result_type(0) : _M_param._M_int.front();
5013 * @brief Returns the least upper bound value of the distribution.
5018 return _M_param._M_int.empty()
5019 ? result_type(1) : _M_param._M_int.back();
5023 * @brief Generating functions.
5025 template<typename _UniformRandomNumberGenerator>
5027 operator()(_UniformRandomNumberGenerator& __urng)
5028 { return this->operator()(__urng, _M_param); }
5030 template<typename _UniformRandomNumberGenerator>
5032 operator()(_UniformRandomNumberGenerator& __urng,
5033 const param_type& __p);
5036 * @brief Return true if two piecewise constant distributions have the
5040 operator==(const piecewise_constant_distribution& __d1,
5041 const piecewise_constant_distribution& __d2)
5042 { return __d1._M_param == __d2._M_param; }
5045 * @brief Inserts a %piecewise_constan_distribution random
5046 * number distribution @p __x into the output stream @p __os.
5048 * @param __os An output stream.
5049 * @param __x A %piecewise_constan_distribution random number
5052 * @returns The output stream with the state of @p __x inserted or in
5055 template<typename _RealType1, typename _CharT, typename _Traits>
5056 friend std::basic_ostream<_CharT, _Traits>&
5057 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5058 const std::piecewise_constant_distribution<_RealType1>& __x);
5061 * @brief Extracts a %piecewise_constan_distribution random
5062 * number distribution @p __x from the input stream @p __is.
5064 * @param __is An input stream.
5065 * @param __x A %piecewise_constan_distribution random number
5068 * @returns The input stream with @p __x extracted or in an error
5071 template<typename _RealType1, typename _CharT, typename _Traits>
5072 friend std::basic_istream<_CharT, _Traits>&
5073 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5074 std::piecewise_constant_distribution<_RealType1>& __x);
5077 param_type _M_param;
5081 * @brief Return true if two piecewise constant distributions have
5082 * different parameters.
5084 template<typename _RealType>
5086 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5087 const std::piecewise_constant_distribution<_RealType>& __d2)
5088 { return !(__d1 == __d2); }
5092 * @brief A piecewise_linear_distribution random number distribution.
5094 * The formula for the piecewise linear probability mass function is
5097 template<typename _RealType = double>
5098 class piecewise_linear_distribution
5100 static_assert(std::is_floating_point<_RealType>::value,
5101 "template argument not a floating point type");
5104 /** The type of the range of the distribution. */
5105 typedef _RealType result_type;
5106 /** Parameter type. */
5109 typedef piecewise_linear_distribution<_RealType> distribution_type;
5110 friend class piecewise_linear_distribution<_RealType>;
5113 : _M_int(), _M_den(), _M_cp(), _M_m()
5116 template<typename _InputIteratorB, typename _InputIteratorW>
5117 param_type(_InputIteratorB __bfirst,
5118 _InputIteratorB __bend,
5119 _InputIteratorW __wbegin);
5121 template<typename _Func>
5122 param_type(initializer_list<_RealType> __bl, _Func __fw);
5124 template<typename _Func>
5125 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5128 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5129 param_type(const param_type&) = default;
5130 param_type& operator=(const param_type&) = default;
5132 std::vector<_RealType>
5137 std::vector<_RealType> __tmp(2);
5138 __tmp[1] = _RealType(1);
5147 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5150 operator==(const param_type& __p1, const param_type& __p2)
5151 { return (__p1._M_int == __p2._M_int
5152 && __p1._M_den == __p2._M_den); }
5158 std::vector<_RealType> _M_int;
5159 std::vector<double> _M_den;
5160 std::vector<double> _M_cp;
5161 std::vector<double> _M_m;
5165 piecewise_linear_distribution()
5169 template<typename _InputIteratorB, typename _InputIteratorW>
5170 piecewise_linear_distribution(_InputIteratorB __bfirst,
5171 _InputIteratorB __bend,
5172 _InputIteratorW __wbegin)
5173 : _M_param(__bfirst, __bend, __wbegin)
5176 template<typename _Func>
5177 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5179 : _M_param(__bl, __fw)
5182 template<typename _Func>
5183 piecewise_linear_distribution(size_t __nw,
5184 _RealType __xmin, _RealType __xmax,
5186 : _M_param(__nw, __xmin, __xmax, __fw)
5190 piecewise_linear_distribution(const param_type& __p)
5195 * Resets the distribution state.
5202 * @brief Return the intervals of the distribution.
5204 std::vector<_RealType>
5207 if (_M_param._M_int.empty())
5209 std::vector<_RealType> __tmp(2);
5210 __tmp[1] = _RealType(1);
5214 return _M_param._M_int;
5218 * @brief Return a vector of the probability densities of the
5224 return _M_param._M_den.empty()
5225 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5229 * @brief Returns the parameter set of the distribution.
5233 { return _M_param; }
5236 * @brief Sets the parameter set of the distribution.
5237 * @param __param The new parameter set of the distribution.
5240 param(const param_type& __param)
5241 { _M_param = __param; }
5244 * @brief Returns the greatest lower bound value of the distribution.
5249 return _M_param._M_int.empty()
5250 ? result_type(0) : _M_param._M_int.front();
5254 * @brief Returns the least upper bound value of the distribution.
5259 return _M_param._M_int.empty()
5260 ? result_type(1) : _M_param._M_int.back();
5264 * @brief Generating functions.
5266 template<typename _UniformRandomNumberGenerator>
5268 operator()(_UniformRandomNumberGenerator& __urng)
5269 { return this->operator()(__urng, _M_param); }
5271 template<typename _UniformRandomNumberGenerator>
5273 operator()(_UniformRandomNumberGenerator& __urng,
5274 const param_type& __p);
5277 * @brief Return true if two piecewise linear distributions have the
5281 operator==(const piecewise_linear_distribution& __d1,
5282 const piecewise_linear_distribution& __d2)
5283 { return __d1._M_param == __d2._M_param; }
5286 * @brief Inserts a %piecewise_linear_distribution random number
5287 * distribution @p __x into the output stream @p __os.
5289 * @param __os An output stream.
5290 * @param __x A %piecewise_linear_distribution random number
5293 * @returns The output stream with the state of @p __x inserted or in
5296 template<typename _RealType1, typename _CharT, typename _Traits>
5297 friend std::basic_ostream<_CharT, _Traits>&
5298 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5299 const std::piecewise_linear_distribution<_RealType1>& __x);
5302 * @brief Extracts a %piecewise_linear_distribution random number
5303 * distribution @p __x from the input stream @p __is.
5305 * @param __is An input stream.
5306 * @param __x A %piecewise_linear_distribution random number
5309 * @returns The input stream with @p __x extracted or in an error
5312 template<typename _RealType1, typename _CharT, typename _Traits>
5313 friend std::basic_istream<_CharT, _Traits>&
5314 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5315 std::piecewise_linear_distribution<_RealType1>& __x);
5318 param_type _M_param;
5322 * @brief Return true if two piecewise linear distributions have
5323 * different parameters.
5325 template<typename _RealType>
5327 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5328 const std::piecewise_linear_distribution<_RealType>& __d2)
5329 { return !(__d1 == __d2); }
5332 /* @} */ // group random_distributions_poisson
5334 /* @} */ // group random_distributions
5337 * @addtogroup random_utilities Random Number Utilities
5343 * @brief The seed_seq class generates sequences of seeds for random
5344 * number generators.
5350 /** The type of the seed vales. */
5351 typedef uint_least32_t result_type;
5353 /** Default constructor. */
5358 template<typename _IntType>
5359 seed_seq(std::initializer_list<_IntType> il);
5361 template<typename _InputIterator>
5362 seed_seq(_InputIterator __begin, _InputIterator __end);
5364 // generating functions
5365 template<typename _RandomAccessIterator>
5367 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5369 // property functions
5371 { return _M_v.size(); }
5373 template<typename OutputIterator>
5375 param(OutputIterator __dest) const
5376 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5380 std::vector<result_type> _M_v;
5383 /* @} */ // group random_utilities
5385 /* @} */ // group random
5387 _GLIBCXX_END_NAMESPACE_VERSION