1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 // [26.4] Random number generation
43 * @defgroup random Random Number Generation
46 * A facility for generating random numbers on selected distributions.
51 * @brief A function template for converting the output of a (integral)
52 * uniform random number generator to a floatng point result in the range
55 template<typename _RealType, size_t __bits,
56 typename _UniformRandomNumberGenerator>
58 generate_canonical(_UniformRandomNumberGenerator& __g);
60 _GLIBCXX_END_NAMESPACE_VERSION
63 * Implementation-space details.
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _UIntType, size_t __w,
70 bool = __w < static_cast<size_t>
71 (std::numeric_limits<_UIntType>::digits)>
73 { static const _UIntType __value = 0; };
75 template<typename _UIntType, size_t __w>
76 struct _Shift<_UIntType, __w, true>
77 { static const _UIntType __value = _UIntType(1) << __w; };
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, this->param()); }
1724 template<typename _UniformRandomNumberGenerator>
1726 operator()(_UniformRandomNumberGenerator& __urng,
1727 const param_type& __p);
1729 param_type _M_param;
1733 * @brief Return true if two uniform integer distributions have
1734 * the same parameters.
1736 template<typename _IntType>
1738 operator==(const std::uniform_int_distribution<_IntType>& __d1,
1739 const std::uniform_int_distribution<_IntType>& __d2)
1740 { return __d1.param() == __d2.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, this->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 param_type _M_param;
1914 * @brief Return true if two uniform real distributions have
1915 * the same parameters.
1917 template<typename _IntType>
1919 operator==(const std::uniform_real_distribution<_IntType>& __d1,
1920 const std::uniform_real_distribution<_IntType>& __d2)
1921 { return __d1.param() == __d2.param(); }
1924 * @brief Return true if two uniform real distributions have
1925 * different parameters.
1927 template<typename _IntType>
1929 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1930 const std::uniform_real_distribution<_IntType>& __d2)
1931 { return !(__d1 == __d2); }
1934 * @brief Inserts a %uniform_real_distribution random number
1935 * distribution @p __x into the output stream @p __os.
1937 * @param __os An output stream.
1938 * @param __x A %uniform_real_distribution random number distribution.
1940 * @returns The output stream with the state of @p __x inserted or in
1943 template<typename _RealType, typename _CharT, typename _Traits>
1944 std::basic_ostream<_CharT, _Traits>&
1945 operator<<(std::basic_ostream<_CharT, _Traits>&,
1946 const std::uniform_real_distribution<_RealType>&);
1949 * @brief Extracts a %uniform_real_distribution random number distribution
1950 * @p __x from the input stream @p __is.
1952 * @param __is An input stream.
1953 * @param __x A %uniform_real_distribution random number generator engine.
1955 * @returns The input stream with @p __x extracted or in an error state.
1957 template<typename _RealType, typename _CharT, typename _Traits>
1958 std::basic_istream<_CharT, _Traits>&
1959 operator>>(std::basic_istream<_CharT, _Traits>&,
1960 std::uniform_real_distribution<_RealType>&);
1962 /* @} */ // group random_distributions_uniform
1965 * @addtogroup random_distributions_normal Normal Distributions
1966 * @ingroup random_distributions
1971 * @brief A normal continuous distribution for random numbers.
1973 * The formula for the normal probability density function is
1975 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1976 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1979 template<typename _RealType = double>
1980 class normal_distribution
1982 static_assert(std::is_floating_point<_RealType>::value,
1983 "template argument not a floating point type");
1986 /** The type of the range of the distribution. */
1987 typedef _RealType result_type;
1988 /** Parameter type. */
1991 typedef normal_distribution<_RealType> distribution_type;
1994 param_type(_RealType __mean = _RealType(0),
1995 _RealType __stddev = _RealType(1))
1996 : _M_mean(__mean), _M_stddev(__stddev)
1998 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
2007 { return _M_stddev; }
2010 operator==(const param_type& __p1, const param_type& __p2)
2011 { return (__p1._M_mean == __p2._M_mean
2012 && __p1._M_stddev == __p2._M_stddev); }
2016 _RealType _M_stddev;
2021 * Constructs a normal distribution with parameters @f$mean@f$ and
2022 * standard deviation.
2025 normal_distribution(result_type __mean = result_type(0),
2026 result_type __stddev = result_type(1))
2027 : _M_param(__mean, __stddev), _M_saved_available(false)
2031 normal_distribution(const param_type& __p)
2032 : _M_param(__p), _M_saved_available(false)
2036 * @brief Resets the distribution state.
2040 { _M_saved_available = false; }
2043 * @brief Returns the mean of the distribution.
2047 { return _M_param.mean(); }
2050 * @brief Returns the standard deviation of the distribution.
2054 { return _M_param.stddev(); }
2057 * @brief Returns the parameter set of the distribution.
2061 { return _M_param; }
2064 * @brief Sets the parameter set of the distribution.
2065 * @param __param The new parameter set of the distribution.
2068 param(const param_type& __param)
2069 { _M_param = __param; }
2072 * @brief Returns the greatest lower bound value of the distribution.
2076 { return std::numeric_limits<result_type>::min(); }
2079 * @brief Returns the least upper bound value of the distribution.
2083 { return std::numeric_limits<result_type>::max(); }
2086 * @brief Generating functions.
2088 template<typename _UniformRandomNumberGenerator>
2090 operator()(_UniformRandomNumberGenerator& __urng)
2091 { return this->operator()(__urng, this->param()); }
2093 template<typename _UniformRandomNumberGenerator>
2095 operator()(_UniformRandomNumberGenerator& __urng,
2096 const param_type& __p);
2099 * @brief Return true if two normal distributions have
2100 * the same parameters and the sequences that would
2101 * be generated are equal.
2103 template<typename _RealType1>
2105 operator==(const std::normal_distribution<_RealType1>& __d1,
2106 const std::normal_distribution<_RealType1>& __d2);
2109 * @brief Inserts a %normal_distribution random number distribution
2110 * @p __x into the output stream @p __os.
2112 * @param __os An output stream.
2113 * @param __x A %normal_distribution random number distribution.
2115 * @returns The output stream with the state of @p __x inserted or in
2118 template<typename _RealType1, typename _CharT, typename _Traits>
2119 friend std::basic_ostream<_CharT, _Traits>&
2120 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2121 const std::normal_distribution<_RealType1>& __x);
2124 * @brief Extracts a %normal_distribution random number distribution
2125 * @p __x from the input stream @p __is.
2127 * @param __is An input stream.
2128 * @param __x A %normal_distribution random number generator engine.
2130 * @returns The input stream with @p __x extracted or in an error
2133 template<typename _RealType1, typename _CharT, typename _Traits>
2134 friend std::basic_istream<_CharT, _Traits>&
2135 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2136 std::normal_distribution<_RealType1>& __x);
2139 param_type _M_param;
2140 result_type _M_saved;
2141 bool _M_saved_available;
2145 * @brief Return true if two normal distributions are different.
2147 template<typename _RealType>
2149 operator!=(const std::normal_distribution<_RealType>& __d1,
2150 const std::normal_distribution<_RealType>& __d2)
2151 { return !(__d1 == __d2); }
2155 * @brief A lognormal_distribution random number distribution.
2157 * The formula for the normal probability mass function is
2159 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2160 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2163 template<typename _RealType = double>
2164 class lognormal_distribution
2166 static_assert(std::is_floating_point<_RealType>::value,
2167 "template argument not a floating point type");
2170 /** The type of the range of the distribution. */
2171 typedef _RealType result_type;
2172 /** Parameter type. */
2175 typedef lognormal_distribution<_RealType> distribution_type;
2178 param_type(_RealType __m = _RealType(0),
2179 _RealType __s = _RealType(1))
2180 : _M_m(__m), _M_s(__s)
2192 operator==(const param_type& __p1, const param_type& __p2)
2193 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2201 lognormal_distribution(_RealType __m = _RealType(0),
2202 _RealType __s = _RealType(1))
2203 : _M_param(__m, __s), _M_nd()
2207 lognormal_distribution(const param_type& __p)
2208 : _M_param(__p), _M_nd()
2212 * Resets the distribution state.
2223 { return _M_param.m(); }
2227 { return _M_param.s(); }
2230 * @brief Returns the parameter set of the distribution.
2234 { return _M_param; }
2237 * @brief Sets the parameter set of the distribution.
2238 * @param __param The new parameter set of the distribution.
2241 param(const param_type& __param)
2242 { _M_param = __param; }
2245 * @brief Returns the greatest lower bound value of the distribution.
2249 { return result_type(0); }
2252 * @brief Returns the least upper bound value of the distribution.
2256 { return std::numeric_limits<result_type>::max(); }
2259 * @brief Generating functions.
2261 template<typename _UniformRandomNumberGenerator>
2263 operator()(_UniformRandomNumberGenerator& __urng)
2264 { return this->operator()(__urng, this->param()); }
2266 template<typename _UniformRandomNumberGenerator>
2268 operator()(_UniformRandomNumberGenerator& __urng,
2269 const param_type& __p)
2270 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2273 * @brief Return true if two lognormal distributions have
2274 * the same parameters and the sequences that would
2275 * be generated are equal.
2278 operator==(const lognormal_distribution& __d1,
2279 const lognormal_distribution& __d2)
2280 { return (__d1.param() == __d2.param()
2281 && __d1._M_nd == __d2._M_nd); }
2284 * @brief Inserts a %lognormal_distribution random number distribution
2285 * @p __x into the output stream @p __os.
2287 * @param __os An output stream.
2288 * @param __x A %lognormal_distribution random number distribution.
2290 * @returns The output stream with the state of @p __x inserted or in
2293 template<typename _RealType1, typename _CharT, typename _Traits>
2294 friend std::basic_ostream<_CharT, _Traits>&
2295 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2296 const std::lognormal_distribution<_RealType1>& __x);
2299 * @brief Extracts a %lognormal_distribution random number distribution
2300 * @p __x from the input stream @p __is.
2302 * @param __is An input stream.
2303 * @param __x A %lognormal_distribution random number
2306 * @returns The input stream with @p __x extracted or in an error state.
2308 template<typename _RealType1, typename _CharT, typename _Traits>
2309 friend std::basic_istream<_CharT, _Traits>&
2310 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2311 std::lognormal_distribution<_RealType1>& __x);
2314 param_type _M_param;
2316 std::normal_distribution<result_type> _M_nd;
2320 * @brief Return true if two lognormal distributions are different.
2322 template<typename _RealType>
2324 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2325 const std::lognormal_distribution<_RealType>& __d2)
2326 { return !(__d1 == __d2); }
2330 * @brief A gamma continuous distribution for random numbers.
2332 * The formula for the gamma probability density function is:
2334 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2335 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2338 template<typename _RealType = double>
2339 class gamma_distribution
2341 static_assert(std::is_floating_point<_RealType>::value,
2342 "template argument not a floating point type");
2345 /** The type of the range of the distribution. */
2346 typedef _RealType result_type;
2347 /** Parameter type. */
2350 typedef gamma_distribution<_RealType> distribution_type;
2351 friend class gamma_distribution<_RealType>;
2354 param_type(_RealType __alpha_val = _RealType(1),
2355 _RealType __beta_val = _RealType(1))
2356 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2358 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2364 { return _M_alpha; }
2371 operator==(const param_type& __p1, const param_type& __p2)
2372 { return (__p1._M_alpha == __p2._M_alpha
2373 && __p1._M_beta == __p2._M_beta); }
2382 _RealType _M_malpha, _M_a2;
2387 * @brief Constructs a gamma distribution with parameters
2388 * @f$\alpha@f$ and @f$\beta@f$.
2391 gamma_distribution(_RealType __alpha_val = _RealType(1),
2392 _RealType __beta_val = _RealType(1))
2393 : _M_param(__alpha_val, __beta_val), _M_nd()
2397 gamma_distribution(const param_type& __p)
2398 : _M_param(__p), _M_nd()
2402 * @brief Resets the distribution state.
2409 * @brief Returns the @f$\alpha@f$ of the distribution.
2413 { return _M_param.alpha(); }
2416 * @brief Returns the @f$\beta@f$ of the distribution.
2420 { return _M_param.beta(); }
2423 * @brief Returns the parameter set of the distribution.
2427 { return _M_param; }
2430 * @brief Sets the parameter set of the distribution.
2431 * @param __param The new parameter set of the distribution.
2434 param(const param_type& __param)
2435 { _M_param = __param; }
2438 * @brief Returns the greatest lower bound value of the distribution.
2442 { return result_type(0); }
2445 * @brief Returns the least upper bound value of the distribution.
2449 { return std::numeric_limits<result_type>::max(); }
2452 * @brief Generating functions.
2454 template<typename _UniformRandomNumberGenerator>
2456 operator()(_UniformRandomNumberGenerator& __urng)
2457 { return this->operator()(__urng, this->param()); }
2459 template<typename _UniformRandomNumberGenerator>
2461 operator()(_UniformRandomNumberGenerator& __urng,
2462 const param_type& __p);
2465 * @brief Return true if two gamma distributions have the same
2466 * parameters and the sequences that would be generated
2470 operator==(const gamma_distribution& __d1,
2471 const gamma_distribution& __d2)
2472 { return (__d1.param() == __d2.param()
2473 && __d1._M_nd == __d2._M_nd); }
2476 * @brief Inserts a %gamma_distribution random number distribution
2477 * @p __x into the output stream @p __os.
2479 * @param __os An output stream.
2480 * @param __x A %gamma_distribution random number distribution.
2482 * @returns The output stream with the state of @p __x inserted or in
2485 template<typename _RealType1, typename _CharT, typename _Traits>
2486 friend std::basic_ostream<_CharT, _Traits>&
2487 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2488 const std::gamma_distribution<_RealType1>& __x);
2491 * @brief Extracts a %gamma_distribution random number distribution
2492 * @p __x from the input stream @p __is.
2494 * @param __is An input stream.
2495 * @param __x A %gamma_distribution random number generator engine.
2497 * @returns The input stream with @p __x extracted or in an error state.
2499 template<typename _RealType1, typename _CharT, typename _Traits>
2500 friend std::basic_istream<_CharT, _Traits>&
2501 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2502 std::gamma_distribution<_RealType1>& __x);
2505 param_type _M_param;
2507 std::normal_distribution<result_type> _M_nd;
2511 * @brief Return true if two gamma distributions are different.
2513 template<typename _RealType>
2515 operator!=(const std::gamma_distribution<_RealType>& __d1,
2516 const std::gamma_distribution<_RealType>& __d2)
2517 { return !(__d1 == __d2); }
2521 * @brief A chi_squared_distribution random number distribution.
2523 * The formula for the normal probability mass function is
2524 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2526 template<typename _RealType = double>
2527 class chi_squared_distribution
2529 static_assert(std::is_floating_point<_RealType>::value,
2530 "template argument not a floating point type");
2533 /** The type of the range of the distribution. */
2534 typedef _RealType result_type;
2535 /** Parameter type. */
2538 typedef chi_squared_distribution<_RealType> distribution_type;
2541 param_type(_RealType __n = _RealType(1))
2550 operator==(const param_type& __p1, const param_type& __p2)
2551 { return __p1._M_n == __p2._M_n; }
2558 chi_squared_distribution(_RealType __n = _RealType(1))
2559 : _M_param(__n), _M_gd(__n / 2)
2563 chi_squared_distribution(const param_type& __p)
2564 : _M_param(__p), _M_gd(__p.n() / 2)
2568 * @brief Resets the distribution state.
2579 { return _M_param.n(); }
2582 * @brief Returns the parameter set of the distribution.
2586 { return _M_param; }
2589 * @brief Sets the parameter set of the distribution.
2590 * @param __param The new parameter set of the distribution.
2593 param(const param_type& __param)
2594 { _M_param = __param; }
2597 * @brief Returns the greatest lower bound value of the distribution.
2601 { return result_type(0); }
2604 * @brief Returns the least upper bound value of the distribution.
2608 { return std::numeric_limits<result_type>::max(); }
2611 * @brief Generating functions.
2613 template<typename _UniformRandomNumberGenerator>
2615 operator()(_UniformRandomNumberGenerator& __urng)
2616 { return 2 * _M_gd(__urng); }
2618 template<typename _UniformRandomNumberGenerator>
2620 operator()(_UniformRandomNumberGenerator& __urng,
2621 const param_type& __p)
2623 typedef typename std::gamma_distribution<result_type>::param_type
2625 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2629 * @brief Return true if two Chi-squared distributions have
2630 * the same parameters and the sequences that would be
2631 * generated are equal.
2634 operator==(const chi_squared_distribution& __d1,
2635 const chi_squared_distribution& __d2)
2636 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2639 * @brief Inserts a %chi_squared_distribution random number distribution
2640 * @p __x into the output stream @p __os.
2642 * @param __os An output stream.
2643 * @param __x A %chi_squared_distribution random number distribution.
2645 * @returns The output stream with the state of @p __x inserted or in
2648 template<typename _RealType1, typename _CharT, typename _Traits>
2649 friend std::basic_ostream<_CharT, _Traits>&
2650 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2651 const std::chi_squared_distribution<_RealType1>& __x);
2654 * @brief Extracts a %chi_squared_distribution random number distribution
2655 * @p __x from the input stream @p __is.
2657 * @param __is An input stream.
2658 * @param __x A %chi_squared_distribution random number
2661 * @returns The input stream with @p __x extracted or in an error state.
2663 template<typename _RealType1, typename _CharT, typename _Traits>
2664 friend std::basic_istream<_CharT, _Traits>&
2665 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2666 std::chi_squared_distribution<_RealType1>& __x);
2669 param_type _M_param;
2671 std::gamma_distribution<result_type> _M_gd;
2675 * @brief Return true if two Chi-squared distributions are different.
2677 template<typename _RealType>
2679 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2680 const std::chi_squared_distribution<_RealType>& __d2)
2681 { return !(__d1 == __d2); }
2685 * @brief A cauchy_distribution random number distribution.
2687 * The formula for the normal probability mass function is
2688 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2690 template<typename _RealType = double>
2691 class cauchy_distribution
2693 static_assert(std::is_floating_point<_RealType>::value,
2694 "template argument not a floating point type");
2697 /** The type of the range of the distribution. */
2698 typedef _RealType result_type;
2699 /** Parameter type. */
2702 typedef cauchy_distribution<_RealType> distribution_type;
2705 param_type(_RealType __a = _RealType(0),
2706 _RealType __b = _RealType(1))
2707 : _M_a(__a), _M_b(__b)
2719 operator==(const param_type& __p1, const param_type& __p2)
2720 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2728 cauchy_distribution(_RealType __a = _RealType(0),
2729 _RealType __b = _RealType(1))
2730 : _M_param(__a, __b)
2734 cauchy_distribution(const param_type& __p)
2739 * @brief Resets the distribution state.
2750 { return _M_param.a(); }
2754 { return _M_param.b(); }
2757 * @brief Returns the parameter set of the distribution.
2761 { return _M_param; }
2764 * @brief Sets the parameter set of the distribution.
2765 * @param __param The new parameter set of the distribution.
2768 param(const param_type& __param)
2769 { _M_param = __param; }
2772 * @brief Returns the greatest lower bound value of the distribution.
2776 { return std::numeric_limits<result_type>::min(); }
2779 * @brief Returns the least upper bound value of the distribution.
2783 { return std::numeric_limits<result_type>::max(); }
2786 * @brief Generating functions.
2788 template<typename _UniformRandomNumberGenerator>
2790 operator()(_UniformRandomNumberGenerator& __urng)
2791 { return this->operator()(__urng, this->param()); }
2793 template<typename _UniformRandomNumberGenerator>
2795 operator()(_UniformRandomNumberGenerator& __urng,
2796 const param_type& __p);
2799 param_type _M_param;
2803 * @brief Return true if two Cauchy distributions have
2804 * the same parameters.
2806 template<typename _RealType>
2808 operator==(const std::cauchy_distribution<_RealType>& __d1,
2809 const std::cauchy_distribution<_RealType>& __d2)
2810 { return __d1.param() == __d2.param(); }
2813 * @brief Return true if two Cauchy distributions have
2814 * different parameters.
2816 template<typename _RealType>
2818 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2819 const std::cauchy_distribution<_RealType>& __d2)
2820 { return !(__d1 == __d2); }
2823 * @brief Inserts a %cauchy_distribution random number distribution
2824 * @p __x into the output stream @p __os.
2826 * @param __os An output stream.
2827 * @param __x A %cauchy_distribution random number distribution.
2829 * @returns The output stream with the state of @p __x inserted or in
2832 template<typename _RealType, typename _CharT, typename _Traits>
2833 std::basic_ostream<_CharT, _Traits>&
2834 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2835 const std::cauchy_distribution<_RealType>& __x);
2838 * @brief Extracts a %cauchy_distribution random number distribution
2839 * @p __x from the input stream @p __is.
2841 * @param __is An input stream.
2842 * @param __x A %cauchy_distribution random number
2845 * @returns The input stream with @p __x extracted or in an error state.
2847 template<typename _RealType, typename _CharT, typename _Traits>
2848 std::basic_istream<_CharT, _Traits>&
2849 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2850 std::cauchy_distribution<_RealType>& __x);
2854 * @brief A fisher_f_distribution random number distribution.
2856 * The formula for the normal probability mass function is
2858 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2859 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2860 * (1 + \frac{mx}{n})^{-(m+n)/2}
2863 template<typename _RealType = double>
2864 class fisher_f_distribution
2866 static_assert(std::is_floating_point<_RealType>::value,
2867 "template argument not a floating point type");
2870 /** The type of the range of the distribution. */
2871 typedef _RealType result_type;
2872 /** Parameter type. */
2875 typedef fisher_f_distribution<_RealType> distribution_type;
2878 param_type(_RealType __m = _RealType(1),
2879 _RealType __n = _RealType(1))
2880 : _M_m(__m), _M_n(__n)
2892 operator==(const param_type& __p1, const param_type& __p2)
2893 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2901 fisher_f_distribution(_RealType __m = _RealType(1),
2902 _RealType __n = _RealType(1))
2903 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2907 fisher_f_distribution(const param_type& __p)
2908 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2912 * @brief Resets the distribution state.
2926 { return _M_param.m(); }
2930 { return _M_param.n(); }
2933 * @brief Returns the parameter set of the distribution.
2937 { return _M_param; }
2940 * @brief Sets the parameter set of the distribution.
2941 * @param __param The new parameter set of the distribution.
2944 param(const param_type& __param)
2945 { _M_param = __param; }
2948 * @brief Returns the greatest lower bound value of the distribution.
2952 { return result_type(0); }
2955 * @brief Returns the least upper bound value of the distribution.
2959 { return std::numeric_limits<result_type>::max(); }
2962 * @brief Generating functions.
2964 template<typename _UniformRandomNumberGenerator>
2966 operator()(_UniformRandomNumberGenerator& __urng)
2967 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2969 template<typename _UniformRandomNumberGenerator>
2971 operator()(_UniformRandomNumberGenerator& __urng,
2972 const param_type& __p)
2974 typedef typename std::gamma_distribution<result_type>::param_type
2976 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2977 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2981 * @brief Return true if two Fisher f distributions have
2982 * the same parameters and the sequences that would
2983 * be generated are equal.
2986 operator==(const fisher_f_distribution& __d1,
2987 const fisher_f_distribution& __d2)
2988 { return (__d1.param() == __d2.param()
2989 && __d1._M_gd_x == __d2._M_gd_x
2990 && __d1._M_gd_y == __d2._M_gd_y); }
2993 * @brief Inserts a %fisher_f_distribution random number distribution
2994 * @p __x into the output stream @p __os.
2996 * @param __os An output stream.
2997 * @param __x A %fisher_f_distribution random number distribution.
2999 * @returns The output stream with the state of @p __x inserted or in
3002 template<typename _RealType1, typename _CharT, typename _Traits>
3003 friend std::basic_ostream<_CharT, _Traits>&
3004 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3005 const std::fisher_f_distribution<_RealType1>& __x);
3008 * @brief Extracts a %fisher_f_distribution random number distribution
3009 * @p __x from the input stream @p __is.
3011 * @param __is An input stream.
3012 * @param __x A %fisher_f_distribution random number
3015 * @returns The input stream with @p __x extracted or in an error state.
3017 template<typename _RealType1, typename _CharT, typename _Traits>
3018 friend std::basic_istream<_CharT, _Traits>&
3019 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3020 std::fisher_f_distribution<_RealType1>& __x);
3023 param_type _M_param;
3025 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3029 * @brief Return true if two Fisher f distributions are diferent.
3031 template<typename _RealType>
3033 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3034 const std::fisher_f_distribution<_RealType>& __d2)
3035 { return !(__d1 == __d2); }
3038 * @brief A student_t_distribution random number distribution.
3040 * The formula for the normal probability mass function is:
3042 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3043 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3046 template<typename _RealType = double>
3047 class student_t_distribution
3049 static_assert(std::is_floating_point<_RealType>::value,
3050 "template argument not a floating point type");
3053 /** The type of the range of the distribution. */
3054 typedef _RealType result_type;
3055 /** Parameter type. */
3058 typedef student_t_distribution<_RealType> distribution_type;
3061 param_type(_RealType __n = _RealType(1))
3070 operator==(const param_type& __p1, const param_type& __p2)
3071 { return __p1._M_n == __p2._M_n; }
3078 student_t_distribution(_RealType __n = _RealType(1))
3079 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3083 student_t_distribution(const param_type& __p)
3084 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3088 * @brief Resets the distribution state.
3102 { return _M_param.n(); }
3105 * @brief Returns the parameter set of the distribution.
3109 { return _M_param; }
3112 * @brief Sets the parameter set of the distribution.
3113 * @param __param The new parameter set of the distribution.
3116 param(const param_type& __param)
3117 { _M_param = __param; }
3120 * @brief Returns the greatest lower bound value of the distribution.
3124 { return std::numeric_limits<result_type>::min(); }
3127 * @brief Returns the least upper bound value of the distribution.
3131 { return std::numeric_limits<result_type>::max(); }
3134 * @brief Generating functions.
3136 template<typename _UniformRandomNumberGenerator>
3138 operator()(_UniformRandomNumberGenerator& __urng)
3139 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3141 template<typename _UniformRandomNumberGenerator>
3143 operator()(_UniformRandomNumberGenerator& __urng,
3144 const param_type& __p)
3146 typedef typename std::gamma_distribution<result_type>::param_type
3149 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3150 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3154 * @brief Return true if two Student t distributions have
3155 * the same parameters and the sequences that would
3156 * be generated are equal.
3159 operator==(const student_t_distribution& __d1,
3160 const student_t_distribution& __d2)
3161 { return (__d1.param() == __d2.param()
3162 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3165 * @brief Inserts a %student_t_distribution random number distribution
3166 * @p __x into the output stream @p __os.
3168 * @param __os An output stream.
3169 * @param __x A %student_t_distribution random number distribution.
3171 * @returns The output stream with the state of @p __x inserted or in
3174 template<typename _RealType1, typename _CharT, typename _Traits>
3175 friend std::basic_ostream<_CharT, _Traits>&
3176 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3177 const std::student_t_distribution<_RealType1>& __x);
3180 * @brief Extracts a %student_t_distribution random number distribution
3181 * @p __x from the input stream @p __is.
3183 * @param __is An input stream.
3184 * @param __x A %student_t_distribution random number
3187 * @returns The input stream with @p __x extracted or in an error state.
3189 template<typename _RealType1, typename _CharT, typename _Traits>
3190 friend std::basic_istream<_CharT, _Traits>&
3191 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3192 std::student_t_distribution<_RealType1>& __x);
3195 param_type _M_param;
3197 std::normal_distribution<result_type> _M_nd;
3198 std::gamma_distribution<result_type> _M_gd;
3202 * @brief Return true if two Student t distributions are different.
3204 template<typename _RealType>
3206 operator!=(const std::student_t_distribution<_RealType>& __d1,
3207 const std::student_t_distribution<_RealType>& __d2)
3208 { return !(__d1 == __d2); }
3211 /* @} */ // group random_distributions_normal
3214 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3215 * @ingroup random_distributions
3220 * @brief A Bernoulli random number distribution.
3222 * Generates a sequence of true and false values with likelihood @f$p@f$
3223 * that true will come up and @f$(1 - p)@f$ that false will appear.
3225 class bernoulli_distribution
3228 /** The type of the range of the distribution. */
3229 typedef bool result_type;
3230 /** Parameter type. */
3233 typedef bernoulli_distribution distribution_type;
3236 param_type(double __p = 0.5)
3239 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3247 operator==(const param_type& __p1, const param_type& __p2)
3248 { return __p1._M_p == __p2._M_p; }
3256 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3258 * @param __p [IN] The likelihood of a true result being returned.
3259 * Must be in the interval @f$[0, 1]@f$.
3262 bernoulli_distribution(double __p = 0.5)
3267 bernoulli_distribution(const param_type& __p)
3272 * @brief Resets the distribution state.
3274 * Does nothing for a Bernoulli distribution.
3280 * @brief Returns the @p p parameter of the distribution.
3284 { return _M_param.p(); }
3287 * @brief Returns the parameter set of the distribution.
3291 { return _M_param; }
3294 * @brief Sets the parameter set of the distribution.
3295 * @param __param The new parameter set of the distribution.
3298 param(const param_type& __param)
3299 { _M_param = __param; }
3302 * @brief Returns the greatest lower bound value of the distribution.
3306 { return std::numeric_limits<result_type>::min(); }
3309 * @brief Returns the least upper bound value of the distribution.
3313 { return std::numeric_limits<result_type>::max(); }
3316 * @brief Generating functions.
3318 template<typename _UniformRandomNumberGenerator>
3320 operator()(_UniformRandomNumberGenerator& __urng)
3321 { return this->operator()(__urng, this->param()); }
3323 template<typename _UniformRandomNumberGenerator>
3325 operator()(_UniformRandomNumberGenerator& __urng,
3326 const param_type& __p)
3328 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3330 if ((__aurng() - __aurng.min())
3331 < __p.p() * (__aurng.max() - __aurng.min()))
3337 param_type _M_param;
3341 * @brief Return true if two Bernoulli distributions have
3342 * the same parameters.
3345 operator==(const std::bernoulli_distribution& __d1,
3346 const std::bernoulli_distribution& __d2)
3347 { return __d1.param() == __d2.param(); }
3350 * @brief Return true if two Bernoulli distributions have
3351 * different parameters.
3354 operator!=(const std::bernoulli_distribution& __d1,
3355 const std::bernoulli_distribution& __d2)
3356 { return !(__d1 == __d2); }
3359 * @brief Inserts a %bernoulli_distribution random number distribution
3360 * @p __x into the output stream @p __os.
3362 * @param __os An output stream.
3363 * @param __x A %bernoulli_distribution random number distribution.
3365 * @returns The output stream with the state of @p __x inserted or in
3368 template<typename _CharT, typename _Traits>
3369 std::basic_ostream<_CharT, _Traits>&
3370 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3371 const std::bernoulli_distribution& __x);
3374 * @brief Extracts a %bernoulli_distribution random number distribution
3375 * @p __x from the input stream @p __is.
3377 * @param __is An input stream.
3378 * @param __x A %bernoulli_distribution random number generator engine.
3380 * @returns The input stream with @p __x extracted or in an error state.
3382 template<typename _CharT, typename _Traits>
3383 std::basic_istream<_CharT, _Traits>&
3384 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3385 std::bernoulli_distribution& __x)
3389 __x.param(bernoulli_distribution::param_type(__p));
3395 * @brief A discrete binomial random number distribution.
3397 * The formula for the binomial probability density function is
3398 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3399 * and @f$p@f$ are the parameters of the distribution.
3401 template<typename _IntType = int>
3402 class binomial_distribution
3404 static_assert(std::is_integral<_IntType>::value,
3405 "template argument not an integral type");
3408 /** The type of the range of the distribution. */
3409 typedef _IntType result_type;
3410 /** Parameter type. */
3413 typedef binomial_distribution<_IntType> distribution_type;
3414 friend class binomial_distribution<_IntType>;
3417 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3418 : _M_t(__t), _M_p(__p)
3420 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3435 operator==(const param_type& __p1, const param_type& __p2)
3436 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3446 #if _GLIBCXX_USE_C99_MATH_TR1
3447 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3448 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3453 // constructors and member function
3455 binomial_distribution(_IntType __t = _IntType(1),
3457 : _M_param(__t, __p), _M_nd()
3461 binomial_distribution(const param_type& __p)
3462 : _M_param(__p), _M_nd()
3466 * @brief Resets the distribution state.
3473 * @brief Returns the distribution @p t parameter.
3477 { return _M_param.t(); }
3480 * @brief Returns the distribution @p p parameter.
3484 { return _M_param.p(); }
3487 * @brief Returns the parameter set of the distribution.
3491 { return _M_param; }
3494 * @brief Sets the parameter set of the distribution.
3495 * @param __param The new parameter set of the distribution.
3498 param(const param_type& __param)
3499 { _M_param = __param; }
3502 * @brief Returns the greatest lower bound value of the distribution.
3509 * @brief Returns the least upper bound value of the distribution.
3513 { return _M_param.t(); }
3516 * @brief Generating functions.
3518 template<typename _UniformRandomNumberGenerator>
3520 operator()(_UniformRandomNumberGenerator& __urng)
3521 { return this->operator()(__urng, this->param()); }
3523 template<typename _UniformRandomNumberGenerator>
3525 operator()(_UniformRandomNumberGenerator& __urng,
3526 const param_type& __p);
3529 * @brief Return true if two binomial distributions have
3530 * the same parameters and the sequences that would
3531 * be generated are equal.
3534 operator==(const binomial_distribution& __d1,
3535 const binomial_distribution& __d2)
3536 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3537 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3539 { return __d1.param() == __d2.param(); }
3543 * @brief Inserts a %binomial_distribution random number distribution
3544 * @p __x into the output stream @p __os.
3546 * @param __os An output stream.
3547 * @param __x A %binomial_distribution random number distribution.
3549 * @returns The output stream with the state of @p __x inserted or in
3552 template<typename _IntType1,
3553 typename _CharT, typename _Traits>
3554 friend std::basic_ostream<_CharT, _Traits>&
3555 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3556 const std::binomial_distribution<_IntType1>& __x);
3559 * @brief Extracts a %binomial_distribution random number distribution
3560 * @p __x from the input stream @p __is.
3562 * @param __is An input stream.
3563 * @param __x A %binomial_distribution random number generator engine.
3565 * @returns The input stream with @p __x extracted or in an error
3568 template<typename _IntType1,
3569 typename _CharT, typename _Traits>
3570 friend std::basic_istream<_CharT, _Traits>&
3571 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3572 std::binomial_distribution<_IntType1>& __x);
3575 template<typename _UniformRandomNumberGenerator>
3577 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3579 param_type _M_param;
3581 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3582 std::normal_distribution<double> _M_nd;
3586 * @brief Return true if two binomial distributions are different.
3588 template<typename _IntType>
3590 operator!=(const std::binomial_distribution<_IntType>& __d1,
3591 const std::binomial_distribution<_IntType>& __d2)
3592 { return !(__d1 == __d2); }
3596 * @brief A discrete geometric random number distribution.
3598 * The formula for the geometric probability density function is
3599 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3602 template<typename _IntType = int>
3603 class geometric_distribution
3605 static_assert(std::is_integral<_IntType>::value,
3606 "template argument not an integral type");
3609 /** The type of the range of the distribution. */
3610 typedef _IntType result_type;
3611 /** Parameter type. */
3614 typedef geometric_distribution<_IntType> distribution_type;
3615 friend class geometric_distribution<_IntType>;
3618 param_type(double __p = 0.5)
3621 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
3630 operator==(const param_type& __p1, const param_type& __p2)
3631 { return __p1._M_p == __p2._M_p; }
3636 { _M_log_1_p = std::log(1.0 - _M_p); }
3643 // constructors and member function
3645 geometric_distribution(double __p = 0.5)
3650 geometric_distribution(const param_type& __p)
3655 * @brief Resets the distribution state.
3657 * Does nothing for the geometric distribution.
3663 * @brief Returns the distribution parameter @p p.
3667 { return _M_param.p(); }
3670 * @brief Returns the parameter set of the distribution.
3674 { return _M_param; }
3677 * @brief Sets the parameter set of the distribution.
3678 * @param __param The new parameter set of the distribution.
3681 param(const param_type& __param)
3682 { _M_param = __param; }
3685 * @brief Returns the greatest lower bound value of the distribution.
3692 * @brief Returns the least upper bound value of the distribution.
3696 { return std::numeric_limits<result_type>::max(); }
3699 * @brief Generating functions.
3701 template<typename _UniformRandomNumberGenerator>
3703 operator()(_UniformRandomNumberGenerator& __urng)
3704 { return this->operator()(__urng, this->param()); }
3706 template<typename _UniformRandomNumberGenerator>
3708 operator()(_UniformRandomNumberGenerator& __urng,
3709 const param_type& __p);
3712 param_type _M_param;
3716 * @brief Return true if two geometric distributions have
3717 * the same parameters.
3719 template<typename _IntType>
3721 operator==(const std::geometric_distribution<_IntType>& __d1,
3722 const std::geometric_distribution<_IntType>& __d2)
3723 { return __d1.param() == __d2.param(); }
3726 * @brief Return true if two geometric distributions have
3727 * different parameters.
3729 template<typename _IntType>
3731 operator!=(const std::geometric_distribution<_IntType>& __d1,
3732 const std::geometric_distribution<_IntType>& __d2)
3733 { return !(__d1 == __d2); }
3736 * @brief Inserts a %geometric_distribution random number distribution
3737 * @p __x into the output stream @p __os.
3739 * @param __os An output stream.
3740 * @param __x A %geometric_distribution random number distribution.
3742 * @returns The output stream with the state of @p __x inserted or in
3745 template<typename _IntType,
3746 typename _CharT, typename _Traits>
3747 std::basic_ostream<_CharT, _Traits>&
3748 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3749 const std::geometric_distribution<_IntType>& __x);
3752 * @brief Extracts a %geometric_distribution random number distribution
3753 * @p __x from the input stream @p __is.
3755 * @param __is An input stream.
3756 * @param __x A %geometric_distribution random number generator engine.
3758 * @returns The input stream with @p __x extracted or in an error state.
3760 template<typename _IntType,
3761 typename _CharT, typename _Traits>
3762 std::basic_istream<_CharT, _Traits>&
3763 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3764 std::geometric_distribution<_IntType>& __x);
3768 * @brief A negative_binomial_distribution random number distribution.
3770 * The formula for the negative binomial probability mass function is
3771 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3772 * and @f$p@f$ are the parameters of the distribution.
3774 template<typename _IntType = int>
3775 class negative_binomial_distribution
3777 static_assert(std::is_integral<_IntType>::value,
3778 "template argument not an integral type");
3781 /** The type of the range of the distribution. */
3782 typedef _IntType result_type;
3783 /** Parameter type. */
3786 typedef negative_binomial_distribution<_IntType> distribution_type;
3789 param_type(_IntType __k = 1, double __p = 0.5)
3790 : _M_k(__k), _M_p(__p)
3792 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
3804 operator==(const param_type& __p1, const param_type& __p2)
3805 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3813 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3814 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
3818 negative_binomial_distribution(const param_type& __p)
3819 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
3823 * @brief Resets the distribution state.
3830 * @brief Return the @f$k@f$ parameter of the distribution.
3834 { return _M_param.k(); }
3837 * @brief Return the @f$p@f$ parameter of the distribution.
3841 { return _M_param.p(); }
3844 * @brief Returns the parameter set of the distribution.
3848 { return _M_param; }
3851 * @brief Sets the parameter set of the distribution.
3852 * @param __param The new parameter set of the distribution.
3855 param(const param_type& __param)
3856 { _M_param = __param; }
3859 * @brief Returns the greatest lower bound value of the distribution.
3863 { return result_type(0); }
3866 * @brief Returns the least upper bound value of the distribution.
3870 { return std::numeric_limits<result_type>::max(); }
3873 * @brief Generating functions.
3875 template<typename _UniformRandomNumberGenerator>
3877 operator()(_UniformRandomNumberGenerator& __urng);
3879 template<typename _UniformRandomNumberGenerator>
3881 operator()(_UniformRandomNumberGenerator& __urng,
3882 const param_type& __p);
3885 * @brief Return true if two negative binomial distributions have
3886 * the same parameters and the sequences that would be
3887 * generated are equal.
3890 operator==(const negative_binomial_distribution& __d1,
3891 const negative_binomial_distribution& __d2)
3892 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3895 * @brief Inserts a %negative_binomial_distribution random
3896 * number distribution @p __x into the output stream @p __os.
3898 * @param __os An output stream.
3899 * @param __x A %negative_binomial_distribution random number
3902 * @returns The output stream with the state of @p __x inserted or in
3905 template<typename _IntType1, typename _CharT, typename _Traits>
3906 friend std::basic_ostream<_CharT, _Traits>&
3907 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3908 const std::negative_binomial_distribution<_IntType1>& __x);
3911 * @brief Extracts a %negative_binomial_distribution random number
3912 * distribution @p __x from the input stream @p __is.
3914 * @param __is An input stream.
3915 * @param __x A %negative_binomial_distribution random number
3918 * @returns The input stream with @p __x extracted or in an error state.
3920 template<typename _IntType1, typename _CharT, typename _Traits>
3921 friend std::basic_istream<_CharT, _Traits>&
3922 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3923 std::negative_binomial_distribution<_IntType1>& __x);
3926 param_type _M_param;
3928 std::gamma_distribution<double> _M_gd;
3932 * @brief Return true if two negative binomial distributions are different.
3934 template<typename _IntType>
3936 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3937 const std::negative_binomial_distribution<_IntType>& __d2)
3938 { return !(__d1 == __d2); }
3941 /* @} */ // group random_distributions_bernoulli
3944 * @addtogroup random_distributions_poisson Poisson Distributions
3945 * @ingroup random_distributions
3950 * @brief A discrete Poisson random number distribution.
3952 * The formula for the Poisson probability density function is
3953 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3954 * parameter of the distribution.
3956 template<typename _IntType = int>
3957 class poisson_distribution
3959 static_assert(std::is_integral<_IntType>::value,
3960 "template argument not an integral type");
3963 /** The type of the range of the distribution. */
3964 typedef _IntType result_type;
3965 /** Parameter type. */
3968 typedef poisson_distribution<_IntType> distribution_type;
3969 friend class poisson_distribution<_IntType>;
3972 param_type(double __mean = 1.0)
3975 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3984 operator==(const param_type& __p1, const param_type& __p2)
3985 { return __p1._M_mean == __p2._M_mean; }
3988 // Hosts either log(mean) or the threshold of the simple method.
3995 #if _GLIBCXX_USE_C99_MATH_TR1
3996 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4000 // constructors and member function
4002 poisson_distribution(double __mean = 1.0)
4003 : _M_param(__mean), _M_nd()
4007 poisson_distribution(const param_type& __p)
4008 : _M_param(__p), _M_nd()
4012 * @brief Resets the distribution state.
4019 * @brief Returns the distribution parameter @p mean.
4023 { return _M_param.mean(); }
4026 * @brief Returns the parameter set of the distribution.
4030 { return _M_param; }
4033 * @brief Sets the parameter set of the distribution.
4034 * @param __param The new parameter set of the distribution.
4037 param(const param_type& __param)
4038 { _M_param = __param; }
4041 * @brief Returns the greatest lower bound value of the distribution.
4048 * @brief Returns the least upper bound value of the distribution.
4052 { return std::numeric_limits<result_type>::max(); }
4055 * @brief Generating functions.
4057 template<typename _UniformRandomNumberGenerator>
4059 operator()(_UniformRandomNumberGenerator& __urng)
4060 { return this->operator()(__urng, this->param()); }
4062 template<typename _UniformRandomNumberGenerator>
4064 operator()(_UniformRandomNumberGenerator& __urng,
4065 const param_type& __p);
4068 * @brief Return true if two Poisson distributions have the same
4069 * parameters and the sequences that would be generated
4073 operator==(const poisson_distribution& __d1,
4074 const poisson_distribution& __d2)
4075 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4076 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4078 { return __d1.param() == __d2.param(); }
4082 * @brief Inserts a %poisson_distribution random number distribution
4083 * @p __x into the output stream @p __os.
4085 * @param __os An output stream.
4086 * @param __x A %poisson_distribution random number distribution.
4088 * @returns The output stream with the state of @p __x inserted or in
4091 template<typename _IntType1, typename _CharT, typename _Traits>
4092 friend std::basic_ostream<_CharT, _Traits>&
4093 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4094 const std::poisson_distribution<_IntType1>& __x);
4097 * @brief Extracts a %poisson_distribution random number distribution
4098 * @p __x from the input stream @p __is.
4100 * @param __is An input stream.
4101 * @param __x A %poisson_distribution random number generator engine.
4103 * @returns The input stream with @p __x extracted or in an error
4106 template<typename _IntType1, typename _CharT, typename _Traits>
4107 friend std::basic_istream<_CharT, _Traits>&
4108 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4109 std::poisson_distribution<_IntType1>& __x);
4112 param_type _M_param;
4114 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4115 std::normal_distribution<double> _M_nd;
4119 * @brief Return true if two Poisson distributions are different.
4121 template<typename _IntType>
4123 operator!=(const std::poisson_distribution<_IntType>& __d1,
4124 const std::poisson_distribution<_IntType>& __d2)
4125 { return !(__d1 == __d2); }
4129 * @brief An exponential continuous distribution for random numbers.
4131 * The formula for the exponential probability density function is
4132 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4134 * <table border=1 cellpadding=10 cellspacing=0>
4135 * <caption align=top>Distribution Statistics</caption>
4136 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4137 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4138 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4139 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4140 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4143 template<typename _RealType = double>
4144 class exponential_distribution
4146 static_assert(std::is_floating_point<_RealType>::value,
4147 "template argument not a floating point type");
4150 /** The type of the range of the distribution. */
4151 typedef _RealType result_type;
4152 /** Parameter type. */
4155 typedef exponential_distribution<_RealType> distribution_type;
4158 param_type(_RealType __lambda = _RealType(1))
4159 : _M_lambda(__lambda)
4161 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4166 { return _M_lambda; }
4169 operator==(const param_type& __p1, const param_type& __p2)
4170 { return __p1._M_lambda == __p2._M_lambda; }
4173 _RealType _M_lambda;
4178 * @brief Constructs an exponential distribution with inverse scale
4179 * parameter @f$\lambda@f$.
4182 exponential_distribution(const result_type& __lambda = result_type(1))
4183 : _M_param(__lambda)
4187 exponential_distribution(const param_type& __p)
4192 * @brief Resets the distribution state.
4194 * Has no effect on exponential distributions.
4200 * @brief Returns the inverse scale parameter of the distribution.
4204 { return _M_param.lambda(); }
4207 * @brief Returns the parameter set of the distribution.
4211 { return _M_param; }
4214 * @brief Sets the parameter set of the distribution.
4215 * @param __param The new parameter set of the distribution.
4218 param(const param_type& __param)
4219 { _M_param = __param; }
4222 * @brief Returns the greatest lower bound value of the distribution.
4226 { return result_type(0); }
4229 * @brief Returns the least upper bound value of the distribution.
4233 { return std::numeric_limits<result_type>::max(); }
4236 * @brief Generating functions.
4238 template<typename _UniformRandomNumberGenerator>
4240 operator()(_UniformRandomNumberGenerator& __urng)
4241 { return this->operator()(__urng, this->param()); }
4243 template<typename _UniformRandomNumberGenerator>
4245 operator()(_UniformRandomNumberGenerator& __urng,
4246 const param_type& __p)
4248 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4250 return -std::log(__aurng()) / __p.lambda();
4254 param_type _M_param;
4258 * @brief Return true if two exponential distributions have the same
4261 template<typename _RealType>
4263 operator==(const std::exponential_distribution<_RealType>& __d1,
4264 const std::exponential_distribution<_RealType>& __d2)
4265 { return __d1.param() == __d2.param(); }
4268 * @brief Return true if two exponential distributions have different
4271 template<typename _RealType>
4273 operator!=(const std::exponential_distribution<_RealType>& __d1,
4274 const std::exponential_distribution<_RealType>& __d2)
4275 { return !(__d1 == __d2); }
4278 * @brief Inserts a %exponential_distribution random number distribution
4279 * @p __x into the output stream @p __os.
4281 * @param __os An output stream.
4282 * @param __x A %exponential_distribution random number distribution.
4284 * @returns The output stream with the state of @p __x inserted or in
4287 template<typename _RealType, typename _CharT, typename _Traits>
4288 std::basic_ostream<_CharT, _Traits>&
4289 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4290 const std::exponential_distribution<_RealType>& __x);
4293 * @brief Extracts a %exponential_distribution random number distribution
4294 * @p __x from the input stream @p __is.
4296 * @param __is An input stream.
4297 * @param __x A %exponential_distribution random number
4300 * @returns The input stream with @p __x extracted or in an error state.
4302 template<typename _RealType, typename _CharT, typename _Traits>
4303 std::basic_istream<_CharT, _Traits>&
4304 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4305 std::exponential_distribution<_RealType>& __x);
4309 * @brief A weibull_distribution random number distribution.
4311 * The formula for the normal probability density function is:
4313 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4314 * \exp{(-(\frac{x}{\beta})^\alpha)}
4317 template<typename _RealType = double>
4318 class weibull_distribution
4320 static_assert(std::is_floating_point<_RealType>::value,
4321 "template argument not a floating point type");
4324 /** The type of the range of the distribution. */
4325 typedef _RealType result_type;
4326 /** Parameter type. */
4329 typedef weibull_distribution<_RealType> distribution_type;
4332 param_type(_RealType __a = _RealType(1),
4333 _RealType __b = _RealType(1))
4334 : _M_a(__a), _M_b(__b)
4346 operator==(const param_type& __p1, const param_type& __p2)
4347 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4355 weibull_distribution(_RealType __a = _RealType(1),
4356 _RealType __b = _RealType(1))
4357 : _M_param(__a, __b)
4361 weibull_distribution(const param_type& __p)
4366 * @brief Resets the distribution state.
4373 * @brief Return the @f$a@f$ parameter of the distribution.
4377 { return _M_param.a(); }
4380 * @brief Return the @f$b@f$ parameter of the distribution.
4384 { return _M_param.b(); }
4387 * @brief Returns the parameter set of the distribution.
4391 { return _M_param; }
4394 * @brief Sets the parameter set of the distribution.
4395 * @param __param The new parameter set of the distribution.
4398 param(const param_type& __param)
4399 { _M_param = __param; }
4402 * @brief Returns the greatest lower bound value of the distribution.
4406 { return result_type(0); }
4409 * @brief Returns the least upper bound value of the distribution.
4413 { return std::numeric_limits<result_type>::max(); }
4416 * @brief Generating functions.
4418 template<typename _UniformRandomNumberGenerator>
4420 operator()(_UniformRandomNumberGenerator& __urng)
4421 { return this->operator()(__urng, this->param()); }
4423 template<typename _UniformRandomNumberGenerator>
4425 operator()(_UniformRandomNumberGenerator& __urng,
4426 const param_type& __p);
4429 param_type _M_param;
4433 * @brief Return true if two Weibull distributions have the same
4436 template<typename _RealType>
4438 operator==(const std::weibull_distribution<_RealType>& __d1,
4439 const std::weibull_distribution<_RealType>& __d2)
4440 { return __d1.param() == __d2.param(); }
4443 * @brief Return true if two Weibull distributions have different
4446 template<typename _RealType>
4448 operator!=(const std::weibull_distribution<_RealType>& __d1,
4449 const std::weibull_distribution<_RealType>& __d2)
4450 { return !(__d1 == __d2); }
4453 * @brief Inserts a %weibull_distribution random number distribution
4454 * @p __x into the output stream @p __os.
4456 * @param __os An output stream.
4457 * @param __x A %weibull_distribution random number distribution.
4459 * @returns The output stream with the state of @p __x inserted or in
4462 template<typename _RealType, typename _CharT, typename _Traits>
4463 std::basic_ostream<_CharT, _Traits>&
4464 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4465 const std::weibull_distribution<_RealType>& __x);
4468 * @brief Extracts a %weibull_distribution random number distribution
4469 * @p __x from the input stream @p __is.
4471 * @param __is An input stream.
4472 * @param __x A %weibull_distribution random number
4475 * @returns The input stream with @p __x extracted or in an error state.
4477 template<typename _RealType, typename _CharT, typename _Traits>
4478 std::basic_istream<_CharT, _Traits>&
4479 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4480 std::weibull_distribution<_RealType>& __x);
4484 * @brief A extreme_value_distribution random number distribution.
4486 * The formula for the normal probability mass function is
4488 * p(x|a,b) = \frac{1}{b}
4489 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4492 template<typename _RealType = double>
4493 class extreme_value_distribution
4495 static_assert(std::is_floating_point<_RealType>::value,
4496 "template argument not a floating point type");
4499 /** The type of the range of the distribution. */
4500 typedef _RealType result_type;
4501 /** Parameter type. */
4504 typedef extreme_value_distribution<_RealType> distribution_type;
4507 param_type(_RealType __a = _RealType(0),
4508 _RealType __b = _RealType(1))
4509 : _M_a(__a), _M_b(__b)
4521 operator==(const param_type& __p1, const param_type& __p2)
4522 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4530 extreme_value_distribution(_RealType __a = _RealType(0),
4531 _RealType __b = _RealType(1))
4532 : _M_param(__a, __b)
4536 extreme_value_distribution(const param_type& __p)
4541 * @brief Resets the distribution state.
4548 * @brief Return the @f$a@f$ parameter of the distribution.
4552 { return _M_param.a(); }
4555 * @brief Return the @f$b@f$ parameter of the distribution.
4559 { return _M_param.b(); }
4562 * @brief Returns the parameter set of the distribution.
4566 { return _M_param; }
4569 * @brief Sets the parameter set of the distribution.
4570 * @param __param The new parameter set of the distribution.
4573 param(const param_type& __param)
4574 { _M_param = __param; }
4577 * @brief Returns the greatest lower bound value of the distribution.
4581 { return std::numeric_limits<result_type>::min(); }
4584 * @brief Returns the least upper bound value of the distribution.
4588 { return std::numeric_limits<result_type>::max(); }
4591 * @brief Generating functions.
4593 template<typename _UniformRandomNumberGenerator>
4595 operator()(_UniformRandomNumberGenerator& __urng)
4596 { return this->operator()(__urng, this->param()); }
4598 template<typename _UniformRandomNumberGenerator>
4600 operator()(_UniformRandomNumberGenerator& __urng,
4601 const param_type& __p);
4604 param_type _M_param;
4608 * @brief Return true if two extreme value distributions have the same
4611 template<typename _RealType>
4613 operator==(const std::extreme_value_distribution<_RealType>& __d1,
4614 const std::extreme_value_distribution<_RealType>& __d2)
4615 { return __d1.param() == __d2.param(); }
4618 * @brief Return true if two extreme value distributions have different
4621 template<typename _RealType>
4623 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4624 const std::extreme_value_distribution<_RealType>& __d2)
4625 { return !(__d1 == __d2); }
4628 * @brief Inserts a %extreme_value_distribution random number distribution
4629 * @p __x into the output stream @p __os.
4631 * @param __os An output stream.
4632 * @param __x A %extreme_value_distribution random number distribution.
4634 * @returns The output stream with the state of @p __x inserted or in
4637 template<typename _RealType, typename _CharT, typename _Traits>
4638 std::basic_ostream<_CharT, _Traits>&
4639 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4640 const std::extreme_value_distribution<_RealType>& __x);
4643 * @brief Extracts a %extreme_value_distribution random number
4644 * distribution @p __x from the input stream @p __is.
4646 * @param __is An input stream.
4647 * @param __x A %extreme_value_distribution random number
4650 * @returns The input stream with @p __x extracted or in an error state.
4652 template<typename _RealType, typename _CharT, typename _Traits>
4653 std::basic_istream<_CharT, _Traits>&
4654 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4655 std::extreme_value_distribution<_RealType>& __x);
4659 * @brief A discrete_distribution random number distribution.
4661 * The formula for the discrete probability mass function is
4664 template<typename _IntType = int>
4665 class discrete_distribution
4667 static_assert(std::is_integral<_IntType>::value,
4668 "template argument not an integral type");
4671 /** The type of the range of the distribution. */
4672 typedef _IntType result_type;
4673 /** Parameter type. */
4676 typedef discrete_distribution<_IntType> distribution_type;
4677 friend class discrete_distribution<_IntType>;
4680 : _M_prob(), _M_cp()
4683 template<typename _InputIterator>
4684 param_type(_InputIterator __wbegin,
4685 _InputIterator __wend)
4686 : _M_prob(__wbegin, __wend), _M_cp()
4687 { _M_initialize(); }
4689 param_type(initializer_list<double> __wil)
4690 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4691 { _M_initialize(); }
4693 template<typename _Func>
4694 param_type(size_t __nw, double __xmin, double __xmax,
4697 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4698 param_type(const param_type&) = default;
4699 param_type& operator=(const param_type&) = default;
4702 probabilities() const
4703 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4706 operator==(const param_type& __p1, const param_type& __p2)
4707 { return __p1._M_prob == __p2._M_prob; }
4713 std::vector<double> _M_prob;
4714 std::vector<double> _M_cp;
4717 discrete_distribution()
4721 template<typename _InputIterator>
4722 discrete_distribution(_InputIterator __wbegin,
4723 _InputIterator __wend)
4724 : _M_param(__wbegin, __wend)
4727 discrete_distribution(initializer_list<double> __wl)
4731 template<typename _Func>
4732 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4734 : _M_param(__nw, __xmin, __xmax, __fw)
4738 discrete_distribution(const param_type& __p)
4743 * @brief Resets the distribution state.
4750 * @brief Returns the probabilities of the distribution.
4753 probabilities() const
4755 return _M_param._M_prob.empty()
4756 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4760 * @brief Returns the parameter set of the distribution.
4764 { return _M_param; }
4767 * @brief Sets the parameter set of the distribution.
4768 * @param __param The new parameter set of the distribution.
4771 param(const param_type& __param)
4772 { _M_param = __param; }
4775 * @brief Returns the greatest lower bound value of the distribution.
4779 { return result_type(0); }
4782 * @brief Returns the least upper bound value of the distribution.
4787 return _M_param._M_prob.empty()
4788 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4792 * @brief Generating functions.
4794 template<typename _UniformRandomNumberGenerator>
4796 operator()(_UniformRandomNumberGenerator& __urng)
4797 { return this->operator()(__urng, this->param()); }
4799 template<typename _UniformRandomNumberGenerator>
4801 operator()(_UniformRandomNumberGenerator& __urng,
4802 const param_type& __p);
4805 * @brief Inserts a %discrete_distribution random number distribution
4806 * @p __x into the output stream @p __os.
4808 * @param __os An output stream.
4809 * @param __x A %discrete_distribution random number distribution.
4811 * @returns The output stream with the state of @p __x inserted or in
4814 template<typename _IntType1, typename _CharT, typename _Traits>
4815 friend std::basic_ostream<_CharT, _Traits>&
4816 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4817 const std::discrete_distribution<_IntType1>& __x);
4820 * @brief Extracts a %discrete_distribution random number distribution
4821 * @p __x from the input stream @p __is.
4823 * @param __is An input stream.
4824 * @param __x A %discrete_distribution random number
4827 * @returns The input stream with @p __x extracted or in an error
4830 template<typename _IntType1, typename _CharT, typename _Traits>
4831 friend std::basic_istream<_CharT, _Traits>&
4832 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4833 std::discrete_distribution<_IntType1>& __x);
4836 param_type _M_param;
4840 * @brief Return true if two discrete distributions have the same
4843 template<typename _IntType>
4845 operator==(const std::discrete_distribution<_IntType>& __d1,
4846 const std::discrete_distribution<_IntType>& __d2)
4847 { return __d1.param() == __d2.param(); }
4850 * @brief Return true if two discrete distributions have different
4853 template<typename _IntType>
4855 operator!=(const std::discrete_distribution<_IntType>& __d1,
4856 const std::discrete_distribution<_IntType>& __d2)
4857 { return !(__d1 == __d2); }
4861 * @brief A piecewise_constant_distribution random number distribution.
4863 * The formula for the piecewise constant probability mass function is
4866 template<typename _RealType = double>
4867 class piecewise_constant_distribution
4869 static_assert(std::is_floating_point<_RealType>::value,
4870 "template argument not a floating point type");
4873 /** The type of the range of the distribution. */
4874 typedef _RealType result_type;
4875 /** Parameter type. */
4878 typedef piecewise_constant_distribution<_RealType> distribution_type;
4879 friend class piecewise_constant_distribution<_RealType>;
4882 : _M_int(), _M_den(), _M_cp()
4885 template<typename _InputIteratorB, typename _InputIteratorW>
4886 param_type(_InputIteratorB __bfirst,
4887 _InputIteratorB __bend,
4888 _InputIteratorW __wbegin);
4890 template<typename _Func>
4891 param_type(initializer_list<_RealType> __bi, _Func __fw);
4893 template<typename _Func>
4894 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4897 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4898 param_type(const param_type&) = default;
4899 param_type& operator=(const param_type&) = default;
4901 std::vector<_RealType>
4906 std::vector<_RealType> __tmp(2);
4907 __tmp[1] = _RealType(1);
4916 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4919 operator==(const param_type& __p1, const param_type& __p2)
4920 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4926 std::vector<_RealType> _M_int;
4927 std::vector<double> _M_den;
4928 std::vector<double> _M_cp;
4932 piecewise_constant_distribution()
4936 template<typename _InputIteratorB, typename _InputIteratorW>
4937 piecewise_constant_distribution(_InputIteratorB __bfirst,
4938 _InputIteratorB __bend,
4939 _InputIteratorW __wbegin)
4940 : _M_param(__bfirst, __bend, __wbegin)
4943 template<typename _Func>
4944 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4946 : _M_param(__bl, __fw)
4949 template<typename _Func>
4950 piecewise_constant_distribution(size_t __nw,
4951 _RealType __xmin, _RealType __xmax,
4953 : _M_param(__nw, __xmin, __xmax, __fw)
4957 piecewise_constant_distribution(const param_type& __p)
4962 * @brief Resets the distribution state.
4969 * @brief Returns a vector of the intervals.
4971 std::vector<_RealType>
4974 if (_M_param._M_int.empty())
4976 std::vector<_RealType> __tmp(2);
4977 __tmp[1] = _RealType(1);
4981 return _M_param._M_int;
4985 * @brief Returns a vector of the probability densities.
4990 return _M_param._M_den.empty()
4991 ? std::vector<double>(1, 1.0) : _M_param._M_den;
4995 * @brief Returns the parameter set of the distribution.
4999 { return _M_param; }
5002 * @brief Sets the parameter set of the distribution.
5003 * @param __param The new parameter set of the distribution.
5006 param(const param_type& __param)
5007 { _M_param = __param; }
5010 * @brief Returns the greatest lower bound value of the distribution.
5015 return _M_param._M_int.empty()
5016 ? result_type(0) : _M_param._M_int.front();
5020 * @brief Returns the least upper bound value of the distribution.
5025 return _M_param._M_int.empty()
5026 ? result_type(1) : _M_param._M_int.back();
5030 * @brief Generating functions.
5032 template<typename _UniformRandomNumberGenerator>
5034 operator()(_UniformRandomNumberGenerator& __urng)
5035 { return this->operator()(__urng, this->param()); }
5037 template<typename _UniformRandomNumberGenerator>
5039 operator()(_UniformRandomNumberGenerator& __urng,
5040 const param_type& __p);
5043 * @brief Inserts a %piecewise_constan_distribution random
5044 * number distribution @p __x into the output stream @p __os.
5046 * @param __os An output stream.
5047 * @param __x A %piecewise_constan_distribution random number
5050 * @returns The output stream with the state of @p __x inserted or in
5053 template<typename _RealType1, typename _CharT, typename _Traits>
5054 friend std::basic_ostream<_CharT, _Traits>&
5055 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5056 const std::piecewise_constant_distribution<_RealType1>& __x);
5059 * @brief Extracts a %piecewise_constan_distribution random
5060 * number distribution @p __x from the input stream @p __is.
5062 * @param __is An input stream.
5063 * @param __x A %piecewise_constan_distribution random number
5066 * @returns The input stream with @p __x extracted or in an error
5069 template<typename _RealType1, typename _CharT, typename _Traits>
5070 friend std::basic_istream<_CharT, _Traits>&
5071 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5072 std::piecewise_constant_distribution<_RealType1>& __x);
5075 param_type _M_param;
5079 * @brief Return true if two piecewise constant distributions have the
5082 template<typename _RealType>
5084 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
5085 const std::piecewise_constant_distribution<_RealType>& __d2)
5086 { return __d1.param() == __d2.param(); }
5089 * @brief Return true if two piecewise constant distributions have
5090 * different parameters.
5092 template<typename _RealType>
5094 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5095 const std::piecewise_constant_distribution<_RealType>& __d2)
5096 { return !(__d1 == __d2); }
5100 * @brief A piecewise_linear_distribution random number distribution.
5102 * The formula for the piecewise linear probability mass function is
5105 template<typename _RealType = double>
5106 class piecewise_linear_distribution
5108 static_assert(std::is_floating_point<_RealType>::value,
5109 "template argument not a floating point type");
5112 /** The type of the range of the distribution. */
5113 typedef _RealType result_type;
5114 /** Parameter type. */
5117 typedef piecewise_linear_distribution<_RealType> distribution_type;
5118 friend class piecewise_linear_distribution<_RealType>;
5121 : _M_int(), _M_den(), _M_cp(), _M_m()
5124 template<typename _InputIteratorB, typename _InputIteratorW>
5125 param_type(_InputIteratorB __bfirst,
5126 _InputIteratorB __bend,
5127 _InputIteratorW __wbegin);
5129 template<typename _Func>
5130 param_type(initializer_list<_RealType> __bl, _Func __fw);
5132 template<typename _Func>
5133 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5136 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5137 param_type(const param_type&) = default;
5138 param_type& operator=(const param_type&) = default;
5140 std::vector<_RealType>
5145 std::vector<_RealType> __tmp(2);
5146 __tmp[1] = _RealType(1);
5155 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5158 operator==(const param_type& __p1, const param_type& __p2)
5159 { return (__p1._M_int == __p2._M_int
5160 && __p1._M_den == __p2._M_den); }
5166 std::vector<_RealType> _M_int;
5167 std::vector<double> _M_den;
5168 std::vector<double> _M_cp;
5169 std::vector<double> _M_m;
5173 piecewise_linear_distribution()
5177 template<typename _InputIteratorB, typename _InputIteratorW>
5178 piecewise_linear_distribution(_InputIteratorB __bfirst,
5179 _InputIteratorB __bend,
5180 _InputIteratorW __wbegin)
5181 : _M_param(__bfirst, __bend, __wbegin)
5184 template<typename _Func>
5185 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5187 : _M_param(__bl, __fw)
5190 template<typename _Func>
5191 piecewise_linear_distribution(size_t __nw,
5192 _RealType __xmin, _RealType __xmax,
5194 : _M_param(__nw, __xmin, __xmax, __fw)
5198 piecewise_linear_distribution(const param_type& __p)
5203 * Resets the distribution state.
5210 * @brief Return the intervals of the distribution.
5212 std::vector<_RealType>
5215 if (_M_param._M_int.empty())
5217 std::vector<_RealType> __tmp(2);
5218 __tmp[1] = _RealType(1);
5222 return _M_param._M_int;
5226 * @brief Return a vector of the probability densities of the
5232 return _M_param._M_den.empty()
5233 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5237 * @brief Returns the parameter set of the distribution.
5241 { return _M_param; }
5244 * @brief Sets the parameter set of the distribution.
5245 * @param __param The new parameter set of the distribution.
5248 param(const param_type& __param)
5249 { _M_param = __param; }
5252 * @brief Returns the greatest lower bound value of the distribution.
5257 return _M_param._M_int.empty()
5258 ? result_type(0) : _M_param._M_int.front();
5262 * @brief Returns the least upper bound value of the distribution.
5267 return _M_param._M_int.empty()
5268 ? result_type(1) : _M_param._M_int.back();
5272 * @brief Generating functions.
5274 template<typename _UniformRandomNumberGenerator>
5276 operator()(_UniformRandomNumberGenerator& __urng)
5277 { return this->operator()(__urng, this->param()); }
5279 template<typename _UniformRandomNumberGenerator>
5281 operator()(_UniformRandomNumberGenerator& __urng,
5282 const param_type& __p);
5285 * @brief Inserts a %piecewise_linear_distribution random number
5286 * distribution @p __x into the output stream @p __os.
5288 * @param __os An output stream.
5289 * @param __x A %piecewise_linear_distribution random number
5292 * @returns The output stream with the state of @p __x inserted or in
5295 template<typename _RealType1, typename _CharT, typename _Traits>
5296 friend std::basic_ostream<_CharT, _Traits>&
5297 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5298 const std::piecewise_linear_distribution<_RealType1>& __x);
5301 * @brief Extracts a %piecewise_linear_distribution random number
5302 * distribution @p __x from the input stream @p __is.
5304 * @param __is An input stream.
5305 * @param __x A %piecewise_linear_distribution random number
5308 * @returns The input stream with @p __x extracted or in an error
5311 template<typename _RealType1, typename _CharT, typename _Traits>
5312 friend std::basic_istream<_CharT, _Traits>&
5313 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5314 std::piecewise_linear_distribution<_RealType1>& __x);
5317 param_type _M_param;
5321 * @brief Return true if two piecewise linear distributions have the
5324 template<typename _RealType>
5326 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
5327 const std::piecewise_linear_distribution<_RealType>& __d2)
5328 { return __d1.param() == __d2.param(); }
5331 * @brief Return true if two piecewise linear distributions have
5332 * different parameters.
5334 template<typename _RealType>
5336 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5337 const std::piecewise_linear_distribution<_RealType>& __d2)
5338 { return !(__d1 == __d2); }
5341 /* @} */ // group random_distributions_poisson
5343 /* @} */ // group random_distributions
5346 * @addtogroup random_utilities Random Number Utilities
5352 * @brief The seed_seq class generates sequences of seeds for random
5353 * number generators.
5359 /** The type of the seed vales. */
5360 typedef uint_least32_t result_type;
5362 /** Default constructor. */
5367 template<typename _IntType>
5368 seed_seq(std::initializer_list<_IntType> il);
5370 template<typename _InputIterator>
5371 seed_seq(_InputIterator __begin, _InputIterator __end);
5373 // generating functions
5374 template<typename _RandomAccessIterator>
5376 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5378 // property functions
5380 { return _M_v.size(); }
5382 template<typename OutputIterator>
5384 param(OutputIterator __dest) const
5385 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5389 std::vector<result_type> _M_v;
5392 /* @} */ // group random_utilities
5394 /* @} */ // group random
5396 _GLIBCXX_END_NAMESPACE_VERSION