1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * This is an internal header file, included by other library headers.
28 * You should not attempt to use it directly.
36 // [26.4] Random number generation
39 * @addtogroup std_random Random Number Generation
40 * A facility for generating random numbers on selected distributions.
45 * @brief A function template for converting the output of a (integral)
46 * uniform random number generator to a floatng point result in the range
49 template<typename _RealType, size_t __bits,
50 typename _UniformRandomNumberGenerator>
52 generate_canonical(_UniformRandomNumberGenerator& __g);
57 * Implementation-space details.
61 template<typename _UIntType, size_t __w,
62 bool = __w < static_cast<size_t>
63 (std::numeric_limits<_UIntType>::digits)>
65 { static const _UIntType __value = 0; };
67 template<typename _UIntType, size_t __w>
68 struct _Shift<_UIntType, __w, true>
69 { static const _UIntType __value = _UIntType(1) << __w; };
71 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
74 // Dispatch based on modulus value to prevent divide-by-zero compile-time
75 // errors when m == 0.
76 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
79 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
82 * An adaptor class for converting the output of any Generator into
83 * the input for a specific Distribution.
85 template<typename _Engine, typename _DInputType>
90 _Adaptor(_Engine& __g)
95 { return _DInputType(0); }
99 { return _DInputType(1); }
102 * Converts a value generated by the adapted random number generator
103 * into a value in the input domain for the dependent random number
109 return std::generate_canonical<_DInputType,
110 std::numeric_limits<_DInputType>::digits,
117 } // namespace __detail
120 * @addtogroup std_random_generators Random Number Generators
121 * @ingroup std_random
123 * These classes define objects which provide random or pseudorandom
124 * numbers, either from a discrete or a continuous interval. The
125 * random number generator supplied as a part of this library are
126 * all uniform random number generators which provide a sequence of
127 * random number uniformly distributed over their range.
129 * A number generator is a function object with an operator() that
130 * takes zero arguments and returns a number.
132 * A compliant random number generator must satisfy the following
133 * requirements. <table border=1 cellpadding=10 cellspacing=0>
134 * <caption align=top>Random Number Generator Requirements</caption>
135 * <tr><td>To be documented.</td></tr> </table>
141 * @brief A model of a linear congruential random number generator.
143 * A random number generator that produces pseudorandom numbers using the
144 * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
146 * The template parameter @p _UIntType must be an unsigned integral type
147 * large enough to store values up to (__m-1). If the template parameter
148 * @p __m is 0, the modulus @p __m used is
149 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
150 * parameters @p __a and @p __c must be less than @p __m.
152 * The size of the state is @f$ 1 @f$.
154 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
155 class linear_congruential_engine
157 __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
158 static_assert(__m == 0 || (__a < __m && __c < __m),
159 "template arguments out of bounds"
160 " in linear_congruential_engine");
163 /** The type of the generated random value. */
164 typedef _UIntType result_type;
166 /** The multiplier. */
167 static const result_type multiplier = __a;
169 static const result_type increment = __c;
171 static const result_type modulus = __m;
172 static const result_type default_seed = 1u;
175 * @brief Constructs a %linear_congruential_engine random number
176 * generator engine with seed @p __s. The default seed value
179 * @param __s The initial seed value.
182 linear_congruential_engine(result_type __s = default_seed)
186 * @brief Constructs a %linear_congruential_engine random number
187 * generator engine seeded from the seed sequence @p __q.
189 * @param __q the seed sequence.
192 linear_congruential_engine(seed_seq& __q)
196 * @brief Reseeds the %linear_congruential_engine random number generator
197 * engine sequence to the seed @p __s.
199 * @param __s The new seed.
202 seed(result_type __s = default_seed);
205 * @brief Reseeds the %linear_congruential_engine random number generator
207 * sequence using values from the seed sequence @p __q.
209 * @param __q the seed sequence.
215 * @brief Gets the smallest possible value in the output range.
217 * The minimum depends on the @p __c parameter: if it is zero, the
218 * minimum generated must be > 0, otherwise 0 is allowed.
220 * @todo This should be constexpr.
224 { return __c == 0u ? 1u : 0u; }
227 * @brief Gets the largest possible value in the output range.
229 * @todo This should be constexpr.
236 * @brief Discard a sequence of random numbers.
238 * @todo Look for a faster way to do discard.
241 discard(unsigned long long __z)
243 for (; __z != 0ULL; --__z)
248 * @brief Gets the next random number in the sequence.
253 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
258 * @brief Compares two linear congruential random number generator
259 * objects of the same type for equality.
261 * @param __lhs A linear congruential random number generator object.
262 * @param __rhs Another linear congruential random number generator
265 * @returns true if the two objects are equal, false otherwise.
268 operator==(const linear_congruential_engine& __lhs,
269 const linear_congruential_engine& __rhs)
270 { return __lhs._M_x == __rhs._M_x; }
273 * @brief Writes the textual representation of the state x(i) of x to
276 * @param __os The output stream.
277 * @param __lcr A % linear_congruential_engine random number generator.
280 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
281 _UIntType1 __m1, typename _CharT, typename _Traits>
282 friend std::basic_ostream<_CharT, _Traits>&
283 operator<<(std::basic_ostream<_CharT, _Traits>&,
284 const std::linear_congruential_engine<_UIntType1,
288 * @brief Sets the state of the engine by reading its textual
289 * representation from @p __is.
291 * The textual representation must have been previously written using
292 * an output stream whose imbued locale and whose type's template
293 * specialization arguments _CharT and _Traits were the same as those
296 * @param __is The input stream.
297 * @param __lcr A % linear_congruential_engine random number generator.
300 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
301 _UIntType1 __m1, typename _CharT, typename _Traits>
302 friend std::basic_istream<_CharT, _Traits>&
303 operator>>(std::basic_istream<_CharT, _Traits>&,
304 std::linear_congruential_engine<_UIntType1, __a1,
313 * A generalized feedback shift register discrete random number generator.
315 * This algorithm avoids multiplication and division and is designed to be
316 * friendly to a pipelined architecture. If the parameters are chosen
317 * correctly, this generator will produce numbers with a very long period and
318 * fairly good apparent entropy, although still not cryptographically strong.
320 * The best way to use this generator is with the predefined mt19937 class.
322 * This algorithm was originally invented by Makoto Matsumoto and
325 * @var word_size The number of bits in each element of the state vector.
326 * @var state_size The degree of recursion.
327 * @var shift_size The period parameter.
328 * @var mask_bits The separation point bit index.
329 * @var parameter_a The last row of the twist matrix.
330 * @var output_u The first right-shift tempering matrix parameter.
331 * @var output_s The first left-shift tempering matrix parameter.
332 * @var output_b The first left-shift tempering matrix mask.
333 * @var output_t The second left-shift tempering matrix parameter.
334 * @var output_c The second left-shift tempering matrix mask.
335 * @var output_l The second right-shift tempering matrix parameter.
337 template<typename _UIntType, size_t __w,
338 size_t __n, size_t __m, size_t __r,
339 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
340 _UIntType __b, size_t __t,
341 _UIntType __c, size_t __l, _UIntType __f>
342 class mersenne_twister_engine
344 __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
346 static_assert(__m >= 1U,
347 "mersenne_twister_engine template arguments out of bounds");
348 static_assert(__n >= __m,
349 "mersenne_twister_engine template arguments out of bounds");
350 static_assert(__w >= __r,
351 "mersenne_twister_engine template arguments out of bounds");
352 static_assert(__w >= __u,
353 "mersenne_twister_engine template arguments out of bounds");
354 static_assert(__w >= __s,
355 "mersenne_twister_engine template arguments out of bounds");
356 static_assert(__w >= __t,
357 "mersenne_twister_engine template arguments out of bounds");
358 static_assert(__w >= __l,
359 "mersenne_twister_engine template arguments out of bounds");
361 static_cast<size_t>(std::numeric_limits<_UIntType>::digits),
362 "mersenne_twister_engine template arguments out of bounds");
363 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
364 "mersenne_twister_engine template arguments out of bounds");
365 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
366 "mersenne_twister_engine template arguments out of bounds");
367 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
368 "mersenne_twister_engine template arguments out of bounds");
369 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
370 "mersenne_twister_engine template arguments out of bounds");
371 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
372 "mersenne_twister_engine template arguments out of bounds");
375 /** The type of the generated random value. */
376 typedef _UIntType result_type;
379 static const size_t word_size = __w;
380 static const size_t state_size = __n;
381 static const size_t shift_size = __m;
382 static const size_t mask_bits = __r;
383 static const result_type xor_mask = __a;
384 static const size_t tempering_u = __u;
385 static const result_type tempering_d = __d;
386 static const size_t tempering_s = __s;
387 static const result_type tempering_b = __b;
388 static const size_t tempering_t = __t;
389 static const result_type tempering_c = __c;
390 static const size_t tempering_l = __l;
391 static const result_type initialization_multiplier = __f;
392 static const result_type default_seed = 5489u;
394 // constructors and member function
396 mersenne_twister_engine(result_type __sd = default_seed)
400 * @brief Constructs a %mersenne_twister_engine random number generator
401 * engine seeded from the seed sequence @p __q.
403 * @param __q the seed sequence.
406 mersenne_twister_engine(seed_seq& __q)
410 seed(result_type __sd = default_seed);
416 * @brief Gets the smallest possible value in the output range.
418 * @todo This should be constexpr.
425 * @brief Gets the largest possible value in the output range.
427 * @todo This should be constexpr.
431 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
434 * @brief Discard a sequence of random numbers.
436 * @todo Look for a faster way to do discard.
439 discard(unsigned long long __z)
441 for (; __z != 0ULL; --__z)
449 * @brief Compares two % mersenne_twister_engine random number generator
450 * objects of the same type for equality.
452 * @param __lhs A % mersenne_twister_engine random number generator
454 * @param __rhs Another % mersenne_twister_engine random number
457 * @returns true if the two objects are equal, false otherwise.
460 operator==(const mersenne_twister_engine& __lhs,
461 const mersenne_twister_engine& __rhs)
462 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
465 * @brief Inserts the current state of a % mersenne_twister_engine
466 * random number generator engine @p __x into the output stream
469 * @param __os An output stream.
470 * @param __x A % mersenne_twister_engine random number generator
473 * @returns The output stream with the state of @p __x inserted or in
476 template<typename _UIntType1,
477 size_t __w1, size_t __n1,
478 size_t __m1, size_t __r1,
479 _UIntType1 __a1, size_t __u1,
480 _UIntType1 __d1, size_t __s1,
481 _UIntType1 __b1, size_t __t1,
482 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
483 typename _CharT, typename _Traits>
484 friend std::basic_ostream<_CharT, _Traits>&
485 operator<<(std::basic_ostream<_CharT, _Traits>&,
486 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
487 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
491 * @brief Extracts the current state of a % mersenne_twister_engine
492 * random number generator engine @p __x from the input stream
495 * @param __is An input stream.
496 * @param __x A % mersenne_twister_engine random number generator
499 * @returns The input stream with the state of @p __x extracted or in
502 template<typename _UIntType1,
503 size_t __w1, size_t __n1,
504 size_t __m1, size_t __r1,
505 _UIntType1 __a1, size_t __u1,
506 _UIntType1 __d1, size_t __s1,
507 _UIntType1 __b1, size_t __t1,
508 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
509 typename _CharT, typename _Traits>
510 friend std::basic_istream<_CharT, _Traits>&
511 operator>>(std::basic_istream<_CharT, _Traits>&,
512 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
513 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
517 _UIntType _M_x[state_size];
522 * @brief The Marsaglia-Zaman generator.
524 * This is a model of a Generalized Fibonacci discrete random number
525 * generator, sometimes referred to as the SWC generator.
527 * A discrete random number generator that produces pseudorandom
528 * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
529 * carry_{i-1}) \bmod m @f$.
531 * The size of the state is @f$ r @f$
532 * and the maximum period of the generator is @f$ m^r - m^s - 1 @f$.
534 * @var _M_x The state of the generator. This is a ring buffer.
535 * @var _M_carry The carry.
536 * @var _M_p Current index of x(i - r).
538 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
539 class subtract_with_carry_engine
541 __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
542 static_assert(__s > 0U && __r > __s
544 && __w <= static_cast<size_t>
545 (std::numeric_limits<_UIntType>::digits),
546 "template arguments out of bounds"
547 " in subtract_with_carry_engine");
550 /** The type of the generated random value. */
551 typedef _UIntType result_type;
554 static const size_t word_size = __w;
555 static const size_t short_lag = __s;
556 static const size_t long_lag = __r;
557 static const result_type default_seed = 19780503u;
560 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
561 * random number generator.
564 subtract_with_carry_engine(result_type __sd = default_seed)
565 { this->seed(__sd); }
568 * @brief Constructs a %subtract_with_carry_engine random number engine
569 * seeded from the seed sequence @p __q.
571 * @param __q the seed sequence.
574 subtract_with_carry_engine(seed_seq& __q)
578 * @brief Seeds the initial state @f$ x_0 @f$ of the random number
581 * N1688[4.19] modifies this as follows. If @p __value == 0,
582 * sets value to 19780503. In any case, with a linear
583 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
584 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
585 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
586 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
587 * set carry to 1, otherwise sets carry to 0.
590 seed(result_type __sd = default_seed);
593 * @brief Seeds the initial state @f$ x_0 @f$ of the
594 * % subtract_with_carry_engine random number generator.
600 * @brief Gets the inclusive minimum value of the range of random
601 * integers returned by this generator.
603 * @todo This should be constexpr.
610 * @brief Gets the inclusive maximum value of the range of random
611 * integers returned by this generator.
613 * @todo This should be constexpr.
617 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
620 * @brief Discard a sequence of random numbers.
622 * @todo Look for a faster way to do discard.
625 discard(unsigned long long __z)
627 for (; __z != 0ULL; --__z)
632 * @brief Gets the next random number in the sequence.
638 * @brief Compares two % subtract_with_carry_engine random number
639 * generator objects of the same type for equality.
641 * @param __lhs A % subtract_with_carry_engine random number generator
643 * @param __rhs Another % subtract_with_carry_engine random number
646 * @returns true if the two objects are equal, false otherwise.
649 operator==(const subtract_with_carry_engine& __lhs,
650 const subtract_with_carry_engine& __rhs)
651 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
654 * @brief Inserts the current state of a % subtract_with_carry_engine
655 * random number generator engine @p __x into the output stream
658 * @param __os An output stream.
659 * @param __x A % subtract_with_carry_engine random number generator
662 * @returns The output stream with the state of @p __x inserted or in
665 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
666 typename _CharT, typename _Traits>
667 friend std::basic_ostream<_CharT, _Traits>&
668 operator<<(std::basic_ostream<_CharT, _Traits>&,
669 const std::subtract_with_carry_engine<_UIntType1, __w1,
673 * @brief Extracts the current state of a % subtract_with_carry_engine
674 * random number generator engine @p __x from the input stream
677 * @param __is An input stream.
678 * @param __x A % subtract_with_carry_engine random number generator engine.
680 * @returns The input stream with the state of @p __x extracted or in
683 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
684 typename _CharT, typename _Traits>
685 friend std::basic_istream<_CharT, _Traits>&
686 operator>>(std::basic_istream<_CharT, _Traits>&,
687 std::subtract_with_carry_engine<_UIntType1, __w1,
691 _UIntType _M_x[long_lag];
697 * Produces random numbers from some base engine by discarding blocks of
700 * 0 <= @p __r <= @p __p
702 template<typename _RandomNumberEngine, size_t __p, size_t __r>
703 class discard_block_engine
705 static_assert(__r >= 1U && __p >= __r,
706 "template arguments out of bounds"
707 " in discard_block_engine");
710 /** The type of the generated random value. */
711 typedef typename _RandomNumberEngine::result_type result_type;
714 static const size_t block_size = __p;
715 static const size_t used_block = __r;
718 * @brief Constructs a default %discard_block_engine engine.
720 * The underlying engine is default constructed as well.
722 discard_block_engine()
723 : _M_b(), _M_n(0) { }
726 * @brief Copy constructs a %discard_block_engine engine.
728 * Copies an existing base class random number generator.
729 * @param rng An existing (base class) engine object.
732 discard_block_engine(const _RandomNumberEngine& __rne)
733 : _M_b(__rne), _M_n(0) { }
736 * @brief Move constructs a %discard_block_engine engine.
738 * Copies an existing base class random number generator.
739 * @param rng An existing (base class) engine object.
742 discard_block_engine(_RandomNumberEngine&& __rne)
743 : _M_b(std::move(__rne)), _M_n(0) { }
746 * @brief Seed constructs a %discard_block_engine engine.
748 * Constructs the underlying generator engine seeded with @p __s.
749 * @param __s A seed value for the base class engine.
752 discard_block_engine(result_type __s)
753 : _M_b(__s), _M_n(0) { }
756 * @brief Generator construct a %discard_block_engine engine.
758 * @param __q A seed sequence.
761 discard_block_engine(seed_seq& __q)
766 * @brief Reseeds the %discard_block_engine object with the default
767 * seed for the underlying base class generator engine.
777 * @brief Reseeds the %discard_block_engine object with the default
778 * seed for the underlying base class generator engine.
781 seed(result_type __s)
788 * @brief Reseeds the %discard_block_engine object with the given seed
790 * @param __q A seed generator function.
800 * @brief Gets a const reference to the underlying generator engine
803 const _RandomNumberEngine&
808 * @brief Gets the minimum value in the generated random number range.
810 * @todo This should be constexpr.
814 { return _M_b.min(); }
817 * @brief Gets the maximum value in the generated random number range.
819 * @todo This should be constexpr.
823 { return _M_b.max(); }
826 * @brief Discard a sequence of random numbers.
828 * @todo Look for a faster way to do discard.
831 discard(unsigned long long __z)
833 for (; __z != 0ULL; --__z)
838 * @brief Gets the next value in the generated random number sequence.
844 * @brief Compares two %discard_block_engine random number generator
845 * objects of the same type for equality.
847 * @param __lhs A %discard_block_engine random number generator object.
848 * @param __rhs Another %discard_block_engine random number generator
851 * @returns true if the two objects are equal, false otherwise.
854 operator==(const discard_block_engine& __lhs,
855 const discard_block_engine& __rhs)
856 { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
859 * @brief Inserts the current state of a %discard_block_engine random
860 * number generator engine @p __x into the output stream
863 * @param __os An output stream.
864 * @param __x A %discard_block_engine random number generator engine.
866 * @returns The output stream with the state of @p __x inserted or in
869 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
870 typename _CharT, typename _Traits>
871 friend std::basic_ostream<_CharT, _Traits>&
872 operator<<(std::basic_ostream<_CharT, _Traits>&,
873 const std::discard_block_engine<_RandomNumberEngine1,
877 * @brief Extracts the current state of a % subtract_with_carry_engine
878 * random number generator engine @p __x from the input stream
881 * @param __is An input stream.
882 * @param __x A %discard_block_engine random number generator engine.
884 * @returns The input stream with the state of @p __x extracted or in
887 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
888 typename _CharT, typename _Traits>
889 friend std::basic_istream<_CharT, _Traits>&
890 operator>>(std::basic_istream<_CharT, _Traits>&,
891 std::discard_block_engine<_RandomNumberEngine1,
895 _RandomNumberEngine _M_b;
900 * Produces random numbers by combining random numbers from some base
901 * engine to produce random numbers with a specifies number of bits @p __w.
903 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
904 class independent_bits_engine
906 static_assert(__w > 0U
909 (std::numeric_limits<_UIntType>::digits),
910 "template arguments out of bounds "
911 "in independent_bits_engine");
914 /** The type of the generated random value. */
915 typedef _UIntType result_type;
918 * @brief Constructs a default %independent_bits_engine engine.
920 * The underlying engine is default constructed as well.
922 independent_bits_engine()
926 * @brief Copy constructs a %independent_bits_engine engine.
928 * Copies an existing base class random number generator.
929 * @param rng An existing (base class) engine object.
932 independent_bits_engine(const _RandomNumberEngine& __rne)
936 * @brief Move constructs a %independent_bits_engine engine.
938 * Copies an existing base class random number generator.
939 * @param rng An existing (base class) engine object.
942 independent_bits_engine(_RandomNumberEngine&& __rne)
943 : _M_b(std::move(__rne)) { }
946 * @brief Seed constructs a %independent_bits_engine engine.
948 * Constructs the underlying generator engine seeded with @p __s.
949 * @param __s A seed value for the base class engine.
952 independent_bits_engine(result_type __s)
956 * @brief Generator construct a %independent_bits_engine engine.
958 * @param __q A seed sequence.
961 independent_bits_engine(seed_seq& __q)
966 * @brief Reseeds the %independent_bits_engine object with the default
967 * seed for the underlying base class generator engine.
974 * @brief Reseeds the %independent_bits_engine object with the default
975 * seed for the underlying base class generator engine.
978 seed(result_type __s)
982 * @brief Reseeds the %independent_bits_engine object with the given
984 * @param __q A seed generator function.
991 * @brief Gets a const reference to the underlying generator engine
994 const _RandomNumberEngine&
999 * @brief Gets the minimum value in the generated random number range.
1001 * @todo This should be constexpr.
1008 * @brief Gets the maximum value in the generated random number range.
1010 * @todo This should be constexpr.
1014 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1017 * @brief Discard a sequence of random numbers.
1019 * @todo Look for a faster way to do discard.
1022 discard(unsigned long long __z)
1024 for (; __z != 0ULL; --__z)
1029 * @brief Gets the next value in the generated random number sequence.
1035 * @brief Compares two %independent_bits_engine random number generator
1036 * objects of the same type for equality.
1038 * @param __lhs A %independent_bits_engine random number generator
1040 * @param __rhs Another %independent_bits_engine random number generator
1043 * @returns true if the two objects are equal, false otherwise.
1046 operator==(const independent_bits_engine& __lhs,
1047 const independent_bits_engine& __rhs)
1048 { return __lhs._M_b == __rhs._M_b; }
1051 * @brief Extracts the current state of a % subtract_with_carry_engine
1052 * random number generator engine @p __x from the input stream
1055 * @param __is An input stream.
1056 * @param __x A %independent_bits_engine random number generator
1059 * @returns The input stream with the state of @p __x extracted or in
1062 template<typename _CharT, typename _Traits>
1063 friend std::basic_istream<_CharT, _Traits>&
1064 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1065 std::independent_bits_engine<_RandomNumberEngine,
1066 __w, _UIntType>& __x)
1073 _RandomNumberEngine _M_b;
1077 * @brief Inserts the current state of a %independent_bits_engine random
1078 * number generator engine @p __x into the output stream @p __os.
1080 * @param __os An output stream.
1081 * @param __x A %independent_bits_engine random number generator engine.
1083 * @returns The output stream with the state of @p __x inserted or in
1086 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1087 typename _CharT, typename _Traits>
1088 std::basic_ostream<_CharT, _Traits>&
1089 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1090 const std::independent_bits_engine<_RandomNumberEngine,
1091 __w, _UIntType>& __x)
1098 * @brief Produces random numbers by combining random numbers from some
1099 * base engine to produce random numbers with a specifies number of bits
1102 template<typename _RandomNumberEngine, size_t __k>
1103 class shuffle_order_engine
1105 static_assert(__k >= 1U,
1106 "template arguments out of bounds"
1107 " in shuffle_order_engine");
1110 /** The type of the generated random value. */
1111 typedef typename _RandomNumberEngine::result_type result_type;
1113 static const size_t table_size = __k;
1116 * @brief Constructs a default %shuffle_order_engine engine.
1118 * The underlying engine is default constructed as well.
1120 shuffle_order_engine()
1122 { _M_initialize(); }
1125 * @brief Copy constructs a %shuffle_order_engine engine.
1127 * Copies an existing base class random number generator.
1128 * @param rng An existing (base class) engine object.
1131 shuffle_order_engine(const _RandomNumberEngine& __rne)
1133 { _M_initialize(); }
1136 * @brief Move constructs a %shuffle_order_engine engine.
1138 * Copies an existing base class random number generator.
1139 * @param rng An existing (base class) engine object.
1142 shuffle_order_engine(_RandomNumberEngine&& __rne)
1143 : _M_b(std::move(__rne))
1144 { _M_initialize(); }
1147 * @brief Seed constructs a %shuffle_order_engine engine.
1149 * Constructs the underlying generator engine seeded with @p __s.
1150 * @param __s A seed value for the base class engine.
1153 shuffle_order_engine(result_type __s)
1155 { _M_initialize(); }
1158 * @brief Generator construct a %shuffle_order_engine engine.
1160 * @param __q A seed sequence.
1163 shuffle_order_engine(seed_seq& __q)
1165 { _M_initialize(); }
1168 * @brief Reseeds the %shuffle_order_engine object with the default seed
1169 for the underlying base class generator engine.
1179 * @brief Reseeds the %shuffle_order_engine object with the default seed
1180 * for the underlying base class generator engine.
1183 seed(result_type __s)
1190 * @brief Reseeds the %shuffle_order_engine object with the given seed
1192 * @param __q A seed generator function.
1202 * Gets a const reference to the underlying generator engine object.
1204 const _RandomNumberEngine&
1209 * Gets the minimum value in the generated random number range.
1211 * @todo This should be constexpr.
1215 { return _M_b.min(); }
1218 * Gets the maximum value in the generated random number range.
1220 * @todo This should be constexpr.
1224 { return _M_b.max(); }
1227 * Discard a sequence of random numbers.
1229 * @todo Look for a faster way to do discard.
1232 discard(unsigned long long __z)
1234 for (; __z != 0ULL; --__z)
1239 * Gets the next value in the generated random number sequence.
1245 * Compares two %shuffle_order_engine random number generator objects
1246 * of the same type for equality.
1248 * @param __lhs A %shuffle_order_engine random number generator object.
1249 * @param __rhs Another %shuffle_order_engine random number generator
1252 * @returns true if the two objects are equal, false otherwise.
1255 operator==(const shuffle_order_engine& __lhs,
1256 const shuffle_order_engine& __rhs)
1257 { return __lhs._M_b == __rhs._M_b; }
1260 * @brief Inserts the current state of a %shuffle_order_engine random
1261 * number generator engine @p __x into the output stream
1264 * @param __os An output stream.
1265 * @param __x A %shuffle_order_engine random number generator engine.
1267 * @returns The output stream with the state of @p __x inserted or in
1270 template<typename _RandomNumberEngine1, size_t __k1,
1271 typename _CharT, typename _Traits>
1272 friend std::basic_ostream<_CharT, _Traits>&
1273 operator<<(std::basic_ostream<_CharT, _Traits>&,
1274 const std::shuffle_order_engine<_RandomNumberEngine1,
1278 * @brief Extracts the current state of a % subtract_with_carry_engine
1279 * random number generator engine @p __x from the input stream
1282 * @param __is An input stream.
1283 * @param __x A %shuffle_order_engine random number generator engine.
1285 * @returns The input stream with the state of @p __x extracted or in
1288 template<typename _RandomNumberEngine1, size_t __k1,
1289 typename _CharT, typename _Traits>
1290 friend std::basic_istream<_CharT, _Traits>&
1291 operator>>(std::basic_istream<_CharT, _Traits>&,
1292 std::shuffle_order_engine<_RandomNumberEngine1, __k1>&);
1295 void _M_initialize()
1297 for (size_t __i = 0; __i < __k; ++__i)
1302 _RandomNumberEngine _M_b;
1303 result_type _M_v[__k];
1308 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1310 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1314 * An alternative LCR (Lehmer Generator function) .
1316 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1320 * The classic Mersenne Twister.
1323 * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
1324 * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
1325 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1327 typedef mersenne_twister_engine<
1333 0xefc60000UL, 18, 1812433253UL> mt19937;
1336 * An alternative Mersenne Twister.
1338 typedef mersenne_twister_engine<
1341 0xb5026f5aa96619e9ULL, 29,
1342 0x5555555555555555ULL, 17,
1343 0x71d67fffeda60000ULL, 37,
1344 0xfff7eee000000000ULL, 43,
1345 6364136223846793005ULL> mt19937_64;
1350 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1353 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1356 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1358 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1363 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1368 typedef minstd_rand0 default_random_engine;
1371 * A standard interface to a platform-specific non-deterministic
1372 * random number generator (if any are available).
1377 /** The type of the generated random value. */
1378 typedef unsigned int result_type;
1380 // constructors, destructors and member functions
1382 #ifdef _GLIBCXX_USE_RANDOM_TR1
1385 random_device(const std::string& __token = "/dev/urandom")
1387 if ((__token != "/dev/urandom" && __token != "/dev/random")
1388 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1389 std::__throw_runtime_error(__N("random_device::"
1390 "random_device(const std::string&)"));
1394 { std::fclose(_M_file); }
1399 random_device(const std::string& __token = "mt19937")
1400 : _M_mt(_M_strtoul(__token)) { }
1403 static unsigned long
1404 _M_strtoul(const std::string& __str)
1406 unsigned long __ret = 5489UL;
1407 if (__str != "mt19937")
1409 const char* __nptr = __str.c_str();
1411 __ret = std::strtoul(__nptr, &__endptr, 0);
1412 if (*__nptr == '\0' || *__endptr != '\0')
1413 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1414 "(const std::string&)"));
1425 { return std::numeric_limits<result_type>::min(); }
1429 { return std::numeric_limits<result_type>::max(); }
1438 #ifdef _GLIBCXX_USE_RANDOM_TR1
1440 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1448 // No copy functions.
1449 random_device(const random_device&) = delete;
1450 void operator=(const random_device&) = delete;
1454 #ifdef _GLIBCXX_USE_RANDOM_TR1
1461 /* @} */ // group std_random_generators
1464 * @addtogroup std_random_distributions Random Number Distributions
1465 * @ingroup std_random
1470 * @addtogroup std_random_distributions_uniform Uniform Distributions
1471 * @ingroup std_random_distributions
1476 * @brief Uniform discrete distribution for random numbers.
1477 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1478 * probability throughout the range.
1480 template<typename _IntType = int>
1481 class uniform_int_distribution
1483 __glibcxx_class_requires(_IntType, _IntegerConcept)
1486 /** The type of the range of the distribution. */
1487 typedef _IntType result_type;
1488 /** Parameter type. */
1491 typedef uniform_int_distribution<_IntType> distribution_type;
1494 param_type(_IntType __a = 0,
1495 _IntType __b = std::numeric_limits<_IntType>::max())
1496 : _M_a(__a), _M_b(__b)
1498 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1516 * @brief Constructs a uniform distribution object.
1519 uniform_int_distribution(_IntType __a = 0,
1520 _IntType __b = std::numeric_limits<_IntType>::max())
1521 : _M_param(__a, __b)
1525 uniform_int_distribution(const param_type& __p)
1530 * @brief Resets the distribution state.
1532 * Does nothing for the uniform integer distribution.
1539 { return _M_param.a(); }
1543 { return _M_param.b(); }
1546 * @brief Returns the inclusive lower bound of the distribution range.
1550 { return this->a(); }
1553 * @brief Returns the inclusive upper bound of the distribution range.
1557 { return this->b(); }
1560 * @brief Returns the parameter set of the distribution.
1564 { return _M_param; }
1567 * @brief Sets the parameter set of the distribution.
1568 * @param __param The new parameter set of the distribution.
1571 param(const param_type& __param)
1572 { _M_param = __param; }
1575 * Gets a uniformly distributed random number in the range
1578 template<typename _UniformRandomNumberGenerator>
1580 operator()(_UniformRandomNumberGenerator& __urng)
1581 { return this->operator()(__urng, this->param()); }
1584 * Gets a uniform random number in the range @f$[0, n)@f$.
1586 * This function is aimed at use with std::random_shuffle.
1588 template<typename _UniformRandomNumberGenerator>
1590 operator()(_UniformRandomNumberGenerator& __urng,
1591 const param_type& __p);
1593 param_type _M_param;
1597 * @brief Inserts a %uniform_int_distribution random number
1598 * distribution @p __x into the output stream @p os.
1600 * @param __os An output stream.
1601 * @param __x A %uniform_int_distribution random number distribution.
1603 * @returns The output stream with the state of @p __x inserted or in
1606 template<typename _IntType, typename _CharT, typename _Traits>
1607 std::basic_ostream<_CharT, _Traits>&
1608 operator<<(std::basic_ostream<_CharT, _Traits>&,
1609 const std::uniform_int_distribution<_IntType>&);
1612 * @brief Extracts a %uniform_int_distribution random number distribution
1613 * @p __x from the input stream @p __is.
1615 * @param __is An input stream.
1616 * @param __x A %uniform_int_distribution random number generator engine.
1618 * @returns The input stream with @p __x extracted or in an error state.
1620 template<typename _IntType, typename _CharT, typename _Traits>
1621 std::basic_istream<_CharT, _Traits>&
1622 operator>>(std::basic_istream<_CharT, _Traits>&,
1623 std::uniform_int_distribution<_IntType>&);
1627 * @brief Uniform continuous distribution for random numbers.
1629 * A continuous random distribution on the range [min, max) with equal
1630 * probability throughout the range. The URNG should be real-valued and
1631 * deliver number in the range [0, 1).
1633 template<typename _RealType = double>
1634 class uniform_real_distribution
1637 /** The type of the range of the distribution. */
1638 typedef _RealType result_type;
1639 /** Parameter type. */
1642 typedef uniform_real_distribution<_RealType> distribution_type;
1645 param_type(_RealType __a = _RealType(0),
1646 _RealType __b = _RealType(1))
1647 : _M_a(__a), _M_b(__b)
1649 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1667 * @brief Constructs a uniform_real_distribution object.
1669 * @param __min [IN] The lower bound of the distribution.
1670 * @param __max [IN] The upper bound of the distribution.
1673 uniform_real_distribution(_RealType __a = _RealType(0),
1674 _RealType __b = _RealType(1))
1675 : _M_param(__a, __b)
1679 uniform_real_distribution(const param_type& __p)
1684 * @brief Resets the distribution state.
1686 * Does nothing for the uniform real distribution.
1693 { return _M_param.a(); }
1697 { return _M_param.b(); }
1700 * @brief Returns the inclusive lower bound of the distribution range.
1704 { return this->a(); }
1707 * @brief Returns the inclusive upper bound of the distribution range.
1711 { return this->b(); }
1714 * @brief Returns the parameter set of the distribution.
1718 { return _M_param; }
1721 * @brief Sets the parameter set of the distribution.
1722 * @param __param The new parameter set of the distribution.
1725 param(const param_type& __param)
1726 { _M_param = __param; }
1728 template<typename _UniformRandomNumberGenerator>
1730 operator()(_UniformRandomNumberGenerator& __urng)
1731 { return this->operator()(__urng, this->param()); }
1733 template<typename _UniformRandomNumberGenerator>
1735 operator()(_UniformRandomNumberGenerator& __urng,
1736 const param_type& __p)
1738 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1740 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1744 param_type _M_param;
1748 * @brief Inserts a %uniform_real_distribution random number
1749 * distribution @p __x into the output stream @p __os.
1751 * @param __os An output stream.
1752 * @param __x A %uniform_real_distribution random number distribution.
1754 * @returns The output stream with the state of @p __x inserted or in
1757 template<typename _RealType, typename _CharT, typename _Traits>
1758 std::basic_ostream<_CharT, _Traits>&
1759 operator<<(std::basic_ostream<_CharT, _Traits>&,
1760 const std::uniform_real_distribution<_RealType>&);
1763 * @brief Extracts a %uniform_real_distribution random number distribution
1764 * @p __x from the input stream @p __is.
1766 * @param __is An input stream.
1767 * @param __x A %uniform_real_distribution random number generator engine.
1769 * @returns The input stream with @p __x extracted or in an error state.
1771 template<typename _RealType, typename _CharT, typename _Traits>
1772 std::basic_istream<_CharT, _Traits>&
1773 operator>>(std::basic_istream<_CharT, _Traits>&,
1774 std::uniform_real_distribution<_RealType>&);
1776 /* @} */ // group std_random_distributions_uniform
1779 * @addtogroup std_random_distributions_normal Normal Distributions
1780 * @ingroup std_random_distributions
1785 * @brief A normal continuous distribution for random numbers.
1787 * The formula for the normal probability density function is
1788 * @f$ p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1789 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } @f$.
1791 template<typename _RealType = double>
1792 class normal_distribution
1795 /** The type of the range of the distribution. */
1796 typedef _RealType result_type;
1797 /** Parameter type. */
1800 typedef normal_distribution<_RealType> distribution_type;
1803 param_type(_RealType __mean = _RealType(0),
1804 _RealType __stddev = _RealType(1))
1805 : _M_mean(__mean), _M_stddev(__stddev)
1807 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1816 { return _M_stddev; }
1820 _RealType _M_stddev;
1825 * Constructs a normal distribution with parameters @f$ mean @f$ and
1826 * standard deviation.
1829 normal_distribution(result_type __mean = result_type(0),
1830 result_type __stddev = result_type(1))
1831 : _M_param(__mean, __stddev), _M_saved_available(false)
1835 normal_distribution(const param_type& __p)
1836 : _M_param(__p), _M_saved_available(false)
1840 * @brief Resets the distribution state.
1844 { _M_saved_available = false; }
1847 * @brief Returns the mean of the distribution.
1851 { return _M_param.mean(); }
1854 * @brief Returns the standard deviation of the distribution.
1858 { return _M_param.stddev(); }
1861 * @brief Returns the parameter set of the distribution.
1865 { return _M_param; }
1868 * @brief Sets the parameter set of the distribution.
1869 * @param __param The new parameter set of the distribution.
1872 param(const param_type& __param)
1873 { _M_param = __param; }
1876 * @brief Returns the greatest lower bound value of the distribution.
1880 { return std::numeric_limits<result_type>::min(); }
1883 * @brief Returns the least upper bound value of the distribution.
1887 { return std::numeric_limits<result_type>::max(); }
1889 template<typename _UniformRandomNumberGenerator>
1891 operator()(_UniformRandomNumberGenerator& __urng)
1892 { return this->operator()(__urng, this->param()); }
1894 template<typename _UniformRandomNumberGenerator>
1896 operator()(_UniformRandomNumberGenerator& __urng,
1897 const param_type& __p);
1900 * @brief Inserts a %normal_distribution random number distribution
1901 * @p __x into the output stream @p __os.
1903 * @param __os An output stream.
1904 * @param __x A %normal_distribution random number distribution.
1906 * @returns The output stream with the state of @p __x inserted or in
1909 template<typename _RealType1, typename _CharT, typename _Traits>
1910 friend std::basic_ostream<_CharT, _Traits>&
1911 operator<<(std::basic_ostream<_CharT, _Traits>&,
1912 const std::normal_distribution<_RealType1>&);
1915 * @brief Extracts a %normal_distribution random number distribution
1916 * @p __x from the input stream @p __is.
1918 * @param __is An input stream.
1919 * @param __x A %normal_distribution random number generator engine.
1921 * @returns The input stream with @p __x extracted or in an error
1924 template<typename _RealType1, typename _CharT, typename _Traits>
1925 friend std::basic_istream<_CharT, _Traits>&
1926 operator>>(std::basic_istream<_CharT, _Traits>&,
1927 std::normal_distribution<_RealType1>&);
1930 param_type _M_param;
1931 result_type _M_saved;
1932 bool _M_saved_available;
1937 * @brief A lognormal_distribution random number distribution.
1939 * The formula for the normal probability mass function is
1940 * @f$ p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
1941 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} @f$
1943 template<typename _RealType = double>
1944 class lognormal_distribution
1947 /** The type of the range of the distribution. */
1948 typedef _RealType result_type;
1949 /** Parameter type. */
1952 typedef lognormal_distribution<_RealType> distribution_type;
1955 param_type(_RealType __m = _RealType(0),
1956 _RealType __s = _RealType(1))
1957 : _M_m(__m), _M_s(__s)
1974 lognormal_distribution(_RealType __m = _RealType(0),
1975 _RealType __s = _RealType(1))
1976 : _M_param(__m, __s), _M_nd()
1980 lognormal_distribution(const param_type& __p)
1981 : _M_param(__p), _M_nd()
1985 * Resets the distribution state.
1996 { return _M_param.m(); }
2000 { return _M_param.s(); }
2003 * @brief Returns the parameter set of the distribution.
2007 { return _M_param; }
2010 * @brief Sets the parameter set of the distribution.
2011 * @param __param The new parameter set of the distribution.
2014 param(const param_type& __param)
2015 { _M_param = __param; }
2018 * @brief Returns the greatest lower bound value of the distribution.
2022 { return result_type(0); }
2025 * @brief Returns the least upper bound value of the distribution.
2029 { return std::numeric_limits<result_type>::max(); }
2031 template<typename _UniformRandomNumberGenerator>
2033 operator()(_UniformRandomNumberGenerator& __urng)
2034 { return this->operator()(__urng, this->param()); }
2036 template<typename _UniformRandomNumberGenerator>
2038 operator()(_UniformRandomNumberGenerator& __urng,
2039 const param_type& __p)
2040 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2043 * @brief Inserts a %lognormal_distribution random number distribution
2044 * @p __x into the output stream @p __os.
2046 * @param __os An output stream.
2047 * @param __x A %lognormal_distribution random number distribution.
2049 * @returns The output stream with the state of @p __x inserted or in
2052 template<typename _RealType1, typename _CharT, typename _Traits>
2053 friend std::basic_ostream<_CharT, _Traits>&
2054 operator<<(std::basic_ostream<_CharT, _Traits>&,
2055 const std::lognormal_distribution<_RealType1>&);
2058 * @brief Extracts a %lognormal_distribution random number distribution
2059 * @p __x from the input stream @p __is.
2061 * @param __is An input stream.
2062 * @param __x A %lognormal_distribution random number
2065 * @returns The input stream with @p __x extracted or in an error state.
2067 template<typename _RealType1, typename _CharT, typename _Traits>
2068 friend std::basic_istream<_CharT, _Traits>&
2069 operator>>(std::basic_istream<_CharT, _Traits>&,
2070 std::lognormal_distribution<_RealType1>&);
2073 param_type _M_param;
2075 std::normal_distribution<result_type> _M_nd;
2080 * @brief A gamma continuous distribution for random numbers.
2082 * The formula for the gamma probability density function is
2083 * @f$ p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2084 * (x/\beta)^{\alpha - 1} e^{-x/\beta} @f$.
2086 template<typename _RealType = double>
2087 class gamma_distribution
2090 /** The type of the range of the distribution. */
2091 typedef _RealType result_type;
2092 /** Parameter type. */
2095 typedef gamma_distribution<_RealType> distribution_type;
2096 friend class gamma_distribution<_RealType>;
2099 param_type(_RealType __alpha_val = _RealType(1),
2100 _RealType __beta_val = _RealType(1))
2101 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2103 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2109 { return _M_alpha; }
2122 _RealType _M_malpha, _M_a2;
2127 * @brief Constructs a gamma distribution with parameters
2128 * @f$ \alpha @f$ and @f$ \beta @f$.
2131 gamma_distribution(_RealType __alpha_val = _RealType(1),
2132 _RealType __beta_val = _RealType(1))
2133 : _M_param(__alpha_val, __beta_val), _M_nd()
2137 gamma_distribution(const param_type& __p)
2138 : _M_param(__p), _M_nd()
2142 * @brief Resets the distribution state.
2149 * @brief Returns the @f$ \alpha @f$ of the distribution.
2153 { return _M_param.alpha(); }
2156 * @brief Returns the @f$ \beta @f$ of the distribution.
2160 { return _M_param.beta(); }
2163 * @brief Returns the parameter set of the distribution.
2167 { return _M_param; }
2170 * @brief Sets the parameter set of the distribution.
2171 * @param __param The new parameter set of the distribution.
2174 param(const param_type& __param)
2175 { _M_param = __param; }
2178 * @brief Returns the greatest lower bound value of the distribution.
2182 { return result_type(0); }
2185 * @brief Returns the least upper bound value of the distribution.
2189 { return std::numeric_limits<result_type>::max(); }
2191 template<typename _UniformRandomNumberGenerator>
2193 operator()(_UniformRandomNumberGenerator& __urng)
2194 { return this->operator()(__urng, this->param()); }
2196 template<typename _UniformRandomNumberGenerator>
2198 operator()(_UniformRandomNumberGenerator& __urng,
2199 const param_type& __p);
2202 * @brief Inserts a %gamma_distribution random number distribution
2203 * @p __x into the output stream @p __os.
2205 * @param __os An output stream.
2206 * @param __x A %gamma_distribution random number distribution.
2208 * @returns The output stream with the state of @p __x inserted or in
2211 template<typename _RealType1, typename _CharT, typename _Traits>
2212 friend std::basic_ostream<_CharT, _Traits>&
2213 operator<<(std::basic_ostream<_CharT, _Traits>&,
2214 const std::gamma_distribution<_RealType1>&);
2217 * @brief Extracts a %gamma_distribution random number distribution
2218 * @p __x from the input stream @p __is.
2220 * @param __is An input stream.
2221 * @param __x A %gamma_distribution random number generator engine.
2223 * @returns The input stream with @p __x extracted or in an error state.
2225 template<typename _RealType1, typename _CharT, typename _Traits>
2226 friend std::basic_istream<_CharT, _Traits>&
2227 operator>>(std::basic_istream<_CharT, _Traits>&,
2228 std::gamma_distribution<_RealType1>&);
2231 param_type _M_param;
2233 std::normal_distribution<result_type> _M_nd;
2238 * @brief A chi_squared_distribution random number distribution.
2240 * The formula for the normal probability mass function is
2241 * @f$ p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}} @f$
2243 template<typename _RealType = double>
2244 class chi_squared_distribution
2247 /** The type of the range of the distribution. */
2248 typedef _RealType result_type;
2249 /** Parameter type. */
2252 typedef chi_squared_distribution<_RealType> distribution_type;
2255 param_type(_RealType __n = _RealType(1))
2268 chi_squared_distribution(_RealType __n = _RealType(1))
2269 : _M_param(__n), _M_gd(__n / 2)
2273 chi_squared_distribution(const param_type& __p)
2274 : _M_param(__p), _M_gd(__p.n() / 2)
2278 * @brief Resets the distribution state.
2289 { return _M_param.n(); }
2292 * @brief Returns the parameter set of the distribution.
2296 { return _M_param; }
2299 * @brief Sets the parameter set of the distribution.
2300 * @param __param The new parameter set of the distribution.
2303 param(const param_type& __param)
2304 { _M_param = __param; }
2307 * @brief Returns the greatest lower bound value of the distribution.
2311 { return result_type(0); }
2314 * @brief Returns the least upper bound value of the distribution.
2318 { return std::numeric_limits<result_type>::max(); }
2320 template<typename _UniformRandomNumberGenerator>
2322 operator()(_UniformRandomNumberGenerator& __urng)
2323 { return 2 * _M_gd(__urng); }
2325 template<typename _UniformRandomNumberGenerator>
2327 operator()(_UniformRandomNumberGenerator& __urng,
2328 const param_type& __p)
2330 typedef typename std::gamma_distribution<result_type>::param_type
2332 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2336 * @brief Inserts a %chi_squared_distribution random number distribution
2337 * @p __x into the output stream @p __os.
2339 * @param __os An output stream.
2340 * @param __x A %chi_squared_distribution random number distribution.
2342 * @returns The output stream with the state of @p __x inserted or in
2345 template<typename _RealType1, typename _CharT, typename _Traits>
2346 friend std::basic_ostream<_CharT, _Traits>&
2347 operator<<(std::basic_ostream<_CharT, _Traits>&,
2348 const std::chi_squared_distribution<_RealType1>&);
2351 * @brief Extracts a %chi_squared_distribution random number distribution
2352 * @p __x from the input stream @p __is.
2354 * @param __is An input stream.
2355 * @param __x A %chi_squared_distribution random number
2358 * @returns The input stream with @p __x extracted or in an error state.
2360 template<typename _RealType1, typename _CharT, typename _Traits>
2361 friend std::basic_istream<_CharT, _Traits>&
2362 operator>>(std::basic_istream<_CharT, _Traits>&,
2363 std::chi_squared_distribution<_RealType1>&);
2366 param_type _M_param;
2368 std::gamma_distribution<result_type> _M_gd;
2373 * @brief A cauchy_distribution random number distribution.
2375 * The formula for the normal probability mass function is
2376 * @f$ p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1} @f$
2378 template<typename _RealType = double>
2379 class cauchy_distribution
2382 /** The type of the range of the distribution. */
2383 typedef _RealType result_type;
2384 /** Parameter type. */
2387 typedef cauchy_distribution<_RealType> distribution_type;
2390 param_type(_RealType __a = _RealType(0),
2391 _RealType __b = _RealType(1))
2392 : _M_a(__a), _M_b(__b)
2409 cauchy_distribution(_RealType __a = _RealType(0),
2410 _RealType __b = _RealType(1))
2411 : _M_param(__a, __b)
2415 cauchy_distribution(const param_type& __p)
2420 * @brief Resets the distribution state.
2431 { return _M_param.a(); }
2435 { return _M_param.b(); }
2438 * @brief Returns the parameter set of the distribution.
2442 { return _M_param; }
2445 * @brief Sets the parameter set of the distribution.
2446 * @param __param The new parameter set of the distribution.
2449 param(const param_type& __param)
2450 { _M_param = __param; }
2453 * @brief Returns the greatest lower bound value of the distribution.
2457 { return std::numeric_limits<result_type>::min(); }
2460 * @brief Returns the least upper bound value of the distribution.
2464 { return std::numeric_limits<result_type>::max(); }
2466 template<typename _UniformRandomNumberGenerator>
2468 operator()(_UniformRandomNumberGenerator& __urng)
2469 { return this->operator()(__urng, this->param()); }
2471 template<typename _UniformRandomNumberGenerator>
2473 operator()(_UniformRandomNumberGenerator& __urng,
2474 const param_type& __p);
2477 param_type _M_param;
2481 * @brief Inserts a %cauchy_distribution random number distribution
2482 * @p __x into the output stream @p __os.
2484 * @param __os An output stream.
2485 * @param __x A %cauchy_distribution random number distribution.
2487 * @returns The output stream with the state of @p __x inserted or in
2490 template<typename _RealType, typename _CharT, typename _Traits>
2491 std::basic_ostream<_CharT, _Traits>&
2492 operator<<(std::basic_ostream<_CharT, _Traits>&,
2493 const std::cauchy_distribution<_RealType>&);
2496 * @brief Extracts a %cauchy_distribution random number distribution
2497 * @p __x from the input stream @p __is.
2499 * @param __is An input stream.
2500 * @param __x A %cauchy_distribution random number
2503 * @returns The input stream with @p __x extracted or in an error state.
2505 template<typename _RealType, typename _CharT, typename _Traits>
2506 std::basic_istream<_CharT, _Traits>&
2507 operator>>(std::basic_istream<_CharT, _Traits>&,
2508 std::cauchy_distribution<_RealType>&);
2512 * @brief A fisher_f_distribution random number distribution.
2514 * The formula for the normal probability mass function is
2515 * @f$ p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2516 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2517 * (1 + \frac{mx}{n})^{-(m+n)/2} @f$
2519 template<typename _RealType = double>
2520 class fisher_f_distribution
2523 /** The type of the range of the distribution. */
2524 typedef _RealType result_type;
2525 /** Parameter type. */
2528 typedef fisher_f_distribution<_RealType> distribution_type;
2531 param_type(_RealType __m = _RealType(1),
2532 _RealType __n = _RealType(1))
2533 : _M_m(__m), _M_n(__n)
2550 fisher_f_distribution(_RealType __m = _RealType(1),
2551 _RealType __n = _RealType(1))
2552 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2556 fisher_f_distribution(const param_type& __p)
2557 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2561 * @brief Resets the distribution state.
2575 { return _M_param.m(); }
2579 { return _M_param.n(); }
2582 * @brief Returns the parameter set of the distribution.
2586 { return _M_param; }
2589 * @brief Sets the parameter set of the distribution.
2590 * @param __param The new parameter set of the distribution.
2593 param(const param_type& __param)
2594 { _M_param = __param; }
2597 * @brief Returns the greatest lower bound value of the distribution.
2601 { return result_type(0); }
2604 * @brief Returns the least upper bound value of the distribution.
2608 { return std::numeric_limits<result_type>::max(); }
2610 template<typename _UniformRandomNumberGenerator>
2612 operator()(_UniformRandomNumberGenerator& __urng)
2613 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2615 template<typename _UniformRandomNumberGenerator>
2617 operator()(_UniformRandomNumberGenerator& __urng,
2618 const param_type& __p)
2620 typedef typename std::gamma_distribution<result_type>::param_type
2622 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2623 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2627 * @brief Inserts a %fisher_f_distribution random number distribution
2628 * @p __x into the output stream @p __os.
2630 * @param __os An output stream.
2631 * @param __x A %fisher_f_distribution random number distribution.
2633 * @returns The output stream with the state of @p __x inserted or in
2636 template<typename _RealType1, typename _CharT, typename _Traits>
2637 friend std::basic_ostream<_CharT, _Traits>&
2638 operator<<(std::basic_ostream<_CharT, _Traits>&,
2639 const std::fisher_f_distribution<_RealType1>&);
2642 * @brief Extracts a %fisher_f_distribution random number distribution
2643 * @p __x from the input stream @p __is.
2645 * @param __is An input stream.
2646 * @param __x A %fisher_f_distribution random number
2649 * @returns The input stream with @p __x extracted or in an error state.
2651 template<typename _RealType1, typename _CharT, typename _Traits>
2652 friend std::basic_istream<_CharT, _Traits>&
2653 operator>>(std::basic_istream<_CharT, _Traits>&,
2654 std::fisher_f_distribution<_RealType1>&);
2657 param_type _M_param;
2659 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
2664 * @brief A student_t_distribution random number distribution.
2666 * The formula for the normal probability mass function is
2667 * @f$ p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
2668 * (1 + \frac{x^2}{n}) ^{-(n+1)/2} @f$
2670 template<typename _RealType = double>
2671 class student_t_distribution
2674 /** The type of the range of the distribution. */
2675 typedef _RealType result_type;
2676 /** Parameter type. */
2679 typedef student_t_distribution<_RealType> distribution_type;
2682 param_type(_RealType __n = _RealType(1))
2695 student_t_distribution(_RealType __n = _RealType(1))
2696 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
2700 student_t_distribution(const param_type& __p)
2701 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
2705 * @brief Resets the distribution state.
2719 { return _M_param.n(); }
2722 * @brief Returns the parameter set of the distribution.
2726 { return _M_param; }
2729 * @brief Sets the parameter set of the distribution.
2730 * @param __param The new parameter set of the distribution.
2733 param(const param_type& __param)
2734 { _M_param = __param; }
2737 * @brief Returns the greatest lower bound value of the distribution.
2741 { return std::numeric_limits<result_type>::min(); }
2744 * @brief Returns the least upper bound value of the distribution.
2748 { return std::numeric_limits<result_type>::max(); }
2750 template<typename _UniformRandomNumberGenerator>
2752 operator()(_UniformRandomNumberGenerator& __urng)
2753 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
2755 template<typename _UniformRandomNumberGenerator>
2757 operator()(_UniformRandomNumberGenerator& __urng,
2758 const param_type& __p)
2760 typedef typename std::gamma_distribution<result_type>::param_type
2763 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
2764 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
2768 * @brief Inserts a %student_t_distribution random number distribution
2769 * @p __x into the output stream @p __os.
2771 * @param __os An output stream.
2772 * @param __x A %student_t_distribution random number distribution.
2774 * @returns The output stream with the state of @p __x inserted or in
2777 template<typename _RealType1, typename _CharT, typename _Traits>
2778 friend std::basic_ostream<_CharT, _Traits>&
2779 operator<<(std::basic_ostream<_CharT, _Traits>&,
2780 const std::student_t_distribution<_RealType1>&);
2783 * @brief Extracts a %student_t_distribution random number distribution
2784 * @p __x from the input stream @p __is.
2786 * @param __is An input stream.
2787 * @param __x A %student_t_distribution random number
2790 * @returns The input stream with @p __x extracted or in an error state.
2792 template<typename _RealType1, typename _CharT, typename _Traits>
2793 friend std::basic_istream<_CharT, _Traits>&
2794 operator>>(std::basic_istream<_CharT, _Traits>&,
2795 std::student_t_distribution<_RealType1>&);
2798 param_type _M_param;
2800 std::normal_distribution<result_type> _M_nd;
2801 std::gamma_distribution<result_type> _M_gd;
2804 /* @} */ // group std_random_distributions_normal
2807 * @addtogroup std_random_distributions_bernoulli Bernoulli Distributions
2808 * @ingroup std_random_distributions
2813 * @brief A Bernoulli random number distribution.
2815 * Generates a sequence of true and false values with likelihood @f$ p @f$
2816 * that true will come up and @f$ (1 - p) @f$ that false will appear.
2818 class bernoulli_distribution
2821 /** The type of the range of the distribution. */
2822 typedef bool result_type;
2823 /** Parameter type. */
2826 typedef bernoulli_distribution distribution_type;
2829 param_type(double __p = 0.5)
2832 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
2845 * @brief Constructs a Bernoulli distribution with likelihood @p p.
2847 * @param __p [IN] The likelihood of a true result being returned.
2848 * Must be in the interval @f$ [0, 1] @f$.
2851 bernoulli_distribution(double __p = 0.5)
2856 bernoulli_distribution(const param_type& __p)
2861 * @brief Resets the distribution state.
2863 * Does nothing for a Bernoulli distribution.
2869 * @brief Returns the @p p parameter of the distribution.
2873 { return _M_param.p(); }
2876 * @brief Returns the parameter set of the distribution.
2880 { return _M_param; }
2883 * @brief Sets the parameter set of the distribution.
2884 * @param __param The new parameter set of the distribution.
2887 param(const param_type& __param)
2888 { _M_param = __param; }
2891 * @brief Returns the greatest lower bound value of the distribution.
2895 { return std::numeric_limits<result_type>::min(); }
2898 * @brief Returns the least upper bound value of the distribution.
2902 { return std::numeric_limits<result_type>::max(); }
2905 * @brief Returns the next value in the Bernoullian sequence.
2907 template<typename _UniformRandomNumberGenerator>
2909 operator()(_UniformRandomNumberGenerator& __urng)
2910 { return this->operator()(__urng, this->param()); }
2912 template<typename _UniformRandomNumberGenerator>
2914 operator()(_UniformRandomNumberGenerator& __urng,
2915 const param_type& __p)
2917 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2919 if ((__aurng() - __aurng.min())
2920 < __p.p() * (__aurng.max() - __aurng.min()))
2926 param_type _M_param;
2930 * @brief Inserts a %bernoulli_distribution random number distribution
2931 * @p __x into the output stream @p __os.
2933 * @param __os An output stream.
2934 * @param __x A %bernoulli_distribution random number distribution.
2936 * @returns The output stream with the state of @p __x inserted or in
2939 template<typename _CharT, typename _Traits>
2940 std::basic_ostream<_CharT, _Traits>&
2941 operator<<(std::basic_ostream<_CharT, _Traits>&,
2942 const std::bernoulli_distribution&);
2945 * @brief Extracts a %bernoulli_distribution random number distribution
2946 * @p __x from the input stream @p __is.
2948 * @param __is An input stream.
2949 * @param __x A %bernoulli_distribution random number generator engine.
2951 * @returns The input stream with @p __x extracted or in an error state.
2953 template<typename _CharT, typename _Traits>
2954 std::basic_istream<_CharT, _Traits>&
2955 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2956 std::bernoulli_distribution& __x)
2960 __x.param(bernoulli_distribution::param_type(__p));
2966 * @brief A discrete binomial random number distribution.
2968 * The formula for the binomial probability density function is
2969 * @f$ p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
2970 * and @f$ p @f$ are the parameters of the distribution.
2972 template<typename _IntType = int>
2973 class binomial_distribution
2975 __glibcxx_class_requires(_IntType, _IntegerConcept)
2978 /** The type of the range of the distribution. */
2979 typedef _IntType result_type;
2980 /** Parameter type. */
2983 typedef binomial_distribution<_IntType> distribution_type;
2984 friend class binomial_distribution<_IntType>;
2987 param_type(_IntType __t = _IntType(1), double __p = 0.5)
2988 : _M_t(__t), _M_p(__p)
2990 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3012 #if _GLIBCXX_USE_C99_MATH_TR1
3013 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3014 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3019 // constructors and member function
3021 binomial_distribution(_IntType __t = _IntType(1),
3023 : _M_param(__t, __p), _M_nd()
3027 binomial_distribution(const param_type& __p)
3028 : _M_param(__p), _M_nd()
3032 * @brief Resets the distribution state.
3039 * @brief Returns the distribution @p t parameter.
3043 { return _M_param.t(); }
3046 * @brief Returns the distribution @p p parameter.
3050 { return _M_param.p(); }
3053 * @brief Returns the parameter set of the distribution.
3057 { return _M_param; }
3060 * @brief Sets the parameter set of the distribution.
3061 * @param __param The new parameter set of the distribution.
3064 param(const param_type& __param)
3065 { _M_param = __param; }
3068 * @brief Returns the greatest lower bound value of the distribution.
3075 * @brief Returns the least upper bound value of the distribution.
3079 { return _M_param.t(); }
3081 template<typename _UniformRandomNumberGenerator>
3083 operator()(_UniformRandomNumberGenerator& __urng)
3084 { return this->operator()(__urng, this->param()); }
3086 template<typename _UniformRandomNumberGenerator>
3088 operator()(_UniformRandomNumberGenerator& __urng,
3089 const param_type& __p);
3092 * @brief Inserts a %binomial_distribution random number distribution
3093 * @p __x into the output stream @p __os.
3095 * @param __os An output stream.
3096 * @param __x A %binomial_distribution random number distribution.
3098 * @returns The output stream with the state of @p __x inserted or in
3101 template<typename _IntType1,
3102 typename _CharT, typename _Traits>
3103 friend std::basic_ostream<_CharT, _Traits>&
3104 operator<<(std::basic_ostream<_CharT, _Traits>&,
3105 const std::binomial_distribution<_IntType1>&);
3108 * @brief Extracts a %binomial_distribution random number distribution
3109 * @p __x from the input stream @p __is.
3111 * @param __is An input stream.
3112 * @param __x A %binomial_distribution random number generator engine.
3114 * @returns The input stream with @p __x extracted or in an error
3117 template<typename _IntType1,
3118 typename _CharT, typename _Traits>
3119 friend std::basic_istream<_CharT, _Traits>&
3120 operator>>(std::basic_istream<_CharT, _Traits>&,
3121 std::binomial_distribution<_IntType1>&);
3124 template<typename _UniformRandomNumberGenerator>
3126 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3128 param_type _M_param;
3130 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3131 std::normal_distribution<double> _M_nd;
3136 * @brief A discrete geometric random number distribution.
3138 * The formula for the geometric probability density function is
3139 * @f$ p(i|p) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
3142 template<typename _IntType = int>
3143 class geometric_distribution
3145 __glibcxx_class_requires(_IntType, _IntegerConcept)
3148 /** The type of the range of the distribution. */
3149 typedef _IntType result_type;
3150 /** Parameter type. */
3153 typedef geometric_distribution<_IntType> distribution_type;
3154 friend class geometric_distribution<_IntType>;
3157 param_type(double __p = 0.5)
3160 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
3172 { _M_log_p = std::log(_M_p); }
3179 // constructors and member function
3181 geometric_distribution(double __p = 0.5)
3186 geometric_distribution(const param_type& __p)
3191 * @brief Resets the distribution state.
3193 * Does nothing for the geometric distribution.
3199 * @brief Returns the distribution parameter @p p.
3203 { return _M_param.p(); }
3206 * @brief Returns the parameter set of the distribution.
3210 { return _M_param; }
3213 * @brief Sets the parameter set of the distribution.
3214 * @param __param The new parameter set of the distribution.
3217 param(const param_type& __param)
3218 { _M_param = __param; }
3221 * @brief Returns the greatest lower bound value of the distribution.
3228 * @brief Returns the least upper bound value of the distribution.
3232 { return std::numeric_limits<result_type>::max(); }
3234 template<typename _UniformRandomNumberGenerator>
3236 operator()(_UniformRandomNumberGenerator& __urng)
3237 { return this->operator()(__urng, this->param()); }
3239 template<typename _UniformRandomNumberGenerator>
3241 operator()(_UniformRandomNumberGenerator& __urng,
3242 const param_type& __p);
3245 param_type _M_param;
3249 * @brief Inserts a %geometric_distribution random number distribution
3250 * @p __x into the output stream @p __os.
3252 * @param __os An output stream.
3253 * @param __x A %geometric_distribution random number distribution.
3255 * @returns The output stream with the state of @p __x inserted or in
3258 template<typename _IntType,
3259 typename _CharT, typename _Traits>
3260 std::basic_ostream<_CharT, _Traits>&
3261 operator<<(std::basic_ostream<_CharT, _Traits>&,
3262 const std::geometric_distribution<_IntType>&);
3265 * @brief Extracts a %geometric_distribution random number distribution
3266 * @p __x from the input stream @p __is.
3268 * @param __is An input stream.
3269 * @param __x A %geometric_distribution random number generator engine.
3271 * @returns The input stream with @p __x extracted or in an error state.
3273 template<typename _IntType,
3274 typename _CharT, typename _Traits>
3275 std::basic_istream<_CharT, _Traits>&
3276 operator>>(std::basic_istream<_CharT, _Traits>&,
3277 std::geometric_distribution<_IntType>&);
3281 * @brief A negative_binomial_distribution random number distribution.
3283 * The formula for the negative binomial probability mass function is
3284 * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
3285 * and @f$ p @f$ are the parameters of the distribution.
3287 template<typename _IntType = int>
3288 class negative_binomial_distribution
3290 __glibcxx_class_requires(_IntType, _IntegerConcept)
3293 /** The type of the range of the distribution. */
3294 typedef _IntType result_type;
3295 /** Parameter type. */
3298 typedef negative_binomial_distribution<_IntType> distribution_type;
3301 param_type(_IntType __k = 1, double __p = 0.5)
3302 : _M_k(__k), _M_p(__p)
3319 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3320 : _M_param(__k, __p), _M_gd(__k, __p / (1.0 - __p))
3324 negative_binomial_distribution(const param_type& __p)
3325 : _M_param(__p), _M_gd(__p.k(), __p.p() / (1.0 - __p.p()))
3329 * @brief Resets the distribution state.
3336 * @brief Return the @f$ k @f$ parameter of the distribution.
3340 { return _M_param.k(); }
3343 * @brief Return the @f$ p @f$ parameter of the distribution.
3347 { return _M_param.p(); }
3350 * @brief Returns the parameter set of the distribution.
3354 { return _M_param; }
3357 * @brief Sets the parameter set of the distribution.
3358 * @param __param The new parameter set of the distribution.
3361 param(const param_type& __param)
3362 { _M_param = __param; }
3365 * @brief Returns the greatest lower bound value of the distribution.
3369 { return result_type(0); }
3372 * @brief Returns the least upper bound value of the distribution.
3376 { return std::numeric_limits<result_type>::max(); }
3378 template<typename _UniformRandomNumberGenerator>
3380 operator()(_UniformRandomNumberGenerator& __urng);
3382 template<typename _UniformRandomNumberGenerator>
3384 operator()(_UniformRandomNumberGenerator& __urng,
3385 const param_type& __p);
3388 * @brief Inserts a %negative_binomial_distribution random
3389 * number distribution @p __x into the output stream @p __os.
3391 * @param __os An output stream.
3392 * @param __x A %negative_binomial_distribution random number
3395 * @returns The output stream with the state of @p __x inserted or in
3398 template<typename _IntType1, typename _CharT, typename _Traits>
3399 friend std::basic_ostream<_CharT, _Traits>&
3400 operator<<(std::basic_ostream<_CharT, _Traits>&,
3401 const std::negative_binomial_distribution<_IntType1>&);
3404 * @brief Extracts a %negative_binomial_distribution random number
3405 * distribution @p __x from the input stream @p __is.
3407 * @param __is An input stream.
3408 * @param __x A %negative_binomial_distribution random number
3411 * @returns The input stream with @p __x extracted or in an error state.
3413 template<typename _IntType1, typename _CharT, typename _Traits>
3414 friend std::basic_istream<_CharT, _Traits>&
3415 operator>>(std::basic_istream<_CharT, _Traits>&,
3416 std::negative_binomial_distribution<_IntType1>&);
3419 param_type _M_param;
3421 std::gamma_distribution<double> _M_gd;
3424 /* @} */ // group std_random_distributions_bernoulli
3427 * @addtogroup std_random_distributions_poisson Poisson Distributions
3428 * @ingroup std_random_distributions
3433 * @brief A discrete Poisson random number distribution.
3435 * The formula for the Poisson probability density function is
3436 * @f$ p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu} @f$ where @f$ \mu @f$ is the
3437 * parameter of the distribution.
3439 template<typename _IntType = int>
3440 class poisson_distribution
3442 __glibcxx_class_requires(_IntType, _IntegerConcept)
3445 /** The type of the range of the distribution. */
3446 typedef _IntType result_type;
3447 /** Parameter type. */
3450 typedef poisson_distribution<_IntType> distribution_type;
3451 friend class poisson_distribution<_IntType>;
3454 param_type(double __mean = 1.0)
3457 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3466 // Hosts either log(mean) or the threshold of the simple method.
3473 #if _GLIBCXX_USE_C99_MATH_TR1
3474 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3478 // constructors and member function
3480 poisson_distribution(double __mean = 1.0)
3481 : _M_param(__mean), _M_nd()
3485 poisson_distribution(const param_type& __p)
3486 : _M_param(__p), _M_nd()
3490 * @brief Resets the distribution state.
3497 * @brief Returns the distribution parameter @p mean.
3501 { return _M_param.mean(); }
3504 * @brief Returns the parameter set of the distribution.
3508 { return _M_param; }
3511 * @brief Sets the parameter set of the distribution.
3512 * @param __param The new parameter set of the distribution.
3515 param(const param_type& __param)
3516 { _M_param = __param; }
3519 * @brief Returns the greatest lower bound value of the distribution.
3526 * @brief Returns the least upper bound value of the distribution.
3530 { return std::numeric_limits<result_type>::max(); }
3532 template<typename _UniformRandomNumberGenerator>
3534 operator()(_UniformRandomNumberGenerator& __urng)
3535 { return this->operator()(__urng, this->param()); }
3537 template<typename _UniformRandomNumberGenerator>
3539 operator()(_UniformRandomNumberGenerator& __urng,
3540 const param_type& __p);
3543 * @brief Inserts a %poisson_distribution random number distribution
3544 * @p __x into the output stream @p __os.
3546 * @param __os An output stream.
3547 * @param __x A %poisson_distribution random number distribution.
3549 * @returns The output stream with the state of @p __x inserted or in
3552 template<typename _IntType1, typename _CharT, typename _Traits>
3553 friend std::basic_ostream<_CharT, _Traits>&
3554 operator<<(std::basic_ostream<_CharT, _Traits>&,
3555 const std::poisson_distribution<_IntType1>&);
3558 * @brief Extracts a %poisson_distribution random number distribution
3559 * @p __x from the input stream @p __is.
3561 * @param __is An input stream.
3562 * @param __x A %poisson_distribution random number generator engine.
3564 * @returns The input stream with @p __x extracted or in an error
3567 template<typename _IntType1, typename _CharT, typename _Traits>
3568 friend std::basic_istream<_CharT, _Traits>&
3569 operator>>(std::basic_istream<_CharT, _Traits>&,
3570 std::poisson_distribution<_IntType1>&);
3573 param_type _M_param;
3575 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3576 std::normal_distribution<double> _M_nd;
3580 * @brief An exponential continuous distribution for random numbers.
3582 * The formula for the exponential probability density function is
3583 * @f$ p(x|\lambda) = \lambda e^{-\lambda x} @f$.
3585 * <table border=1 cellpadding=10 cellspacing=0>
3586 * <caption align=top>Distribution Statistics</caption>
3587 * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3588 * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
3589 * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
3590 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
3591 * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3594 template<typename _RealType = double>
3595 class exponential_distribution
3598 /** The type of the range of the distribution. */
3599 typedef _RealType result_type;
3600 /** Parameter type. */
3603 typedef exponential_distribution<_RealType> distribution_type;
3606 param_type(_RealType __lambda = _RealType(1))
3607 : _M_lambda(__lambda)
3609 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
3614 { return _M_lambda; }
3617 _RealType _M_lambda;
3622 * @brief Constructs an exponential distribution with inverse scale
3623 * parameter @f$ \lambda @f$.
3626 exponential_distribution(const result_type& __lambda = result_type(1))
3627 : _M_param(__lambda)
3631 exponential_distribution(const param_type& __p)
3636 * @brief Resets the distribution state.
3638 * Has no effect on exponential distributions.
3644 * @brief Returns the inverse scale parameter of the distribution.
3648 { return _M_param.lambda(); }
3651 * @brief Returns the parameter set of the distribution.
3655 { return _M_param; }
3658 * @brief Sets the parameter set of the distribution.
3659 * @param __param The new parameter set of the distribution.
3662 param(const param_type& __param)
3663 { _M_param = __param; }
3666 * @brief Returns the greatest lower bound value of the distribution.
3670 { return result_type(0); }
3673 * @brief Returns the least upper bound value of the distribution.
3677 { return std::numeric_limits<result_type>::max(); }
3679 template<typename _UniformRandomNumberGenerator>
3681 operator()(_UniformRandomNumberGenerator& __urng)
3682 { return this->operator()(__urng, this->param()); }
3684 template<typename _UniformRandomNumberGenerator>
3686 operator()(_UniformRandomNumberGenerator& __urng,
3687 const param_type& __p)
3689 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
3691 return -std::log(__aurng()) / __p.lambda();
3695 param_type _M_param;
3699 * @brief Inserts a %exponential_distribution random number distribution
3700 * @p __x into the output stream @p __os.
3702 * @param __os An output stream.
3703 * @param __x A %exponential_distribution random number distribution.
3705 * @returns The output stream with the state of @p __x inserted or in
3708 template<typename _RealType, typename _CharT, typename _Traits>
3709 std::basic_ostream<_CharT, _Traits>&
3710 operator<<(std::basic_ostream<_CharT, _Traits>&,
3711 const std::exponential_distribution<_RealType>&);
3714 * @brief Extracts a %exponential_distribution random number distribution
3715 * @p __x from the input stream @p __is.
3717 * @param __is An input stream.
3718 * @param __x A %exponential_distribution random number
3721 * @returns The input stream with @p __x extracted or in an error state.
3723 template<typename _RealType, typename _CharT, typename _Traits>
3724 std::basic_istream<_CharT, _Traits>&
3725 operator>>(std::basic_istream<_CharT, _Traits>&,
3726 std::exponential_distribution<_RealType>&);
3730 * @brief A weibull_distribution random number distribution.
3732 * The formula for the normal probability density function is
3733 * @f$ p(x|\alpha,\beta) = \frac{a}{b} (frac{x}{b})^{a-1}
3734 * \exp{(-(frac{x}{b})^a)} @f$.
3736 template<typename _RealType = double>
3737 class weibull_distribution
3740 /** The type of the range of the distribution. */
3741 typedef _RealType result_type;
3742 /** Parameter type. */
3745 typedef weibull_distribution<_RealType> distribution_type;
3748 param_type(_RealType __a = _RealType(1),
3749 _RealType __b = _RealType(1))
3750 : _M_a(__a), _M_b(__b)
3767 weibull_distribution(_RealType __a = _RealType(1),
3768 _RealType __b = _RealType(1))
3769 : _M_param(__a, __b)
3773 weibull_distribution(const param_type& __p)
3778 * @brief Resets the distribution state.
3785 * @brief Return the @f$ a @f$ parameter of the distribution.
3789 { return _M_param.a(); }
3792 * @brief Return the @f$ b @f$ parameter of the distribution.
3796 { return _M_param.b(); }
3799 * @brief Returns the parameter set of the distribution.
3803 { return _M_param; }
3806 * @brief Sets the parameter set of the distribution.
3807 * @param __param The new parameter set of the distribution.
3810 param(const param_type& __param)
3811 { _M_param = __param; }
3814 * @brief Returns the greatest lower bound value of the distribution.
3818 { return result_type(0); }
3821 * @brief Returns the least upper bound value of the distribution.
3825 { return std::numeric_limits<result_type>::max(); }
3827 template<typename _UniformRandomNumberGenerator>
3829 operator()(_UniformRandomNumberGenerator& __urng)
3830 { return this->operator()(__urng, this->param()); }
3832 template<typename _UniformRandomNumberGenerator>
3834 operator()(_UniformRandomNumberGenerator& __urng,
3835 const param_type& __p);
3838 param_type _M_param;
3842 * @brief Inserts a %weibull_distribution random number distribution
3843 * @p __x into the output stream @p __os.
3845 * @param __os An output stream.
3846 * @param __x A %weibull_distribution random number distribution.
3848 * @returns The output stream with the state of @p __x inserted or in
3851 template<typename _RealType, typename _CharT, typename _Traits>
3852 std::basic_ostream<_CharT, _Traits>&
3853 operator<<(std::basic_ostream<_CharT, _Traits>&,
3854 const std::weibull_distribution<_RealType>&);
3857 * @brief Extracts a %weibull_distribution random number distribution
3858 * @p __x from the input stream @p __is.
3860 * @param __is An input stream.
3861 * @param __x A %weibull_distribution random number
3864 * @returns The input stream with @p __x extracted or in an error state.
3866 template<typename _RealType, typename _CharT, typename _Traits>
3867 std::basic_istream<_CharT, _Traits>&
3868 operator>>(std::basic_istream<_CharT, _Traits>&,
3869 std::weibull_distribution<_RealType>&);
3873 * @brief A extreme_value_distribution random number distribution.
3875 * The formula for the normal probability mass function is
3876 * @f$ p(x|a,b) = \frac{1}{b}
3877 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) @f$
3879 template<typename _RealType = double>
3880 class extreme_value_distribution
3883 /** The type of the range of the distribution. */
3884 typedef _RealType result_type;
3885 /** Parameter type. */
3888 typedef extreme_value_distribution<_RealType> distribution_type;
3891 param_type(_RealType __a = _RealType(0),
3892 _RealType __b = _RealType(1))
3893 : _M_a(__a), _M_b(__b)
3910 extreme_value_distribution(_RealType __a = _RealType(0),
3911 _RealType __b = _RealType(1))
3912 : _M_param(__a, __b)
3916 extreme_value_distribution(const param_type& __p)
3921 * @brief Resets the distribution state.
3928 * @brief Return the @f$ a @f$ parameter of the distribution.
3932 { return _M_param.a(); }
3935 * @brief Return the @f$ b @f$ parameter of the distribution.
3939 { return _M_param.b(); }
3942 * @brief Returns the parameter set of the distribution.
3946 { return _M_param; }
3949 * @brief Sets the parameter set of the distribution.
3950 * @param __param The new parameter set of the distribution.
3953 param(const param_type& __param)
3954 { _M_param = __param; }
3957 * @brief Returns the greatest lower bound value of the distribution.
3961 { return std::numeric_limits<result_type>::min(); }
3964 * @brief Returns the least upper bound value of the distribution.
3968 { return std::numeric_limits<result_type>::max(); }
3970 template<typename _UniformRandomNumberGenerator>
3972 operator()(_UniformRandomNumberGenerator& __urng)
3973 { return this->operator()(__urng, this->param()); }
3975 template<typename _UniformRandomNumberGenerator>
3977 operator()(_UniformRandomNumberGenerator& __urng,
3978 const param_type& __p);
3981 param_type _M_param;
3985 * @brief Inserts a %extreme_value_distribution random number distribution
3986 * @p __x into the output stream @p __os.
3988 * @param __os An output stream.
3989 * @param __x A %extreme_value_distribution random number distribution.
3991 * @returns The output stream with the state of @p __x inserted or in
3994 template<typename _RealType, typename _CharT, typename _Traits>
3995 std::basic_ostream<_CharT, _Traits>&
3996 operator<<(std::basic_ostream<_CharT, _Traits>&,
3997 const std::extreme_value_distribution<_RealType>&);
4000 * @brief Extracts a %extreme_value_distribution random number
4001 * distribution @p __x from the input stream @p __is.
4003 * @param __is An input stream.
4004 * @param __x A %extreme_value_distribution random number
4007 * @returns The input stream with @p __x extracted or in an error state.
4009 template<typename _RealType, typename _CharT, typename _Traits>
4010 std::basic_istream<_CharT, _Traits>&
4011 operator>>(std::basic_istream<_CharT, _Traits>&,
4012 std::extreme_value_distribution<_RealType>&);
4016 * @brief A discrete_distribution random number distribution.
4018 * The formula for the discrete probability mass function is
4021 template<typename _IntType = int>
4022 class discrete_distribution
4024 __glibcxx_class_requires(_IntType, _IntegerConcept)
4027 /** The type of the range of the distribution. */
4028 typedef _IntType result_type;
4029 /** Parameter type. */
4032 typedef discrete_distribution<_IntType> distribution_type;
4033 friend class discrete_distribution<_IntType>;
4036 : _M_prob(), _M_cp()
4037 { _M_initialize(); }
4039 template<typename _InputIterator>
4040 param_type(_InputIterator __wbegin,
4041 _InputIterator __wend)
4042 : _M_prob(__wbegin, __wend), _M_cp()
4043 { _M_initialize(); }
4045 param_type(initializer_list<double> __wil)
4046 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4047 { _M_initialize(); }
4049 template<typename _Func>
4050 param_type(size_t __nw, double __xmin, double __xmax,
4054 probabilities() const
4061 std::vector<double> _M_prob;
4062 std::vector<double> _M_cp;
4065 discrete_distribution()
4069 template<typename _InputIterator>
4070 discrete_distribution(_InputIterator __wbegin,
4071 _InputIterator __wend)
4072 : _M_param(__wbegin, __wend)
4075 discrete_distribution(initializer_list<double> __wl)
4079 template<typename _Func>
4080 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4082 : _M_param(__nw, __xmin, __xmax, __fw)
4086 discrete_distribution(const param_type& __p)
4091 * @brief Resets the distribution state.
4098 * @brief Returns the probabilities of the distribution.
4101 probabilities() const
4102 { return _M_param.probabilities(); }
4105 * @brief Returns the parameter set of the distribution.
4109 { return _M_param; }
4112 * @brief Sets the parameter set of the distribution.
4113 * @param __param The new parameter set of the distribution.
4116 param(const param_type& __param)
4117 { _M_param = __param; }
4120 * @brief Returns the greatest lower bound value of the distribution.
4124 { return result_type(0); }
4127 * @brief Returns the least upper bound value of the distribution.
4131 { return this->_M_param._M_prob.size() - 1; }
4133 template<typename _UniformRandomNumberGenerator>
4135 operator()(_UniformRandomNumberGenerator& __urng)
4136 { return this->operator()(__urng, this->param()); }
4138 template<typename _UniformRandomNumberGenerator>
4140 operator()(_UniformRandomNumberGenerator& __urng,
4141 const param_type& __p);
4144 * @brief Inserts a %discrete_distribution random number distribution
4145 * @p __x into the output stream @p __os.
4147 * @param __os An output stream.
4148 * @param __x A %discrete_distribution random number distribution.
4150 * @returns The output stream with the state of @p __x inserted or in
4153 template<typename _IntType1, typename _CharT, typename _Traits>
4154 friend std::basic_ostream<_CharT, _Traits>&
4155 operator<<(std::basic_ostream<_CharT, _Traits>&,
4156 const std::discrete_distribution<_IntType1>&);
4159 * @brief Extracts a %discrete_distribution random number distribution
4160 * @p __x from the input stream @p __is.
4162 * @param __is An input stream.
4163 * @param __x A %discrete_distribution random number
4166 * @returns The input stream with @p __x extracted or in an error
4169 template<typename _IntType1, typename _CharT, typename _Traits>
4170 friend std::basic_istream<_CharT, _Traits>&
4171 operator>>(std::basic_istream<_CharT, _Traits>&,
4172 std::discrete_distribution<_IntType1>&);
4175 param_type _M_param;
4180 * @brief A piecewise_constant_distribution random number distribution.
4182 * The formula for the piecewise constant probability mass function is
4185 template<typename _RealType = double>
4186 class piecewise_constant_distribution
4189 /** The type of the range of the distribution. */
4190 typedef _RealType result_type;
4191 /** Parameter type. */
4194 typedef piecewise_constant_distribution<_RealType> distribution_type;
4195 friend class piecewise_constant_distribution<_RealType>;
4198 : _M_int(), _M_den(), _M_cp()
4199 { _M_initialize(); }
4201 template<typename _InputIteratorB, typename _InputIteratorW>
4202 param_type(_InputIteratorB __bfirst,
4203 _InputIteratorB __bend,
4204 _InputIteratorW __wbegin);
4206 template<typename _Func>
4207 param_type(initializer_list<_RealType> __bi, _Func __fw);
4209 template<typename _Func>
4210 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4213 std::vector<_RealType>
4225 std::vector<_RealType> _M_int;
4226 std::vector<double> _M_den;
4227 std::vector<double> _M_cp;
4231 piecewise_constant_distribution()
4235 template<typename _InputIteratorB, typename _InputIteratorW>
4236 piecewise_constant_distribution(_InputIteratorB __bfirst,
4237 _InputIteratorB __bend,
4238 _InputIteratorW __wbegin)
4239 : _M_param(__bfirst, __bend, __wbegin)
4242 template<typename _Func>
4243 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4245 : _M_param(__bl, __fw)
4248 template<typename _Func>
4249 piecewise_constant_distribution(size_t __nw,
4250 _RealType __xmin, _RealType __xmax,
4252 : _M_param(__nw, __xmin, __xmax, __fw)
4256 piecewise_constant_distribution(const param_type& __p)
4261 * @brief Resets the distribution state.
4268 * @brief Returns a vector of the intervals.
4270 std::vector<_RealType>
4272 { return _M_param.intervals(); }
4275 * @brief Returns a vector of the probability densities.
4279 { return _M_param.densities(); }
4282 * @brief Returns the parameter set of the distribution.
4286 { return _M_param; }
4289 * @brief Sets the parameter set of the distribution.
4290 * @param __param The new parameter set of the distribution.
4293 param(const param_type& __param)
4294 { _M_param = __param; }
4297 * @brief Returns the greatest lower bound value of the distribution.
4301 { return this->_M_param._M_int.front(); }
4304 * @brief Returns the least upper bound value of the distribution.
4308 { return this->_M_param._M_int.back(); }
4310 template<typename _UniformRandomNumberGenerator>
4312 operator()(_UniformRandomNumberGenerator& __urng)
4313 { return this->operator()(__urng, this->param()); }
4315 template<typename _UniformRandomNumberGenerator>
4317 operator()(_UniformRandomNumberGenerator& __urng,
4318 const param_type& __p);
4321 * @brief Inserts a %piecewise_constan_distribution random
4322 * number distribution @p __x into the output stream @p __os.
4324 * @param __os An output stream.
4325 * @param __x A %piecewise_constan_distribution random number
4328 * @returns The output stream with the state of @p __x inserted or in
4331 template<typename _RealType1, typename _CharT, typename _Traits>
4332 friend std::basic_ostream<_CharT, _Traits>&
4333 operator<<(std::basic_ostream<_CharT, _Traits>&,
4334 const std::piecewise_constant_distribution<_RealType1>&);
4337 * @brief Extracts a %piecewise_constan_distribution random
4338 * number distribution @p __x from the input stream @p __is.
4340 * @param __is An input stream.
4341 * @param __x A %piecewise_constan_distribution random number
4344 * @returns The input stream with @p __x extracted or in an error
4347 template<typename _RealType1, typename _CharT, typename _Traits>
4348 friend std::basic_istream<_CharT, _Traits>&
4349 operator>>(std::basic_istream<_CharT, _Traits>&,
4350 std::piecewise_constant_distribution<_RealType1>&);
4353 param_type _M_param;
4358 * @brief A piecewise_linear_distribution random number distribution.
4360 * The formula for the piecewise linear probability mass function is
4363 template<typename _RealType = double>
4364 class piecewise_linear_distribution
4367 /** The type of the range of the distribution. */
4368 typedef _RealType result_type;
4369 /** Parameter type. */
4372 typedef piecewise_linear_distribution<_RealType> distribution_type;
4373 friend class piecewise_linear_distribution<_RealType>;
4376 : _M_int(), _M_den(), _M_cp(), _M_m()
4377 { _M_initialize(); }
4379 template<typename _InputIteratorB, typename _InputIteratorW>
4380 param_type(_InputIteratorB __bfirst,
4381 _InputIteratorB __bend,
4382 _InputIteratorW __wbegin);
4384 template<typename _Func>
4385 param_type(initializer_list<_RealType> __bl, _Func __fw);
4387 template<typename _Func>
4388 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4391 std::vector<_RealType>
4403 std::vector<_RealType> _M_int;
4404 std::vector<double> _M_den;
4405 std::vector<double> _M_cp;
4406 std::vector<double> _M_m;
4410 piecewise_linear_distribution()
4414 template<typename _InputIteratorB, typename _InputIteratorW>
4415 piecewise_linear_distribution(_InputIteratorB __bfirst,
4416 _InputIteratorB __bend,
4417 _InputIteratorW __wbegin)
4418 : _M_param(__bfirst, __bend, __wbegin)
4421 template<typename _Func>
4422 piecewise_linear_distribution(initializer_list<_RealType> __bl,
4424 : _M_param(__bl, __fw)
4427 template<typename _Func>
4428 piecewise_linear_distribution(size_t __nw,
4429 _RealType __xmin, _RealType __xmax,
4431 : _M_param(__nw, __xmin, __xmax, __fw)
4435 piecewise_linear_distribution(const param_type& __p)
4440 * Resets the distribution state.
4447 * @brief Return the intervals of the distribution.
4449 std::vector<_RealType>
4451 { return _M_param.intervals(); }
4454 * @brief Return a vector of the probability densities of the
4459 { return _M_param.densities(); }
4462 * @brief Returns the parameter set of the distribution.
4466 { return _M_param; }
4469 * @brief Sets the parameter set of the distribution.
4470 * @param __param The new parameter set of the distribution.
4473 param(const param_type& __param)
4474 { _M_param = __param; }
4477 * @brief Returns the greatest lower bound value of the distribution.
4481 { return this->_M_param._M_int.front(); }
4484 * @brief Returns the least upper bound value of the distribution.
4488 { return this->_M_param._M_int.back(); }
4490 template<typename _UniformRandomNumberGenerator>
4492 operator()(_UniformRandomNumberGenerator& __urng)
4493 { return this->operator()(__urng, this->param()); }
4495 template<typename _UniformRandomNumberGenerator>
4497 operator()(_UniformRandomNumberGenerator& __urng,
4498 const param_type& __p);
4501 * @brief Inserts a %piecewise_linear_distribution random number
4502 * distribution @p __x into the output stream @p __os.
4504 * @param __os An output stream.
4505 * @param __x A %piecewise_linear_distribution random number
4508 * @returns The output stream with the state of @p __x inserted or in
4511 template<typename _RealType1, typename _CharT, typename _Traits>
4512 friend std::basic_ostream<_CharT, _Traits>&
4513 operator<<(std::basic_ostream<_CharT, _Traits>&,
4514 const std::piecewise_linear_distribution<_RealType1>&);
4517 * @brief Extracts a %piecewise_linear_distribution random number
4518 * distribution @p __x from the input stream @p __is.
4520 * @param __is An input stream.
4521 * @param __x A %piecewise_linear_distribution random number
4524 * @returns The input stream with @p __x extracted or in an error
4527 template<typename _RealType1, typename _CharT, typename _Traits>
4528 friend std::basic_istream<_CharT, _Traits>&
4529 operator>>(std::basic_istream<_CharT, _Traits>&,
4530 std::piecewise_linear_distribution<_RealType1>&);
4533 param_type _M_param;
4537 /* @} */ // group std_random_distributions_poisson
4539 /* @} */ // group std_random_distributions
4542 * @addtogroup std_random_utilities Random Number Utilities
4543 * @ingroup std_random
4548 * @brief The seed_seq class generates sequences of seeds for random
4549 * number generators.
4555 /** The type of the seed vales. */
4556 typedef uint_least32_t result_type;
4558 /** Default constructor. */
4563 template<typename _IntType>
4564 seed_seq(std::initializer_list<_IntType> il);
4566 template<typename _InputIterator>
4567 seed_seq(_InputIterator __begin, _InputIterator __end);
4569 // generating functions
4570 template<typename _RandomAccessIterator>
4572 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
4574 // property functions
4576 { return _M_v.size(); }
4578 template<typename OutputIterator>
4580 param(OutputIterator __dest) const
4581 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
4585 std::vector<result_type> _M_v;
4588 /* @} */ // group std_random_utilities
4590 /* @} */ // group std_random