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.
2277 template<typename _RealType1>
2279 operator==(const std::lognormal_distribution<_RealType1>& __d1,
2280 const std::lognormal_distribution<_RealType1>& __d2)
2281 { return (__d1.param() == __d2.param()
2282 && __d1._M_nd == __d2._M_nd); }
2285 * @brief Inserts a %lognormal_distribution random number distribution
2286 * @p __x into the output stream @p __os.
2288 * @param __os An output stream.
2289 * @param __x A %lognormal_distribution random number distribution.
2291 * @returns The output stream with the state of @p __x inserted or in
2294 template<typename _RealType1, typename _CharT, typename _Traits>
2295 friend std::basic_ostream<_CharT, _Traits>&
2296 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2297 const std::lognormal_distribution<_RealType1>& __x);
2300 * @brief Extracts a %lognormal_distribution random number distribution
2301 * @p __x from the input stream @p __is.
2303 * @param __is An input stream.
2304 * @param __x A %lognormal_distribution random number
2307 * @returns The input stream with @p __x extracted or in an error state.
2309 template<typename _RealType1, typename _CharT, typename _Traits>
2310 friend std::basic_istream<_CharT, _Traits>&
2311 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2312 std::lognormal_distribution<_RealType1>& __x);
2315 param_type _M_param;
2317 std::normal_distribution<result_type> _M_nd;
2321 * @brief Return true if two lognormal distributions are different.
2323 template<typename _RealType>
2325 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2326 const std::lognormal_distribution<_RealType>& __d2)
2327 { return !(__d1 == __d2); }
2331 * @brief A gamma continuous distribution for random numbers.
2333 * The formula for the gamma probability density function is:
2335 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2336 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2339 template<typename _RealType = double>
2340 class gamma_distribution
2342 static_assert(std::is_floating_point<_RealType>::value,
2343 "template argument not a floating point type");
2346 /** The type of the range of the distribution. */
2347 typedef _RealType result_type;
2348 /** Parameter type. */
2351 typedef gamma_distribution<_RealType> distribution_type;
2352 friend class gamma_distribution<_RealType>;
2355 param_type(_RealType __alpha_val = _RealType(1),
2356 _RealType __beta_val = _RealType(1))
2357 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2359 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2365 { return _M_alpha; }
2372 operator==(const param_type& __p1, const param_type& __p2)
2373 { return (__p1._M_alpha == __p2._M_alpha
2374 && __p1._M_beta == __p2._M_beta); }
2383 _RealType _M_malpha, _M_a2;
2388 * @brief Constructs a gamma distribution with parameters
2389 * @f$\alpha@f$ and @f$\beta@f$.
2392 gamma_distribution(_RealType __alpha_val = _RealType(1),
2393 _RealType __beta_val = _RealType(1))
2394 : _M_param(__alpha_val, __beta_val), _M_nd()
2398 gamma_distribution(const param_type& __p)
2399 : _M_param(__p), _M_nd()
2403 * @brief Resets the distribution state.
2410 * @brief Returns the @f$\alpha@f$ of the distribution.
2414 { return _M_param.alpha(); }
2417 * @brief Returns the @f$\beta@f$ of the distribution.
2421 { return _M_param.beta(); }
2424 * @brief Returns the parameter set of the distribution.
2428 { return _M_param; }
2431 * @brief Sets the parameter set of the distribution.
2432 * @param __param The new parameter set of the distribution.
2435 param(const param_type& __param)
2436 { _M_param = __param; }
2439 * @brief Returns the greatest lower bound value of the distribution.
2443 { return result_type(0); }
2446 * @brief Returns the least upper bound value of the distribution.
2450 { return std::numeric_limits<result_type>::max(); }
2453 * @brief Generating functions.
2455 template<typename _UniformRandomNumberGenerator>
2457 operator()(_UniformRandomNumberGenerator& __urng)
2458 { return this->operator()(__urng, this->param()); }
2460 template<typename _UniformRandomNumberGenerator>
2462 operator()(_UniformRandomNumberGenerator& __urng,
2463 const param_type& __p);
2466 * @brief Return true if two gamma distributions have the same
2467 * parameters and the sequences that would be generated
2470 template<typename _RealType1>
2472 operator==(const std::gamma_distribution<_RealType1>& __d1,
2473 const std::gamma_distribution<_RealType1>& __d2)
2474 { return (__d1.param() == __d2.param()
2475 && __d1._M_nd == __d2._M_nd); }
2478 * @brief Inserts a %gamma_distribution random number distribution
2479 * @p __x into the output stream @p __os.
2481 * @param __os An output stream.
2482 * @param __x A %gamma_distribution random number distribution.
2484 * @returns The output stream with the state of @p __x inserted or in
2487 template<typename _RealType1, typename _CharT, typename _Traits>
2488 friend std::basic_ostream<_CharT, _Traits>&
2489 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2490 const std::gamma_distribution<_RealType1>& __x);
2493 * @brief Extracts a %gamma_distribution random number distribution
2494 * @p __x from the input stream @p __is.
2496 * @param __is An input stream.
2497 * @param __x A %gamma_distribution random number generator engine.
2499 * @returns The input stream with @p __x extracted or in an error state.
2501 template<typename _RealType1, typename _CharT, typename _Traits>
2502 friend std::basic_istream<_CharT, _Traits>&
2503 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2504 std::gamma_distribution<_RealType1>& __x);
2507 param_type _M_param;
2509 std::normal_distribution<result_type> _M_nd;
2513 * @brief Return true if two gamma distributions are different.
2515 template<typename _RealType>
2517 operator!=(const std::gamma_distribution<_RealType>& __d1,
2518 const std::gamma_distribution<_RealType>& __d2)
2519 { return !(__d1 == __d2); }
2523 * @brief A chi_squared_distribution random number distribution.
2525 * The formula for the normal probability mass function is
2526 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2528 template<typename _RealType = double>
2529 class chi_squared_distribution
2531 static_assert(std::is_floating_point<_RealType>::value,
2532 "template argument not a floating point type");
2535 /** The type of the range of the distribution. */
2536 typedef _RealType result_type;
2537 /** Parameter type. */
2540 typedef chi_squared_distribution<_RealType> distribution_type;
2543 param_type(_RealType __n = _RealType(1))
2552 operator==(const param_type& __p1, const param_type& __p2)
2553 { return __p1._M_n == __p2._M_n; }
2560 chi_squared_distribution(_RealType __n = _RealType(1))
2561 : _M_param(__n), _M_gd(__n / 2)
2565 chi_squared_distribution(const param_type& __p)
2566 : _M_param(__p), _M_gd(__p.n() / 2)
2570 * @brief Resets the distribution state.
2581 { return _M_param.n(); }
2584 * @brief Returns the parameter set of the distribution.
2588 { return _M_param; }
2591 * @brief Sets the parameter set of the distribution.
2592 * @param __param The new parameter set of the distribution.
2595 param(const param_type& __param)
2596 { _M_param = __param; }
2599 * @brief Returns the greatest lower bound value of the distribution.
2603 { return result_type(0); }
2606 * @brief Returns the least upper bound value of the distribution.
2610 { return std::numeric_limits<result_type>::max(); }
2613 * @brief Generating functions.
2615 template<typename _UniformRandomNumberGenerator>
2617 operator()(_UniformRandomNumberGenerator& __urng)
2618 { return 2 * _M_gd(__urng); }
2620 template<typename _UniformRandomNumberGenerator>
2622 operator()(_UniformRandomNumberGenerator& __urng,
2623 const param_type& __p)
2625 typedef typename std::gamma_distribution<result_type>::param_type
2627 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2631 * @brief Return true if two Chi-squared distributions have
2632 * the same parameters and the sequences that would be
2633 * generated are equal.
2635 template<typename _RealType1>
2637 operator==(const std::chi_squared_distribution<_RealType1>& __d1,
2638 const std::chi_squared_distribution<_RealType1>& __d2)
2639 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2642 * @brief Inserts a %chi_squared_distribution random number distribution
2643 * @p __x into the output stream @p __os.
2645 * @param __os An output stream.
2646 * @param __x A %chi_squared_distribution random number distribution.
2648 * @returns The output stream with the state of @p __x inserted or in
2651 template<typename _RealType1, typename _CharT, typename _Traits>
2652 friend std::basic_ostream<_CharT, _Traits>&
2653 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2654 const std::chi_squared_distribution<_RealType1>& __x);
2657 * @brief Extracts a %chi_squared_distribution random number distribution
2658 * @p __x from the input stream @p __is.
2660 * @param __is An input stream.
2661 * @param __x A %chi_squared_distribution random number
2664 * @returns The input stream with @p __x extracted or in an error state.
2666 template<typename _RealType1, typename _CharT, typename _Traits>
2667 friend std::basic_istream<_CharT, _Traits>&
2668 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2669 std::chi_squared_distribution<_RealType1>& __x);
2672 param_type _M_param;
2674 std::gamma_distribution<result_type> _M_gd;
2678 * @brief Return true if two Chi-squared distributions are different.
2680 template<typename _RealType>
2682 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2683 const std::chi_squared_distribution<_RealType>& __d2)
2684 { return !(__d1 == __d2); }
2688 * @brief A cauchy_distribution random number distribution.
2690 * The formula for the normal probability mass function is
2691 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2693 template<typename _RealType = double>
2694 class cauchy_distribution
2696 static_assert(std::is_floating_point<_RealType>::value,
2697 "template argument not a floating point type");
2700 /** The type of the range of the distribution. */
2701 typedef _RealType result_type;
2702 /** Parameter type. */
2705 typedef cauchy_distribution<_RealType> distribution_type;
2708 param_type(_RealType __a = _RealType(0),
2709 _RealType __b = _RealType(1))
2710 : _M_a(__a), _M_b(__b)
2722 operator==(const param_type& __p1, const param_type& __p2)
2723 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2731 cauchy_distribution(_RealType __a = _RealType(0),
2732 _RealType __b = _RealType(1))
2733 : _M_param(__a, __b)
2737 cauchy_distribution(const param_type& __p)
2742 * @brief Resets the distribution state.
2753 { return _M_param.a(); }
2757 { return _M_param.b(); }
2760 * @brief Returns the parameter set of the distribution.
2764 { return _M_param; }
2767 * @brief Sets the parameter set of the distribution.
2768 * @param __param The new parameter set of the distribution.
2771 param(const param_type& __param)
2772 { _M_param = __param; }
2775 * @brief Returns the greatest lower bound value of the distribution.
2779 { return std::numeric_limits<result_type>::min(); }
2782 * @brief Returns the least upper bound value of the distribution.
2786 { return std::numeric_limits<result_type>::max(); }
2789 * @brief Generating functions.
2791 template<typename _UniformRandomNumberGenerator>
2793 operator()(_UniformRandomNumberGenerator& __urng)
2794 { return this->operator()(__urng, this->param()); }
2796 template<typename _UniformRandomNumberGenerator>
2798 operator()(_UniformRandomNumberGenerator& __urng,
2799 const param_type& __p);
2802 param_type _M_param;
2806 * @brief Return true if two Cauchy distributions have
2807 * the same parameters.
2809 template<typename _RealType>
2811 operator==(const std::cauchy_distribution<_RealType>& __d1,
2812 const std::cauchy_distribution<_RealType>& __d2)
2813 { return __d1.param() == __d2.param(); }
2816 * @brief Return true if two Cauchy distributions have
2817 * different parameters.
2819 template<typename _RealType>
2821 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2822 const std::cauchy_distribution<_RealType>& __d2)
2823 { return !(__d1 == __d2); }
2826 * @brief Inserts a %cauchy_distribution random number distribution
2827 * @p __x into the output stream @p __os.
2829 * @param __os An output stream.
2830 * @param __x A %cauchy_distribution random number distribution.
2832 * @returns The output stream with the state of @p __x inserted or in
2835 template<typename _RealType, typename _CharT, typename _Traits>
2836 std::basic_ostream<_CharT, _Traits>&
2837 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2838 const std::cauchy_distribution<_RealType>& __x);
2841 * @brief Extracts a %cauchy_distribution random number distribution
2842 * @p __x from the input stream @p __is.
2844 * @param __is An input stream.
2845 * @param __x A %cauchy_distribution random number
2848 * @returns The input stream with @p __x extracted or in an error state.
2850 template<typename _RealType, typename _CharT, typename _Traits>
2851 std::basic_istream<_CharT, _Traits>&
2852 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2853 std::cauchy_distribution<_RealType>& __x);
2857 * @brief A fisher_f_distribution random number distribution.
2859 * The formula for the normal probability mass function is
2861 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2862 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2863 * (1 + \frac{mx}{n})^{-(m+n)/2}
2866 template<typename _RealType = double>
2867 class fisher_f_distribution
2869 static_assert(std::is_floating_point<_RealType>::value,
2870 "template argument not a floating point type");
2873 /** The type of the range of the distribution. */
2874 typedef _RealType result_type;
2875 /** Parameter type. */
2878 typedef fisher_f_distribution<_RealType> distribution_type;
2881 param_type(_RealType __m = _RealType(1),
2882 _RealType __n = _RealType(1))
2883 : _M_m(__m), _M_n(__n)
2895 operator==(const param_type& __p1, const param_type& __p2)
2896 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2904 fisher_f_distribution(_RealType __m = _RealType(1),
2905 _RealType __n = _RealType(1))
2906 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2910 fisher_f_distribution(const param_type& __p)
2911 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2915 * @brief Resets the distribution state.
2929 { return _M_param.m(); }
2933 { return _M_param.n(); }
2936 * @brief Returns the parameter set of the distribution.
2940 { return _M_param; }
2943 * @brief Sets the parameter set of the distribution.
2944 * @param __param The new parameter set of the distribution.
2947 param(const param_type& __param)
2948 { _M_param = __param; }
2951 * @brief Returns the greatest lower bound value of the distribution.
2955 { return result_type(0); }
2958 * @brief Returns the least upper bound value of the distribution.
2962 { return std::numeric_limits<result_type>::max(); }
2965 * @brief Generating functions.
2967 template<typename _UniformRandomNumberGenerator>
2969 operator()(_UniformRandomNumberGenerator& __urng)
2970 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2972 template<typename _UniformRandomNumberGenerator>
2974 operator()(_UniformRandomNumberGenerator& __urng,
2975 const param_type& __p)
2977 typedef typename std::gamma_distribution<result_type>::param_type
2979 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2980 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2984 * @brief Return true if two Fisher f distributions have
2985 * the same parameters and the sequences that would
2986 * be generated are equal.
2988 template<typename _RealType1>
2990 operator==(const std::fisher_f_distribution<_RealType1>& __d1,
2991 const std::fisher_f_distribution<_RealType1>& __d2)
2992 { return (__d1.param() == __d2.param()
2993 && __d1._M_gd_x == __d2._M_gd_x
2994 && __d1._M_gd_y == __d2._M_gd_y); }
2997 * @brief Inserts a %fisher_f_distribution random number distribution
2998 * @p __x into the output stream @p __os.
3000 * @param __os An output stream.
3001 * @param __x A %fisher_f_distribution random number distribution.
3003 * @returns The output stream with the state of @p __x inserted or in
3006 template<typename _RealType1, typename _CharT, typename _Traits>
3007 friend std::basic_ostream<_CharT, _Traits>&
3008 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3009 const std::fisher_f_distribution<_RealType1>& __x);
3012 * @brief Extracts a %fisher_f_distribution random number distribution
3013 * @p __x from the input stream @p __is.
3015 * @param __is An input stream.
3016 * @param __x A %fisher_f_distribution random number
3019 * @returns The input stream with @p __x extracted or in an error state.
3021 template<typename _RealType1, typename _CharT, typename _Traits>
3022 friend std::basic_istream<_CharT, _Traits>&
3023 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3024 std::fisher_f_distribution<_RealType1>& __x);
3027 param_type _M_param;
3029 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3033 * @brief Return true if two Fisher f distributions are diferent.
3035 template<typename _RealType>
3037 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3038 const std::fisher_f_distribution<_RealType>& __d2)
3039 { return !(__d1 == __d2); }
3042 * @brief A student_t_distribution random number distribution.
3044 * The formula for the normal probability mass function is:
3046 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3047 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3050 template<typename _RealType = double>
3051 class student_t_distribution
3053 static_assert(std::is_floating_point<_RealType>::value,
3054 "template argument not a floating point type");
3057 /** The type of the range of the distribution. */
3058 typedef _RealType result_type;
3059 /** Parameter type. */
3062 typedef student_t_distribution<_RealType> distribution_type;
3065 param_type(_RealType __n = _RealType(1))
3074 operator==(const param_type& __p1, const param_type& __p2)
3075 { return __p1._M_n == __p2._M_n; }
3082 student_t_distribution(_RealType __n = _RealType(1))
3083 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3087 student_t_distribution(const param_type& __p)
3088 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3092 * @brief Resets the distribution state.
3106 { return _M_param.n(); }
3109 * @brief Returns the parameter set of the distribution.
3113 { return _M_param; }
3116 * @brief Sets the parameter set of the distribution.
3117 * @param __param The new parameter set of the distribution.
3120 param(const param_type& __param)
3121 { _M_param = __param; }
3124 * @brief Returns the greatest lower bound value of the distribution.
3128 { return std::numeric_limits<result_type>::min(); }
3131 * @brief Returns the least upper bound value of the distribution.
3135 { return std::numeric_limits<result_type>::max(); }
3138 * @brief Generating functions.
3140 template<typename _UniformRandomNumberGenerator>
3142 operator()(_UniformRandomNumberGenerator& __urng)
3143 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3145 template<typename _UniformRandomNumberGenerator>
3147 operator()(_UniformRandomNumberGenerator& __urng,
3148 const param_type& __p)
3150 typedef typename std::gamma_distribution<result_type>::param_type
3153 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3154 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3158 * @brief Return true if two Student t distributions have
3159 * the same parameters and the sequences that would
3160 * be generated are equal.
3162 template<typename _RealType1>
3164 operator==(const std::student_t_distribution<_RealType1>& __d1,
3165 const std::student_t_distribution<_RealType1>& __d2)
3166 { return (__d1.param() == __d2.param()
3167 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3170 * @brief Inserts a %student_t_distribution random number distribution
3171 * @p __x into the output stream @p __os.
3173 * @param __os An output stream.
3174 * @param __x A %student_t_distribution random number distribution.
3176 * @returns The output stream with the state of @p __x inserted or in
3179 template<typename _RealType1, typename _CharT, typename _Traits>
3180 friend std::basic_ostream<_CharT, _Traits>&
3181 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3182 const std::student_t_distribution<_RealType1>& __x);
3185 * @brief Extracts a %student_t_distribution random number distribution
3186 * @p __x from the input stream @p __is.
3188 * @param __is An input stream.
3189 * @param __x A %student_t_distribution random number
3192 * @returns The input stream with @p __x extracted or in an error state.
3194 template<typename _RealType1, typename _CharT, typename _Traits>
3195 friend std::basic_istream<_CharT, _Traits>&
3196 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3197 std::student_t_distribution<_RealType1>& __x);
3200 param_type _M_param;
3202 std::normal_distribution<result_type> _M_nd;
3203 std::gamma_distribution<result_type> _M_gd;
3207 * @brief Return true if two Student t distributions are different.
3209 template<typename _RealType>
3211 operator!=(const std::student_t_distribution<_RealType>& __d1,
3212 const std::student_t_distribution<_RealType>& __d2)
3213 { return !(__d1 == __d2); }
3216 /* @} */ // group random_distributions_normal
3219 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3220 * @ingroup random_distributions
3225 * @brief A Bernoulli random number distribution.
3227 * Generates a sequence of true and false values with likelihood @f$p@f$
3228 * that true will come up and @f$(1 - p)@f$ that false will appear.
3230 class bernoulli_distribution
3233 /** The type of the range of the distribution. */
3234 typedef bool result_type;
3235 /** Parameter type. */
3238 typedef bernoulli_distribution distribution_type;
3241 param_type(double __p = 0.5)
3244 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3252 operator==(const param_type& __p1, const param_type& __p2)
3253 { return __p1._M_p == __p2._M_p; }
3261 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3263 * @param __p [IN] The likelihood of a true result being returned.
3264 * Must be in the interval @f$[0, 1]@f$.
3267 bernoulli_distribution(double __p = 0.5)
3272 bernoulli_distribution(const param_type& __p)
3277 * @brief Resets the distribution state.
3279 * Does nothing for a Bernoulli distribution.
3285 * @brief Returns the @p p parameter of the distribution.
3289 { return _M_param.p(); }
3292 * @brief Returns the parameter set of the distribution.
3296 { return _M_param; }
3299 * @brief Sets the parameter set of the distribution.
3300 * @param __param The new parameter set of the distribution.
3303 param(const param_type& __param)
3304 { _M_param = __param; }
3307 * @brief Returns the greatest lower bound value of the distribution.
3311 { return std::numeric_limits<result_type>::min(); }
3314 * @brief Returns the least upper bound value of the distribution.
3318 { return std::numeric_limits<result_type>::max(); }
3321 * @brief Generating functions.
3323 template<typename _UniformRandomNumberGenerator>
3325 operator()(_UniformRandomNumberGenerator& __urng)
3326 { return this->operator()(__urng, this->param()); }
3328 template<typename _UniformRandomNumberGenerator>
3330 operator()(_UniformRandomNumberGenerator& __urng,
3331 const param_type& __p)
3333 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3335 if ((__aurng() - __aurng.min())
3336 < __p.p() * (__aurng.max() - __aurng.min()))
3342 param_type _M_param;
3346 * @brief Return true if two Bernoulli distributions have
3347 * the same parameters.
3350 operator==(const std::bernoulli_distribution& __d1,
3351 const std::bernoulli_distribution& __d2)
3352 { return __d1.param() == __d2.param(); }
3355 * @brief Return true if two Bernoulli distributions have
3356 * different parameters.
3359 operator!=(const std::bernoulli_distribution& __d1,
3360 const std::bernoulli_distribution& __d2)
3361 { return !(__d1 == __d2); }
3364 * @brief Inserts a %bernoulli_distribution random number distribution
3365 * @p __x into the output stream @p __os.
3367 * @param __os An output stream.
3368 * @param __x A %bernoulli_distribution random number distribution.
3370 * @returns The output stream with the state of @p __x inserted or in
3373 template<typename _CharT, typename _Traits>
3374 std::basic_ostream<_CharT, _Traits>&
3375 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3376 const std::bernoulli_distribution& __x);
3379 * @brief Extracts a %bernoulli_distribution random number distribution
3380 * @p __x from the input stream @p __is.
3382 * @param __is An input stream.
3383 * @param __x A %bernoulli_distribution random number generator engine.
3385 * @returns The input stream with @p __x extracted or in an error state.
3387 template<typename _CharT, typename _Traits>
3388 std::basic_istream<_CharT, _Traits>&
3389 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3390 std::bernoulli_distribution& __x)
3394 __x.param(bernoulli_distribution::param_type(__p));
3400 * @brief A discrete binomial random number distribution.
3402 * The formula for the binomial probability density function is
3403 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3404 * and @f$p@f$ are the parameters of the distribution.
3406 template<typename _IntType = int>
3407 class binomial_distribution
3409 static_assert(std::is_integral<_IntType>::value,
3410 "template argument not an integral type");
3413 /** The type of the range of the distribution. */
3414 typedef _IntType result_type;
3415 /** Parameter type. */
3418 typedef binomial_distribution<_IntType> distribution_type;
3419 friend class binomial_distribution<_IntType>;
3422 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3423 : _M_t(__t), _M_p(__p)
3425 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3440 operator==(const param_type& __p1, const param_type& __p2)
3441 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3451 #if _GLIBCXX_USE_C99_MATH_TR1
3452 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3453 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3458 // constructors and member function
3460 binomial_distribution(_IntType __t = _IntType(1),
3462 : _M_param(__t, __p), _M_nd()
3466 binomial_distribution(const param_type& __p)
3467 : _M_param(__p), _M_nd()
3471 * @brief Resets the distribution state.
3478 * @brief Returns the distribution @p t parameter.
3482 { return _M_param.t(); }
3485 * @brief Returns the distribution @p p parameter.
3489 { return _M_param.p(); }
3492 * @brief Returns the parameter set of the distribution.
3496 { return _M_param; }
3499 * @brief Sets the parameter set of the distribution.
3500 * @param __param The new parameter set of the distribution.
3503 param(const param_type& __param)
3504 { _M_param = __param; }
3507 * @brief Returns the greatest lower bound value of the distribution.
3514 * @brief Returns the least upper bound value of the distribution.
3518 { return _M_param.t(); }
3521 * @brief Generating functions.
3523 template<typename _UniformRandomNumberGenerator>
3525 operator()(_UniformRandomNumberGenerator& __urng)
3526 { return this->operator()(__urng, this->param()); }
3528 template<typename _UniformRandomNumberGenerator>
3530 operator()(_UniformRandomNumberGenerator& __urng,
3531 const param_type& __p);
3534 * @brief Return true if two binomial distributions have
3535 * the same parameters and the sequences that would
3536 * be generated are equal.
3538 template<typename _IntType1>
3540 operator==(const std::binomial_distribution<_IntType1>& __d1,
3541 const std::binomial_distribution<_IntType1>& __d2)
3542 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3543 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3545 { return __d1.param() == __d2.param(); }
3549 * @brief Inserts a %binomial_distribution random number distribution
3550 * @p __x into the output stream @p __os.
3552 * @param __os An output stream.
3553 * @param __x A %binomial_distribution random number distribution.
3555 * @returns The output stream with the state of @p __x inserted or in
3558 template<typename _IntType1,
3559 typename _CharT, typename _Traits>
3560 friend std::basic_ostream<_CharT, _Traits>&
3561 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3562 const std::binomial_distribution<_IntType1>& __x);
3565 * @brief Extracts a %binomial_distribution random number distribution
3566 * @p __x from the input stream @p __is.
3568 * @param __is An input stream.
3569 * @param __x A %binomial_distribution random number generator engine.
3571 * @returns The input stream with @p __x extracted or in an error
3574 template<typename _IntType1,
3575 typename _CharT, typename _Traits>
3576 friend std::basic_istream<_CharT, _Traits>&
3577 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3578 std::binomial_distribution<_IntType1>& __x);
3581 template<typename _UniformRandomNumberGenerator>
3583 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3585 param_type _M_param;
3587 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3588 std::normal_distribution<double> _M_nd;
3592 * @brief Return true if two binomial distributions are different.
3594 template<typename _IntType>
3596 operator!=(const std::binomial_distribution<_IntType>& __d1,
3597 const std::binomial_distribution<_IntType>& __d2)
3598 { return !(__d1 == __d2); }
3602 * @brief A discrete geometric random number distribution.
3604 * The formula for the geometric probability density function is
3605 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3608 template<typename _IntType = int>
3609 class geometric_distribution
3611 static_assert(std::is_integral<_IntType>::value,
3612 "template argument not an integral type");
3615 /** The type of the range of the distribution. */
3616 typedef _IntType result_type;
3617 /** Parameter type. */
3620 typedef geometric_distribution<_IntType> distribution_type;
3621 friend class geometric_distribution<_IntType>;
3624 param_type(double __p = 0.5)
3627 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
3636 operator==(const param_type& __p1, const param_type& __p2)
3637 { return __p1._M_p == __p2._M_p; }
3642 { _M_log_1_p = std::log(1.0 - _M_p); }
3649 // constructors and member function
3651 geometric_distribution(double __p = 0.5)
3656 geometric_distribution(const param_type& __p)
3661 * @brief Resets the distribution state.
3663 * Does nothing for the geometric distribution.
3669 * @brief Returns the distribution parameter @p p.
3673 { return _M_param.p(); }
3676 * @brief Returns the parameter set of the distribution.
3680 { return _M_param; }
3683 * @brief Sets the parameter set of the distribution.
3684 * @param __param The new parameter set of the distribution.
3687 param(const param_type& __param)
3688 { _M_param = __param; }
3691 * @brief Returns the greatest lower bound value of the distribution.
3698 * @brief Returns the least upper bound value of the distribution.
3702 { return std::numeric_limits<result_type>::max(); }
3705 * @brief Generating functions.
3707 template<typename _UniformRandomNumberGenerator>
3709 operator()(_UniformRandomNumberGenerator& __urng)
3710 { return this->operator()(__urng, this->param()); }
3712 template<typename _UniformRandomNumberGenerator>
3714 operator()(_UniformRandomNumberGenerator& __urng,
3715 const param_type& __p);
3718 param_type _M_param;
3722 * @brief Return true if two geometric distributions have
3723 * the same parameters.
3725 template<typename _IntType>
3727 operator==(const std::geometric_distribution<_IntType>& __d1,
3728 const std::geometric_distribution<_IntType>& __d2)
3729 { return __d1.param() == __d2.param(); }
3732 * @brief Return true if two geometric distributions have
3733 * different parameters.
3735 template<typename _IntType>
3737 operator!=(const std::geometric_distribution<_IntType>& __d1,
3738 const std::geometric_distribution<_IntType>& __d2)
3739 { return !(__d1 == __d2); }
3742 * @brief Inserts a %geometric_distribution random number distribution
3743 * @p __x into the output stream @p __os.
3745 * @param __os An output stream.
3746 * @param __x A %geometric_distribution random number distribution.
3748 * @returns The output stream with the state of @p __x inserted or in
3751 template<typename _IntType,
3752 typename _CharT, typename _Traits>
3753 std::basic_ostream<_CharT, _Traits>&
3754 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3755 const std::geometric_distribution<_IntType>& __x);
3758 * @brief Extracts a %geometric_distribution random number distribution
3759 * @p __x from the input stream @p __is.
3761 * @param __is An input stream.
3762 * @param __x A %geometric_distribution random number generator engine.
3764 * @returns The input stream with @p __x extracted or in an error state.
3766 template<typename _IntType,
3767 typename _CharT, typename _Traits>
3768 std::basic_istream<_CharT, _Traits>&
3769 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3770 std::geometric_distribution<_IntType>& __x);
3774 * @brief A negative_binomial_distribution random number distribution.
3776 * The formula for the negative binomial probability mass function is
3777 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3778 * and @f$p@f$ are the parameters of the distribution.
3780 template<typename _IntType = int>
3781 class negative_binomial_distribution
3783 static_assert(std::is_integral<_IntType>::value,
3784 "template argument not an integral type");
3787 /** The type of the range of the distribution. */
3788 typedef _IntType result_type;
3789 /** Parameter type. */
3792 typedef negative_binomial_distribution<_IntType> distribution_type;
3795 param_type(_IntType __k = 1, double __p = 0.5)
3796 : _M_k(__k), _M_p(__p)
3798 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
3810 operator==(const param_type& __p1, const param_type& __p2)
3811 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3819 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3820 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
3824 negative_binomial_distribution(const param_type& __p)
3825 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
3829 * @brief Resets the distribution state.
3836 * @brief Return the @f$k@f$ parameter of the distribution.
3840 { return _M_param.k(); }
3843 * @brief Return the @f$p@f$ parameter of the distribution.
3847 { return _M_param.p(); }
3850 * @brief Returns the parameter set of the distribution.
3854 { return _M_param; }
3857 * @brief Sets the parameter set of the distribution.
3858 * @param __param The new parameter set of the distribution.
3861 param(const param_type& __param)
3862 { _M_param = __param; }
3865 * @brief Returns the greatest lower bound value of the distribution.
3869 { return result_type(0); }
3872 * @brief Returns the least upper bound value of the distribution.
3876 { return std::numeric_limits<result_type>::max(); }
3879 * @brief Generating functions.
3881 template<typename _UniformRandomNumberGenerator>
3883 operator()(_UniformRandomNumberGenerator& __urng);
3885 template<typename _UniformRandomNumberGenerator>
3887 operator()(_UniformRandomNumberGenerator& __urng,
3888 const param_type& __p);
3891 * @brief Return true if two negative binomial distributions have
3892 * the same parameters and the sequences that would be
3893 * generated are equal.
3895 template<typename _IntType1>
3897 operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
3898 const std::negative_binomial_distribution<_IntType1>& __d2)
3899 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3902 * @brief Inserts a %negative_binomial_distribution random
3903 * number distribution @p __x into the output stream @p __os.
3905 * @param __os An output stream.
3906 * @param __x A %negative_binomial_distribution random number
3909 * @returns The output stream with the state of @p __x inserted or in
3912 template<typename _IntType1, typename _CharT, typename _Traits>
3913 friend std::basic_ostream<_CharT, _Traits>&
3914 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3915 const std::negative_binomial_distribution<_IntType1>& __x);
3918 * @brief Extracts a %negative_binomial_distribution random number
3919 * distribution @p __x from the input stream @p __is.
3921 * @param __is An input stream.
3922 * @param __x A %negative_binomial_distribution random number
3925 * @returns The input stream with @p __x extracted or in an error state.
3927 template<typename _IntType1, typename _CharT, typename _Traits>
3928 friend std::basic_istream<_CharT, _Traits>&
3929 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3930 std::negative_binomial_distribution<_IntType1>& __x);
3933 param_type _M_param;
3935 std::gamma_distribution<double> _M_gd;
3939 * @brief Return true if two negative binomial distributions are different.
3941 template<typename _IntType>
3943 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3944 const std::negative_binomial_distribution<_IntType>& __d2)
3945 { return !(__d1 == __d2); }
3948 /* @} */ // group random_distributions_bernoulli
3951 * @addtogroup random_distributions_poisson Poisson Distributions
3952 * @ingroup random_distributions
3957 * @brief A discrete Poisson random number distribution.
3959 * The formula for the Poisson probability density function is
3960 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3961 * parameter of the distribution.
3963 template<typename _IntType = int>
3964 class poisson_distribution
3966 static_assert(std::is_integral<_IntType>::value,
3967 "template argument not an integral type");
3970 /** The type of the range of the distribution. */
3971 typedef _IntType result_type;
3972 /** Parameter type. */
3975 typedef poisson_distribution<_IntType> distribution_type;
3976 friend class poisson_distribution<_IntType>;
3979 param_type(double __mean = 1.0)
3982 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3991 operator==(const param_type& __p1, const param_type& __p2)
3992 { return __p1._M_mean == __p2._M_mean; }
3995 // Hosts either log(mean) or the threshold of the simple method.
4002 #if _GLIBCXX_USE_C99_MATH_TR1
4003 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4007 // constructors and member function
4009 poisson_distribution(double __mean = 1.0)
4010 : _M_param(__mean), _M_nd()
4014 poisson_distribution(const param_type& __p)
4015 : _M_param(__p), _M_nd()
4019 * @brief Resets the distribution state.
4026 * @brief Returns the distribution parameter @p mean.
4030 { return _M_param.mean(); }
4033 * @brief Returns the parameter set of the distribution.
4037 { return _M_param; }
4040 * @brief Sets the parameter set of the distribution.
4041 * @param __param The new parameter set of the distribution.
4044 param(const param_type& __param)
4045 { _M_param = __param; }
4048 * @brief Returns the greatest lower bound value of the distribution.
4055 * @brief Returns the least upper bound value of the distribution.
4059 { return std::numeric_limits<result_type>::max(); }
4062 * @brief Generating functions.
4064 template<typename _UniformRandomNumberGenerator>
4066 operator()(_UniformRandomNumberGenerator& __urng)
4067 { return this->operator()(__urng, this->param()); }
4069 template<typename _UniformRandomNumberGenerator>
4071 operator()(_UniformRandomNumberGenerator& __urng,
4072 const param_type& __p);
4075 * @brief Return true if two Poisson distributions have the same
4076 * parameters and the sequences that would be generated
4079 template<typename _IntType1>
4081 operator==(const std::poisson_distribution<_IntType1>& __d1,
4082 const std::poisson_distribution<_IntType1>& __d2)
4083 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4084 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4086 { return __d1.param() == __d2.param(); }
4090 * @brief Inserts a %poisson_distribution random number distribution
4091 * @p __x into the output stream @p __os.
4093 * @param __os An output stream.
4094 * @param __x A %poisson_distribution random number distribution.
4096 * @returns The output stream with the state of @p __x inserted or in
4099 template<typename _IntType1, typename _CharT, typename _Traits>
4100 friend std::basic_ostream<_CharT, _Traits>&
4101 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4102 const std::poisson_distribution<_IntType1>& __x);
4105 * @brief Extracts a %poisson_distribution random number distribution
4106 * @p __x from the input stream @p __is.
4108 * @param __is An input stream.
4109 * @param __x A %poisson_distribution random number generator engine.
4111 * @returns The input stream with @p __x extracted or in an error
4114 template<typename _IntType1, typename _CharT, typename _Traits>
4115 friend std::basic_istream<_CharT, _Traits>&
4116 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4117 std::poisson_distribution<_IntType1>& __x);
4120 param_type _M_param;
4122 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4123 std::normal_distribution<double> _M_nd;
4127 * @brief Return true if two Poisson distributions are different.
4129 template<typename _IntType>
4131 operator!=(const std::poisson_distribution<_IntType>& __d1,
4132 const std::poisson_distribution<_IntType>& __d2)
4133 { return !(__d1 == __d2); }
4137 * @brief An exponential continuous distribution for random numbers.
4139 * The formula for the exponential probability density function is
4140 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4142 * <table border=1 cellpadding=10 cellspacing=0>
4143 * <caption align=top>Distribution Statistics</caption>
4144 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4145 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4146 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4147 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4148 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4151 template<typename _RealType = double>
4152 class exponential_distribution
4154 static_assert(std::is_floating_point<_RealType>::value,
4155 "template argument not a floating point type");
4158 /** The type of the range of the distribution. */
4159 typedef _RealType result_type;
4160 /** Parameter type. */
4163 typedef exponential_distribution<_RealType> distribution_type;
4166 param_type(_RealType __lambda = _RealType(1))
4167 : _M_lambda(__lambda)
4169 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4174 { return _M_lambda; }
4177 operator==(const param_type& __p1, const param_type& __p2)
4178 { return __p1._M_lambda == __p2._M_lambda; }
4181 _RealType _M_lambda;
4186 * @brief Constructs an exponential distribution with inverse scale
4187 * parameter @f$\lambda@f$.
4190 exponential_distribution(const result_type& __lambda = result_type(1))
4191 : _M_param(__lambda)
4195 exponential_distribution(const param_type& __p)
4200 * @brief Resets the distribution state.
4202 * Has no effect on exponential distributions.
4208 * @brief Returns the inverse scale parameter of the distribution.
4212 { return _M_param.lambda(); }
4215 * @brief Returns the parameter set of the distribution.
4219 { return _M_param; }
4222 * @brief Sets the parameter set of the distribution.
4223 * @param __param The new parameter set of the distribution.
4226 param(const param_type& __param)
4227 { _M_param = __param; }
4230 * @brief Returns the greatest lower bound value of the distribution.
4234 { return result_type(0); }
4237 * @brief Returns the least upper bound value of the distribution.
4241 { return std::numeric_limits<result_type>::max(); }
4244 * @brief Generating functions.
4246 template<typename _UniformRandomNumberGenerator>
4248 operator()(_UniformRandomNumberGenerator& __urng)
4249 { return this->operator()(__urng, this->param()); }
4251 template<typename _UniformRandomNumberGenerator>
4253 operator()(_UniformRandomNumberGenerator& __urng,
4254 const param_type& __p)
4256 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4258 return -std::log(__aurng()) / __p.lambda();
4262 param_type _M_param;
4266 * @brief Return true if two exponential distributions have the same
4269 template<typename _RealType>
4271 operator==(const std::exponential_distribution<_RealType>& __d1,
4272 const std::exponential_distribution<_RealType>& __d2)
4273 { return __d1.param() == __d2.param(); }
4276 * @brief Return true if two exponential distributions have different
4279 template<typename _RealType>
4281 operator!=(const std::exponential_distribution<_RealType>& __d1,
4282 const std::exponential_distribution<_RealType>& __d2)
4283 { return !(__d1 == __d2); }
4286 * @brief Inserts a %exponential_distribution random number distribution
4287 * @p __x into the output stream @p __os.
4289 * @param __os An output stream.
4290 * @param __x A %exponential_distribution random number distribution.
4292 * @returns The output stream with the state of @p __x inserted or in
4295 template<typename _RealType, typename _CharT, typename _Traits>
4296 std::basic_ostream<_CharT, _Traits>&
4297 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4298 const std::exponential_distribution<_RealType>& __x);
4301 * @brief Extracts a %exponential_distribution random number distribution
4302 * @p __x from the input stream @p __is.
4304 * @param __is An input stream.
4305 * @param __x A %exponential_distribution random number
4308 * @returns The input stream with @p __x extracted or in an error state.
4310 template<typename _RealType, typename _CharT, typename _Traits>
4311 std::basic_istream<_CharT, _Traits>&
4312 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4313 std::exponential_distribution<_RealType>& __x);
4317 * @brief A weibull_distribution random number distribution.
4319 * The formula for the normal probability density function is:
4321 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4322 * \exp{(-(\frac{x}{\beta})^\alpha)}
4325 template<typename _RealType = double>
4326 class weibull_distribution
4328 static_assert(std::is_floating_point<_RealType>::value,
4329 "template argument not a floating point type");
4332 /** The type of the range of the distribution. */
4333 typedef _RealType result_type;
4334 /** Parameter type. */
4337 typedef weibull_distribution<_RealType> distribution_type;
4340 param_type(_RealType __a = _RealType(1),
4341 _RealType __b = _RealType(1))
4342 : _M_a(__a), _M_b(__b)
4354 operator==(const param_type& __p1, const param_type& __p2)
4355 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4363 weibull_distribution(_RealType __a = _RealType(1),
4364 _RealType __b = _RealType(1))
4365 : _M_param(__a, __b)
4369 weibull_distribution(const param_type& __p)
4374 * @brief Resets the distribution state.
4381 * @brief Return the @f$a@f$ parameter of the distribution.
4385 { return _M_param.a(); }
4388 * @brief Return the @f$b@f$ parameter of the distribution.
4392 { return _M_param.b(); }
4395 * @brief Returns the parameter set of the distribution.
4399 { return _M_param; }
4402 * @brief Sets the parameter set of the distribution.
4403 * @param __param The new parameter set of the distribution.
4406 param(const param_type& __param)
4407 { _M_param = __param; }
4410 * @brief Returns the greatest lower bound value of the distribution.
4414 { return result_type(0); }
4417 * @brief Returns the least upper bound value of the distribution.
4421 { return std::numeric_limits<result_type>::max(); }
4424 * @brief Generating functions.
4426 template<typename _UniformRandomNumberGenerator>
4428 operator()(_UniformRandomNumberGenerator& __urng)
4429 { return this->operator()(__urng, this->param()); }
4431 template<typename _UniformRandomNumberGenerator>
4433 operator()(_UniformRandomNumberGenerator& __urng,
4434 const param_type& __p);
4437 param_type _M_param;
4441 * @brief Return true if two Weibull distributions have the same
4444 template<typename _RealType>
4446 operator==(const std::weibull_distribution<_RealType>& __d1,
4447 const std::weibull_distribution<_RealType>& __d2)
4448 { return __d1.param() == __d2.param(); }
4451 * @brief Return true if two Weibull distributions have different
4454 template<typename _RealType>
4456 operator!=(const std::weibull_distribution<_RealType>& __d1,
4457 const std::weibull_distribution<_RealType>& __d2)
4458 { return !(__d1 == __d2); }
4461 * @brief Inserts a %weibull_distribution random number distribution
4462 * @p __x into the output stream @p __os.
4464 * @param __os An output stream.
4465 * @param __x A %weibull_distribution random number distribution.
4467 * @returns The output stream with the state of @p __x inserted or in
4470 template<typename _RealType, typename _CharT, typename _Traits>
4471 std::basic_ostream<_CharT, _Traits>&
4472 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4473 const std::weibull_distribution<_RealType>& __x);
4476 * @brief Extracts a %weibull_distribution random number distribution
4477 * @p __x from the input stream @p __is.
4479 * @param __is An input stream.
4480 * @param __x A %weibull_distribution random number
4483 * @returns The input stream with @p __x extracted or in an error state.
4485 template<typename _RealType, typename _CharT, typename _Traits>
4486 std::basic_istream<_CharT, _Traits>&
4487 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4488 std::weibull_distribution<_RealType>& __x);
4492 * @brief A extreme_value_distribution random number distribution.
4494 * The formula for the normal probability mass function is
4496 * p(x|a,b) = \frac{1}{b}
4497 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4500 template<typename _RealType = double>
4501 class extreme_value_distribution
4503 static_assert(std::is_floating_point<_RealType>::value,
4504 "template argument not a floating point type");
4507 /** The type of the range of the distribution. */
4508 typedef _RealType result_type;
4509 /** Parameter type. */
4512 typedef extreme_value_distribution<_RealType> distribution_type;
4515 param_type(_RealType __a = _RealType(0),
4516 _RealType __b = _RealType(1))
4517 : _M_a(__a), _M_b(__b)
4529 operator==(const param_type& __p1, const param_type& __p2)
4530 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4538 extreme_value_distribution(_RealType __a = _RealType(0),
4539 _RealType __b = _RealType(1))
4540 : _M_param(__a, __b)
4544 extreme_value_distribution(const param_type& __p)
4549 * @brief Resets the distribution state.
4556 * @brief Return the @f$a@f$ parameter of the distribution.
4560 { return _M_param.a(); }
4563 * @brief Return the @f$b@f$ parameter of the distribution.
4567 { return _M_param.b(); }
4570 * @brief Returns the parameter set of the distribution.
4574 { return _M_param; }
4577 * @brief Sets the parameter set of the distribution.
4578 * @param __param The new parameter set of the distribution.
4581 param(const param_type& __param)
4582 { _M_param = __param; }
4585 * @brief Returns the greatest lower bound value of the distribution.
4589 { return std::numeric_limits<result_type>::min(); }
4592 * @brief Returns the least upper bound value of the distribution.
4596 { return std::numeric_limits<result_type>::max(); }
4599 * @brief Generating functions.
4601 template<typename _UniformRandomNumberGenerator>
4603 operator()(_UniformRandomNumberGenerator& __urng)
4604 { return this->operator()(__urng, this->param()); }
4606 template<typename _UniformRandomNumberGenerator>
4608 operator()(_UniformRandomNumberGenerator& __urng,
4609 const param_type& __p);
4612 param_type _M_param;
4616 * @brief Return true if two extreme value distributions have the same
4619 template<typename _RealType>
4621 operator==(const std::extreme_value_distribution<_RealType>& __d1,
4622 const std::extreme_value_distribution<_RealType>& __d2)
4623 { return __d1.param() == __d2.param(); }
4626 * @brief Return true if two extreme value distributions have different
4629 template<typename _RealType>
4631 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4632 const std::extreme_value_distribution<_RealType>& __d2)
4633 { return !(__d1 == __d2); }
4636 * @brief Inserts a %extreme_value_distribution random number distribution
4637 * @p __x into the output stream @p __os.
4639 * @param __os An output stream.
4640 * @param __x A %extreme_value_distribution random number distribution.
4642 * @returns The output stream with the state of @p __x inserted or in
4645 template<typename _RealType, typename _CharT, typename _Traits>
4646 std::basic_ostream<_CharT, _Traits>&
4647 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4648 const std::extreme_value_distribution<_RealType>& __x);
4651 * @brief Extracts a %extreme_value_distribution random number
4652 * distribution @p __x from the input stream @p __is.
4654 * @param __is An input stream.
4655 * @param __x A %extreme_value_distribution random number
4658 * @returns The input stream with @p __x extracted or in an error state.
4660 template<typename _RealType, typename _CharT, typename _Traits>
4661 std::basic_istream<_CharT, _Traits>&
4662 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4663 std::extreme_value_distribution<_RealType>& __x);
4667 * @brief A discrete_distribution random number distribution.
4669 * The formula for the discrete probability mass function is
4672 template<typename _IntType = int>
4673 class discrete_distribution
4675 static_assert(std::is_integral<_IntType>::value,
4676 "template argument not an integral type");
4679 /** The type of the range of the distribution. */
4680 typedef _IntType result_type;
4681 /** Parameter type. */
4684 typedef discrete_distribution<_IntType> distribution_type;
4685 friend class discrete_distribution<_IntType>;
4688 : _M_prob(), _M_cp()
4691 template<typename _InputIterator>
4692 param_type(_InputIterator __wbegin,
4693 _InputIterator __wend)
4694 : _M_prob(__wbegin, __wend), _M_cp()
4695 { _M_initialize(); }
4697 param_type(initializer_list<double> __wil)
4698 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4699 { _M_initialize(); }
4701 template<typename _Func>
4702 param_type(size_t __nw, double __xmin, double __xmax,
4705 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4706 param_type(const param_type&) = default;
4707 param_type& operator=(const param_type&) = default;
4710 probabilities() const
4711 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4714 operator==(const param_type& __p1, const param_type& __p2)
4715 { return __p1._M_prob == __p2._M_prob; }
4721 std::vector<double> _M_prob;
4722 std::vector<double> _M_cp;
4725 discrete_distribution()
4729 template<typename _InputIterator>
4730 discrete_distribution(_InputIterator __wbegin,
4731 _InputIterator __wend)
4732 : _M_param(__wbegin, __wend)
4735 discrete_distribution(initializer_list<double> __wl)
4739 template<typename _Func>
4740 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4742 : _M_param(__nw, __xmin, __xmax, __fw)
4746 discrete_distribution(const param_type& __p)
4751 * @brief Resets the distribution state.
4758 * @brief Returns the probabilities of the distribution.
4761 probabilities() const
4763 return _M_param._M_prob.empty()
4764 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4768 * @brief Returns the parameter set of the distribution.
4772 { return _M_param; }
4775 * @brief Sets the parameter set of the distribution.
4776 * @param __param The new parameter set of the distribution.
4779 param(const param_type& __param)
4780 { _M_param = __param; }
4783 * @brief Returns the greatest lower bound value of the distribution.
4787 { return result_type(0); }
4790 * @brief Returns the least upper bound value of the distribution.
4795 return _M_param._M_prob.empty()
4796 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4800 * @brief Generating functions.
4802 template<typename _UniformRandomNumberGenerator>
4804 operator()(_UniformRandomNumberGenerator& __urng)
4805 { return this->operator()(__urng, this->param()); }
4807 template<typename _UniformRandomNumberGenerator>
4809 operator()(_UniformRandomNumberGenerator& __urng,
4810 const param_type& __p);
4813 * @brief Inserts a %discrete_distribution random number distribution
4814 * @p __x into the output stream @p __os.
4816 * @param __os An output stream.
4817 * @param __x A %discrete_distribution random number distribution.
4819 * @returns The output stream with the state of @p __x inserted or in
4822 template<typename _IntType1, typename _CharT, typename _Traits>
4823 friend std::basic_ostream<_CharT, _Traits>&
4824 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4825 const std::discrete_distribution<_IntType1>& __x);
4828 * @brief Extracts a %discrete_distribution random number distribution
4829 * @p __x from the input stream @p __is.
4831 * @param __is An input stream.
4832 * @param __x A %discrete_distribution random number
4835 * @returns The input stream with @p __x extracted or in an error
4838 template<typename _IntType1, typename _CharT, typename _Traits>
4839 friend std::basic_istream<_CharT, _Traits>&
4840 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4841 std::discrete_distribution<_IntType1>& __x);
4844 param_type _M_param;
4848 * @brief Return true if two discrete distributions have the same
4851 template<typename _IntType>
4853 operator==(const std::discrete_distribution<_IntType>& __d1,
4854 const std::discrete_distribution<_IntType>& __d2)
4855 { return __d1.param() == __d2.param(); }
4858 * @brief Return true if two discrete distributions have different
4861 template<typename _IntType>
4863 operator!=(const std::discrete_distribution<_IntType>& __d1,
4864 const std::discrete_distribution<_IntType>& __d2)
4865 { return !(__d1 == __d2); }
4869 * @brief A piecewise_constant_distribution random number distribution.
4871 * The formula for the piecewise constant probability mass function is
4874 template<typename _RealType = double>
4875 class piecewise_constant_distribution
4877 static_assert(std::is_floating_point<_RealType>::value,
4878 "template argument not a floating point type");
4881 /** The type of the range of the distribution. */
4882 typedef _RealType result_type;
4883 /** Parameter type. */
4886 typedef piecewise_constant_distribution<_RealType> distribution_type;
4887 friend class piecewise_constant_distribution<_RealType>;
4890 : _M_int(), _M_den(), _M_cp()
4893 template<typename _InputIteratorB, typename _InputIteratorW>
4894 param_type(_InputIteratorB __bfirst,
4895 _InputIteratorB __bend,
4896 _InputIteratorW __wbegin);
4898 template<typename _Func>
4899 param_type(initializer_list<_RealType> __bi, _Func __fw);
4901 template<typename _Func>
4902 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4905 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4906 param_type(const param_type&) = default;
4907 param_type& operator=(const param_type&) = default;
4909 std::vector<_RealType>
4914 std::vector<_RealType> __tmp(2);
4915 __tmp[1] = _RealType(1);
4924 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4927 operator==(const param_type& __p1, const param_type& __p2)
4928 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4934 std::vector<_RealType> _M_int;
4935 std::vector<double> _M_den;
4936 std::vector<double> _M_cp;
4940 piecewise_constant_distribution()
4944 template<typename _InputIteratorB, typename _InputIteratorW>
4945 piecewise_constant_distribution(_InputIteratorB __bfirst,
4946 _InputIteratorB __bend,
4947 _InputIteratorW __wbegin)
4948 : _M_param(__bfirst, __bend, __wbegin)
4951 template<typename _Func>
4952 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4954 : _M_param(__bl, __fw)
4957 template<typename _Func>
4958 piecewise_constant_distribution(size_t __nw,
4959 _RealType __xmin, _RealType __xmax,
4961 : _M_param(__nw, __xmin, __xmax, __fw)
4965 piecewise_constant_distribution(const param_type& __p)
4970 * @brief Resets the distribution state.
4977 * @brief Returns a vector of the intervals.
4979 std::vector<_RealType>
4982 if (_M_param._M_int.empty())
4984 std::vector<_RealType> __tmp(2);
4985 __tmp[1] = _RealType(1);
4989 return _M_param._M_int;
4993 * @brief Returns a vector of the probability densities.
4998 return _M_param._M_den.empty()
4999 ? std::vector<double>(1, 1.0) : _M_param._M_den;
5003 * @brief Returns the parameter set of the distribution.
5007 { return _M_param; }
5010 * @brief Sets the parameter set of the distribution.
5011 * @param __param The new parameter set of the distribution.
5014 param(const param_type& __param)
5015 { _M_param = __param; }
5018 * @brief Returns the greatest lower bound value of the distribution.
5023 return _M_param._M_int.empty()
5024 ? result_type(0) : _M_param._M_int.front();
5028 * @brief Returns the least upper bound value of the distribution.
5033 return _M_param._M_int.empty()
5034 ? result_type(1) : _M_param._M_int.back();
5038 * @brief Generating functions.
5040 template<typename _UniformRandomNumberGenerator>
5042 operator()(_UniformRandomNumberGenerator& __urng)
5043 { return this->operator()(__urng, this->param()); }
5045 template<typename _UniformRandomNumberGenerator>
5047 operator()(_UniformRandomNumberGenerator& __urng,
5048 const param_type& __p);
5051 * @brief Inserts a %piecewise_constan_distribution random
5052 * number distribution @p __x into the output stream @p __os.
5054 * @param __os An output stream.
5055 * @param __x A %piecewise_constan_distribution random number
5058 * @returns The output stream with the state of @p __x inserted or in
5061 template<typename _RealType1, typename _CharT, typename _Traits>
5062 friend std::basic_ostream<_CharT, _Traits>&
5063 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5064 const std::piecewise_constant_distribution<_RealType1>& __x);
5067 * @brief Extracts a %piecewise_constan_distribution random
5068 * number distribution @p __x from the input stream @p __is.
5070 * @param __is An input stream.
5071 * @param __x A %piecewise_constan_distribution random number
5074 * @returns The input stream with @p __x extracted or in an error
5077 template<typename _RealType1, typename _CharT, typename _Traits>
5078 friend std::basic_istream<_CharT, _Traits>&
5079 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5080 std::piecewise_constant_distribution<_RealType1>& __x);
5083 param_type _M_param;
5087 * @brief Return true if two piecewise constant distributions have the
5090 template<typename _RealType>
5092 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
5093 const std::piecewise_constant_distribution<_RealType>& __d2)
5094 { return __d1.param() == __d2.param(); }
5097 * @brief Return true if two piecewise constant distributions have
5098 * different parameters.
5100 template<typename _RealType>
5102 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5103 const std::piecewise_constant_distribution<_RealType>& __d2)
5104 { return !(__d1 == __d2); }
5108 * @brief A piecewise_linear_distribution random number distribution.
5110 * The formula for the piecewise linear probability mass function is
5113 template<typename _RealType = double>
5114 class piecewise_linear_distribution
5116 static_assert(std::is_floating_point<_RealType>::value,
5117 "template argument not a floating point type");
5120 /** The type of the range of the distribution. */
5121 typedef _RealType result_type;
5122 /** Parameter type. */
5125 typedef piecewise_linear_distribution<_RealType> distribution_type;
5126 friend class piecewise_linear_distribution<_RealType>;
5129 : _M_int(), _M_den(), _M_cp(), _M_m()
5132 template<typename _InputIteratorB, typename _InputIteratorW>
5133 param_type(_InputIteratorB __bfirst,
5134 _InputIteratorB __bend,
5135 _InputIteratorW __wbegin);
5137 template<typename _Func>
5138 param_type(initializer_list<_RealType> __bl, _Func __fw);
5140 template<typename _Func>
5141 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5144 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5145 param_type(const param_type&) = default;
5146 param_type& operator=(const param_type&) = default;
5148 std::vector<_RealType>
5153 std::vector<_RealType> __tmp(2);
5154 __tmp[1] = _RealType(1);
5163 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5166 operator==(const param_type& __p1, const param_type& __p2)
5167 { return (__p1._M_int == __p2._M_int
5168 && __p1._M_den == __p2._M_den); }
5174 std::vector<_RealType> _M_int;
5175 std::vector<double> _M_den;
5176 std::vector<double> _M_cp;
5177 std::vector<double> _M_m;
5181 piecewise_linear_distribution()
5185 template<typename _InputIteratorB, typename _InputIteratorW>
5186 piecewise_linear_distribution(_InputIteratorB __bfirst,
5187 _InputIteratorB __bend,
5188 _InputIteratorW __wbegin)
5189 : _M_param(__bfirst, __bend, __wbegin)
5192 template<typename _Func>
5193 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5195 : _M_param(__bl, __fw)
5198 template<typename _Func>
5199 piecewise_linear_distribution(size_t __nw,
5200 _RealType __xmin, _RealType __xmax,
5202 : _M_param(__nw, __xmin, __xmax, __fw)
5206 piecewise_linear_distribution(const param_type& __p)
5211 * Resets the distribution state.
5218 * @brief Return the intervals of the distribution.
5220 std::vector<_RealType>
5223 if (_M_param._M_int.empty())
5225 std::vector<_RealType> __tmp(2);
5226 __tmp[1] = _RealType(1);
5230 return _M_param._M_int;
5234 * @brief Return a vector of the probability densities of the
5240 return _M_param._M_den.empty()
5241 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5245 * @brief Returns the parameter set of the distribution.
5249 { return _M_param; }
5252 * @brief Sets the parameter set of the distribution.
5253 * @param __param The new parameter set of the distribution.
5256 param(const param_type& __param)
5257 { _M_param = __param; }
5260 * @brief Returns the greatest lower bound value of the distribution.
5265 return _M_param._M_int.empty()
5266 ? result_type(0) : _M_param._M_int.front();
5270 * @brief Returns the least upper bound value of the distribution.
5275 return _M_param._M_int.empty()
5276 ? result_type(1) : _M_param._M_int.back();
5280 * @brief Generating functions.
5282 template<typename _UniformRandomNumberGenerator>
5284 operator()(_UniformRandomNumberGenerator& __urng)
5285 { return this->operator()(__urng, this->param()); }
5287 template<typename _UniformRandomNumberGenerator>
5289 operator()(_UniformRandomNumberGenerator& __urng,
5290 const param_type& __p);
5293 * @brief Inserts a %piecewise_linear_distribution random number
5294 * distribution @p __x into the output stream @p __os.
5296 * @param __os An output stream.
5297 * @param __x A %piecewise_linear_distribution random number
5300 * @returns The output stream with the state of @p __x inserted or in
5303 template<typename _RealType1, typename _CharT, typename _Traits>
5304 friend std::basic_ostream<_CharT, _Traits>&
5305 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5306 const std::piecewise_linear_distribution<_RealType1>& __x);
5309 * @brief Extracts a %piecewise_linear_distribution random number
5310 * distribution @p __x from the input stream @p __is.
5312 * @param __is An input stream.
5313 * @param __x A %piecewise_linear_distribution random number
5316 * @returns The input stream with @p __x extracted or in an error
5319 template<typename _RealType1, typename _CharT, typename _Traits>
5320 friend std::basic_istream<_CharT, _Traits>&
5321 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5322 std::piecewise_linear_distribution<_RealType1>& __x);
5325 param_type _M_param;
5329 * @brief Return true if two piecewise linear distributions have the
5332 template<typename _RealType>
5334 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
5335 const std::piecewise_linear_distribution<_RealType>& __d2)
5336 { return __d1.param() == __d2.param(); }
5339 * @brief Return true if two piecewise linear distributions have
5340 * different parameters.
5342 template<typename _RealType>
5344 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5345 const std::piecewise_linear_distribution<_RealType>& __d2)
5346 { return !(__d1 == __d2); }
5349 /* @} */ // group random_distributions_poisson
5351 /* @} */ // group random_distributions
5354 * @addtogroup random_utilities Random Number Utilities
5360 * @brief The seed_seq class generates sequences of seeds for random
5361 * number generators.
5367 /** The type of the seed vales. */
5368 typedef uint_least32_t result_type;
5370 /** Default constructor. */
5375 template<typename _IntType>
5376 seed_seq(std::initializer_list<_IntType> il);
5378 template<typename _InputIterator>
5379 seed_seq(_InputIterator __begin, _InputIterator __end);
5381 // generating functions
5382 template<typename _RandomAccessIterator>
5384 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5386 // property functions
5388 { return _M_v.size(); }
5390 template<typename OutputIterator>
5392 param(OutputIterator __dest) const
5393 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5397 std::vector<result_type> _M_v;
5400 /* @} */ // group random_utilities
5402 /* @} */ // group random
5404 _GLIBCXX_END_NAMESPACE_VERSION