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 __a
, _Tp __c
, _Tp __m
, bool>
74 // Dispatch based on modulus value to prevent divide-by-zero compile-time
75 // errors when m == 0.
76 template<typename _Tp
, _Tp __a
, _Tp __c
, _Tp __m
>
79 { return _Mod
<_Tp
, __a
, __c
, __m
, __m
== 0>::__calc(__x
); }
81 typedef __gnu_cxx::__conditional_type
<(sizeof(unsigned) == 4),
82 unsigned, unsigned long>::__type _UInt32Type
;
85 * An adaptor class for converting the output of any Generator into
86 * the input for a specific Distribution.
88 template<typename _Engine
, typename _DInputType
>
93 _Adaptor(_Engine
& __g
)
99 if (is_integral
<_DInputType
>::value
)
102 return _DInputType(0);
108 if (is_integral
<_DInputType
>::value
)
111 return _DInputType(1);
115 * Converts a value generated by the adapted random number generator
116 * into a value in the input domain for the dependent random number
119 * Because the type traits are compile time constants only the
120 * appropriate clause of the if statements will actually be emitted
126 if (is_integral
<_DInputType
>::value
)
129 return generate_canonical
<_DInputType
,
130 numeric_limits
<_DInputType
>::digits
,
137 } // namespace __detail
140 * @addtogroup std_random_generators Random Number Generators
141 * @ingroup std_random
143 * These classes define objects which provide random or pseudorandom
144 * numbers, either from a discrete or a continuous interval. The
145 * random number generator supplied as a part of this library are
146 * all uniform random number generators which provide a sequence of
147 * random number uniformly distributed over their range.
149 * A number generator is a function object with an operator() that
150 * takes zero arguments and returns a number.
152 * A compliant random number generator must satisfy the following
153 * requirements. <table border=1 cellpadding=10 cellspacing=0>
154 * <caption align=top>Random Number Generator Requirements</caption>
155 * <tr><td>To be documented.</td></tr> </table>
161 * @brief A model of a linear congruential random number generator.
163 * A random number generator that produces pseudorandom numbers using the
164 * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
166 * The template parameter @p _UIntType must be an unsigned integral type
167 * large enough to store values up to (__m-1). If the template parameter
168 * @p __m is 0, the modulus @p __m used is
169 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
170 * parameters @p __a and @p __c must be less than @p __m.
172 * The size of the state is @f$ 1 @f$.
174 template<typename _UIntType
, _UIntType __a
, _UIntType __c
, _UIntType __m
>
175 class linear_congruential_engine
177 __glibcxx_class_requires(_UIntType
, _UnsignedIntegerConcept
)
178 static_assert(__m
== 0 || (__a
< __m
&& __c
< __m
),
179 "template arguments out of bounds"
180 " in linear_congruential_engine");
183 /** The type of the generated random value. */
184 typedef _UIntType result_type
;
186 /** The multiplier. */
187 static const result_type multiplier
= __a
;
189 static const result_type increment
= __c
;
191 static const result_type modulus
= __m
;
192 static const result_type default_seed
= 1u;
195 * @brief Constructs a %linear_congruential_engine random number
196 * generator engine with seed @p __s. The default seed value
199 * @param __s The initial seed value.
202 linear_congruential_engine(result_type __s
= default_seed
)
206 * @brief Constructs a %linear_congruential_engine random number
207 * generator engine seeded from the seed sequence @p __q.
209 * @param __q the seed sequence.
212 linear_congruential_engine(seed_seq
& __q
)
216 * @brief Reseeds the %linear_congruential_engine random number generator
217 * engine sequence to the seed @p __s.
219 * @param __s The new seed.
222 seed(result_type __s
= default_seed
);
225 * @brief Reseeds the %linear_congruential_engine random number generator
227 * sequence using values from the seed sequence @p __q.
229 * @param __q the seed sequence.
235 * @brief Gets the smallest possible value in the output range.
237 * The minimum depends on the @p __c parameter: if it is zero, the
238 * minimum generated must be > 0, otherwise 0 is allowed.
240 * @todo This should be constexpr.
244 { return __c
== 0u ? 1u : 0u; }
247 * @brief Gets the largest possible value in the output range.
249 * @todo This should be constexpr.
256 * @brief Discard a sequence of random numbers.
258 * @todo Look for a faster way to do discard.
261 discard(unsigned long long __z
)
263 for (; __z
!= 0ULL; --__z
)
268 * @brief Gets the next random number in the sequence.
274 * @brief Compares two linear congruential random number generator
275 * objects of the same type for equality.
277 * @param __lhs A linear congruential random number generator object.
278 * @param __rhs Another linear congruential random number generator
281 * @returns true if the two objects are equal, false otherwise.
284 operator==(const linear_congruential_engine
& __lhs
,
285 const linear_congruential_engine
& __rhs
)
286 { return __lhs
._M_x
== __rhs
._M_x
; }
289 * @brief Writes the textual representation of the state x(i) of x to
292 * @param __os The output stream.
293 * @param __lcr A % linear_congruential_engine random number generator.
296 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
298 typename _CharT
, typename _Traits
>
299 friend std::basic_ostream
<_CharT
, _Traits
>&
300 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
301 const std::linear_congruential_engine
<_UIntType1
,
305 * @brief Sets the state of the engine by reading its textual
306 * representation from @p __is.
308 * The textual representation must have been previously written using
309 * an output stream whose imbued locale and whose type's template
310 * specialization arguments _CharT and _Traits were the same as those
313 * @param __is The input stream.
314 * @param __lcr A % linear_congruential_engine random number generator.
317 template<typename _UIntType1
, _UIntType1 __a1
, _UIntType1 __c1
,
319 typename _CharT
, typename _Traits
>
320 friend std::basic_istream
<_CharT
, _Traits
>&
321 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
322 std::linear_congruential_engine
<_UIntType1
, __a1
,
331 * A generalized feedback shift register discrete random number generator.
333 * This algorithm avoids multiplication and division and is designed to be
334 * friendly to a pipelined architecture. If the parameters are chosen
335 * correctly, this generator will produce numbers with a very long period and
336 * fairly good apparent entropy, although still not cryptographically strong.
338 * The best way to use this generator is with the predefined mt19937 class.
340 * This algorithm was originally invented by Makoto Matsumoto and
343 * @var word_size The number of bits in each element of the state vector.
344 * @var state_size The degree of recursion.
345 * @var shift_size The period parameter.
346 * @var mask_bits The separation point bit index.
347 * @var parameter_a The last row of the twist matrix.
348 * @var output_u The first right-shift tempering matrix parameter.
349 * @var output_s The first left-shift tempering matrix parameter.
350 * @var output_b The first left-shift tempering matrix mask.
351 * @var output_t The second left-shift tempering matrix parameter.
352 * @var output_c The second left-shift tempering matrix mask.
353 * @var output_l The second right-shift tempering matrix parameter.
355 template<typename _UIntType
, size_t __w
,
356 size_t __n
, size_t __m
, size_t __r
,
357 _UIntType __a
, size_t __u
, _UIntType __d
, size_t __s
,
358 _UIntType __b
, size_t __t
,
359 _UIntType __c
, size_t __l
, _UIntType __f
>
360 class mersenne_twister_engine
362 __glibcxx_class_requires(_UIntType
, _UnsignedIntegerConcept
)
364 static_assert(__m
>= 1U,
365 "mersenne_twister_engine template arguments out of bounds");
366 static_assert(__n
>= __m
,
367 "mersenne_twister_engine template arguments out of bounds");
368 static_assert(__w
>= __r
,
369 "mersenne_twister_engine template arguments out of bounds");
370 static_assert(__w
>= __u
,
371 "mersenne_twister_engine template arguments out of bounds");
372 static_assert(__w
>= __s
,
373 "mersenne_twister_engine template arguments out of bounds");
374 static_assert(__w
>= __t
,
375 "mersenne_twister_engine template arguments out of bounds");
376 static_assert(__w
>= __l
,
377 "mersenne_twister_engine template arguments out of bounds");
379 static_cast<size_t>(numeric_limits
<_UIntType
>::digits
),
380 "mersenne_twister_engine template arguments out of bounds");
381 static_assert(__a
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
382 "mersenne_twister_engine template arguments out of bounds");
383 static_assert(__b
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
384 "mersenne_twister_engine template arguments out of bounds");
385 static_assert(__c
<= (__detail::_Shift
<_UIntType
, __w
>::__value
- 1),
386 "mersenne_twister_engine template arguments out of bounds");
389 /** The type of the generated random value. */
390 typedef _UIntType result_type
;
393 static const size_t word_size
= __w
;
394 static const size_t state_size
= __n
;
395 static const size_t shift_size
= __m
;
396 static const size_t mask_bits
= __r
;
397 static const result_type xor_mask
= __a
;
398 static const size_t tempering_u
= __u
;
399 static const result_type tempering_d
= __d
;
400 static const size_t tempering_s
= __s
;
401 static const result_type tempering_b
= __b
;
402 static const size_t tempering_t
= __t
;
403 static const result_type tempering_c
= __c
;
404 static const size_t tempering_l
= __l
;
405 static const size_t initialization_multiplier
= __f
;
406 static const result_type default_seed
= 5489u;
408 // constructors and member function
410 mersenne_twister_engine(result_type __sd
= default_seed
)
414 * @brief Constructs a %mersenne_twister_engine random number generator
415 * engine seeded from the seed sequence @p __q.
417 * @param __q the seed sequence.
420 mersenne_twister_engine(seed_seq
& __q
)
424 seed(result_type __sd
= default_seed
);
430 * @brief Gets the smallest possible value in the output range.
432 * @todo This should be constexpr.
439 * @brief Gets the largest possible value in the output range.
441 * @todo This should be constexpr.
445 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
448 * @brief Discard a sequence of random numbers.
450 * @todo Look for a faster way to do discard.
453 discard(unsigned long long __z
)
455 for (; __z
!= 0ULL; --__z
)
463 * @brief Compares two % mersenne_twister_engine random number generator
464 * objects of the same type for equality.
466 * @param __lhs A % mersenne_twister_engine random number generator
468 * @param __rhs Another % mersenne_twister_engine random number
471 * @returns true if the two objects are equal, false otherwise.
474 operator==(const mersenne_twister_engine
& __lhs
,
475 const mersenne_twister_engine
& __rhs
)
476 { return std::equal(__lhs
._M_x
, __lhs
._M_x
+ state_size
, __rhs
._M_x
); }
479 * @brief Inserts the current state of a % mersenne_twister_engine
480 * random number generator engine @p __x into the output stream
483 * @param __os An output stream.
484 * @param __x A % mersenne_twister_engine random number generator
487 * @returns The output stream with the state of @p __x inserted or in
490 template<typename _UIntType1
,
491 size_t __w1
, size_t __n1
,
492 size_t __m1
, size_t __r1
,
493 _UIntType1 __a1
, size_t __u1
,
494 _UIntType1 __d1
, size_t __s1
,
495 _UIntType1 __b1
, size_t __t1
,
496 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
497 typename _CharT
, typename _Traits
>
498 friend std::basic_ostream
<_CharT
, _Traits
>&
499 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
500 const std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
,
501 __m1
, __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
505 * @brief Extracts the current state of a % mersenne_twister_engine
506 * random number generator engine @p __x from the input stream
509 * @param __is An input stream.
510 * @param __x A % mersenne_twister_engine random number generator
513 * @returns The input stream with the state of @p __x extracted or in
516 template<typename _UIntType1
,
517 size_t __w1
, size_t __n1
,
518 size_t __m1
, size_t __r1
,
519 _UIntType1 __a1
, size_t __u1
,
520 _UIntType1 __d1
, size_t __s1
,
521 _UIntType1 __b1
, size_t __t1
,
522 _UIntType1 __c1
, size_t __l1
, _UIntType1 __f1
,
523 typename _CharT
, typename _Traits
>
524 friend std::basic_istream
<_CharT
, _Traits
>&
525 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
526 std::mersenne_twister_engine
<_UIntType1
, __w1
, __n1
, __m1
,
527 __r1
, __a1
, __u1
, __d1
, __s1
, __b1
, __t1
, __c1
,
531 _UIntType _M_x
[state_size
];
536 * @brief The Marsaglia-Zaman generator.
538 * This is a model of a Generalized Fibonacci discrete random number
539 * generator, sometimes referred to as the SWC generator.
541 * A discrete random number generator that produces pseudorandom
542 * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
543 * carry_{i-1}) \bmod m @f$.
545 * The size of the state is @f$ r @f$
546 * and the maximum period of the generator is @f$ m^r - m^s - 1 @f$.
548 * @var _M_x The state of the generator. This is a ring buffer.
549 * @var _M_carry The carry.
550 * @var _M_p Current index of x(i - r).
552 template<typename _UIntType
, size_t __w
, size_t __s
, size_t __r
>
553 class subtract_with_carry_engine
555 __glibcxx_class_requires(_UIntType
, _UnsignedIntegerConcept
)
556 static_assert(__s
> 0U && __r
> __s
558 && __w
<= static_cast<size_t>(numeric_limits
<_UIntType
>::digits
),
559 "template arguments out of bounds"
560 " in subtract_with_carry_engine");
563 /** The type of the generated random value. */
564 typedef _UIntType result_type
;
567 static const size_t word_size
= __w
;
568 static const size_t short_lag
= __s
;
569 static const size_t long_lag
= __r
;
570 static const result_type default_seed
= 19780503u;
573 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
574 * random number generator.
577 subtract_with_carry_engine(result_type __sd
= default_seed
)
578 { this->seed(__sd
); }
581 * @brief Constructs a %subtract_with_carry_engine random number engine
582 * seeded from the seed sequence @p __q.
584 * @param __q the seed sequence.
587 subtract_with_carry_engine(seed_seq
& __q
)
591 * @brief Seeds the initial state @f$ x_0 @f$ of the random number
594 * N1688[4.19] modifies this as follows. If @p __value == 0,
595 * sets value to 19780503. In any case, with a linear
596 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
597 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
598 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
599 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
600 * set carry to 1, otherwise sets carry to 0.
603 seed(result_type __sd
= default_seed
);
606 * @brief Seeds the initial state @f$ x_0 @f$ of the
607 * % subtract_with_carry_engine random number generator.
613 * @brief Gets the inclusive minimum value of the range of random
614 * integers returned by this generator.
616 * @todo This should be constexpr.
623 * @brief Gets the inclusive maximum value of the range of random
624 * integers returned by this generator.
626 * @todo This should be constexpr.
630 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
633 * @brief Discard a sequence of random numbers.
635 * @todo Look for a faster way to do discard.
638 discard(unsigned long long __z
)
640 for (; __z
!= 0ULL; --__z
)
645 * @brief Gets the next random number in the sequence.
651 * @brief Compares two % subtract_with_carry_engine random number
652 * generator objects of the same type for equality.
654 * @param __lhs A % subtract_with_carry_engine random number generator
656 * @param __rhs Another % subtract_with_carry_engine random number
659 * @returns true if the two objects are equal, false otherwise.
662 operator==(const subtract_with_carry_engine
& __lhs
,
663 const subtract_with_carry_engine
& __rhs
)
664 { return std::equal(__lhs
._M_x
, __lhs
._M_x
+ long_lag
, __rhs
._M_x
); }
667 * @brief Inserts the current state of a % subtract_with_carry_engine
668 * random number generator engine @p __x into the output stream
671 * @param __os An output stream.
672 * @param __x A % subtract_with_carry_engine random number generator
675 * @returns The output stream with the state of @p __x inserted or in
678 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
679 typename _CharT
, typename _Traits
>
680 friend std::basic_ostream
<_CharT
, _Traits
>&
681 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
682 const std::subtract_with_carry_engine
<_UIntType1
, __w1
,
686 * @brief Extracts the current state of a % subtract_with_carry_engine
687 * random number generator engine @p __x from the input stream
690 * @param __is An input stream.
691 * @param __x A % subtract_with_carry_engine random number generator engine.
693 * @returns The input stream with the state of @p __x extracted or in
696 template<typename _UIntType1
, size_t __w1
, size_t __s1
, size_t __r1
,
697 typename _CharT
, typename _Traits
>
698 friend std::basic_istream
<_CharT
, _Traits
>&
699 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
700 std::subtract_with_carry_engine
<_UIntType1
, __w1
,
704 _UIntType _M_x
[long_lag
];
710 * Produces random numbers from some base engine by discarding blocks of
713 * 0 <= @p __r <= @p __p
715 template<typename _RandomNumberEngine
, size_t __p
, size_t __r
>
716 class discard_block_engine
718 static_assert(__r
>= 1U && __p
>= __r
,
719 "template arguments out of bounds"
720 " in discard_block_engine");
723 /** The type of the generated random value. */
724 typedef typename
_RandomNumberEngine::result_type result_type
;
727 static const size_t block_size
= __p
;
728 static const size_t used_block
= __r
;
731 * @brief Constructs a default %discard_block_engine engine.
733 * The underlying engine is default constructed as well.
735 discard_block_engine()
736 : _M_b(), _M_n(0) { }
739 * @brief Copy constructs a %discard_block_engine engine.
741 * Copies an existing base class random number generator.
742 * @param rng An existing (base class) engine object.
745 discard_block_engine(const _RandomNumberEngine
& __rne
)
746 : _M_b(__rne
), _M_n(0) { }
749 * @brief Move constructs a %discard_block_engine engine.
751 * Copies an existing base class random number generator.
752 * @param rng An existing (base class) engine object.
755 discard_block_engine(_RandomNumberEngine
&& __rne
)
756 : _M_b(std::move(__rne
)), _M_n(0) { }
759 * @brief Seed constructs a %discard_block_engine engine.
761 * Constructs the underlying generator engine seeded with @p __s.
762 * @param __s A seed value for the base class engine.
765 discard_block_engine(result_type __s
)
766 : _M_b(__s
), _M_n(0) { }
769 * @brief Generator construct a %discard_block_engine engine.
771 * @param __q A seed sequence.
774 discard_block_engine(seed_seq
& __q
)
779 * @brief Reseeds the %discard_block_engine object with the default
780 * seed for the underlying base class generator engine.
790 * @brief Reseeds the %discard_block_engine object with the default
791 * seed for the underlying base class generator engine.
794 seed(result_type __s
)
801 * @brief Reseeds the %discard_block_engine object with the given seed
803 * @param __q A seed generator function.
813 * @brief Gets a const reference to the underlying generator engine
816 const _RandomNumberEngine
&
821 * @brief Gets the minimum value in the generated random number range.
823 * @todo This should be constexpr.
827 { return _M_b
.min(); }
830 * @brief Gets the maximum value in the generated random number range.
832 * @todo This should be constexpr.
836 { return _M_b
.max(); }
839 * @brief Discard a sequence of random numbers.
841 * @todo Look for a faster way to do discard.
844 discard(unsigned long long __z
)
846 for (; __z
!= 0ULL; --__z
)
851 * @brief Gets the next value in the generated random number sequence.
857 * @brief Compares two %discard_block_engine random number generator
858 * objects of the same type for equality.
860 * @param __lhs A %discard_block_engine random number generator object.
861 * @param __rhs Another %discard_block_engine random number generator
864 * @returns true if the two objects are equal, false otherwise.
867 operator==(const discard_block_engine
& __lhs
,
868 const discard_block_engine
& __rhs
)
869 { return (__lhs
._M_b
== __rhs
._M_b
) && (__lhs
._M_n
== __rhs
._M_n
); }
872 * @brief Inserts the current state of a %discard_block_engine random
873 * number generator engine @p __x into the output stream
876 * @param __os An output stream.
877 * @param __x A %discard_block_engine random number generator engine.
879 * @returns The output stream with the state of @p __x inserted or in
882 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
883 typename _CharT
, typename _Traits
>
884 friend std::basic_ostream
<_CharT
, _Traits
>&
885 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
886 const std::discard_block_engine
<_RandomNumberEngine1
,
890 * @brief Extracts the current state of a % subtract_with_carry_engine
891 * random number generator engine @p __x from the input stream
894 * @param __is An input stream.
895 * @param __x A %discard_block_engine random number generator engine.
897 * @returns The input stream with the state of @p __x extracted or in
900 template<typename _RandomNumberEngine1
, size_t __p1
, size_t __r1
,
901 typename _CharT
, typename _Traits
>
902 friend std::basic_istream
<_CharT
, _Traits
>&
903 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
904 std::discard_block_engine
<_RandomNumberEngine1
,
908 _RandomNumberEngine _M_b
;
913 * Produces random numbers by combining random numbers from some base
914 * engine to produce random numbers with a specifies number of bits @p __w.
916 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
>
917 class independent_bits_engine
919 static_assert(__w
> 0U
921 static_cast<size_t>(numeric_limits
<_UIntType
>::digits
),
922 "template arguments out of bounds "
923 "in independent_bits_engine");
926 /** The type of the generated random value. */
927 typedef _UIntType result_type
;
930 * @brief Constructs a default %independent_bits_engine engine.
932 * The underlying engine is default constructed as well.
934 independent_bits_engine()
938 * @brief Copy constructs a %independent_bits_engine engine.
940 * Copies an existing base class random number generator.
941 * @param rng An existing (base class) engine object.
944 independent_bits_engine(const _RandomNumberEngine
& __rne
)
948 * @brief Move constructs a %independent_bits_engine engine.
950 * Copies an existing base class random number generator.
951 * @param rng An existing (base class) engine object.
954 independent_bits_engine(_RandomNumberEngine
&& __rne
)
955 : _M_b(std::move(__rne
)) { }
958 * @brief Seed constructs a %independent_bits_engine engine.
960 * Constructs the underlying generator engine seeded with @p __s.
961 * @param __s A seed value for the base class engine.
964 independent_bits_engine(result_type __s
)
968 * @brief Generator construct a %independent_bits_engine engine.
970 * @param __q A seed sequence.
973 independent_bits_engine(seed_seq
& __q
)
978 * @brief Reseeds the %independent_bits_engine object with the default
979 * seed for the underlying base class generator engine.
986 * @brief Reseeds the %independent_bits_engine object with the default
987 * seed for the underlying base class generator engine.
990 seed(result_type __s
)
994 * @brief Reseeds the %independent_bits_engine object with the given
996 * @param __q A seed generator function.
1003 * @brief Gets a const reference to the underlying generator engine
1006 const _RandomNumberEngine
&
1011 * @brief Gets the minimum value in the generated random number range.
1013 * @todo This should be constexpr.
1020 * @brief Gets the maximum value in the generated random number range.
1022 * @todo This should be constexpr.
1026 { return __detail::_Shift
<_UIntType
, __w
>::__value
- 1; }
1029 * @brief Discard a sequence of random numbers.
1031 * @todo Look for a faster way to do discard.
1034 discard(unsigned long long __z
)
1036 for (; __z
!= 0ULL; --__z
)
1041 * @brief Gets the next value in the generated random number sequence.
1047 * @brief Compares two %independent_bits_engine random number generator
1048 * objects of the same type for equality.
1050 * @param __lhs A %independent_bits_engine random number generator
1052 * @param __rhs Another %independent_bits_engine random number generator
1055 * @returns true if the two objects are equal, false otherwise.
1058 operator==(const independent_bits_engine
& __lhs
,
1059 const independent_bits_engine
& __rhs
)
1060 { return __lhs
._M_b
== __rhs
._M_b
; }
1063 * @brief Extracts the current state of a % subtract_with_carry_engine
1064 * random number generator engine @p __x from the input stream
1067 * @param __is An input stream.
1068 * @param __x A %independent_bits_engine random number generator
1071 * @returns The input stream with the state of @p __x extracted or in
1074 template<typename _CharT
, typename _Traits
>
1075 friend std::basic_istream
<_CharT
, _Traits
>&
1076 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
1077 std::independent_bits_engine
<_RandomNumberEngine
,
1078 __w
, _UIntType
>& __x
)
1085 _RandomNumberEngine _M_b
;
1089 * @brief Inserts the current state of a %independent_bits_engine random
1090 * number generator engine @p __x into the output stream @p __os.
1092 * @param __os An output stream.
1093 * @param __x A %independent_bits_engine random number generator engine.
1095 * @returns The output stream with the state of @p __x inserted or in
1098 template<typename _RandomNumberEngine
, size_t __w
, typename _UIntType
,
1099 typename _CharT
, typename _Traits
>
1100 std::basic_ostream
<_CharT
, _Traits
>&
1101 operator<<(std::basic_ostream
<_CharT
, _Traits
>& __os
,
1102 const std::independent_bits_engine
<_RandomNumberEngine
,
1103 __w
, _UIntType
>& __x
)
1110 * @brief Produces random numbers by combining random numbers from some
1111 * base engine to produce random numbers with a specifies number of bits
1114 template<typename _RandomNumberEngine
, size_t __k
>
1115 class shuffle_order_engine
1117 static_assert(__k
>= 1U,
1118 "template arguments out of bounds"
1119 " in shuffle_order_engine");
1122 /** The type of the generated random value. */
1123 typedef typename
_RandomNumberEngine::result_type result_type
;
1125 static const size_t table_size
= __k
;
1128 * @brief Constructs a default %shuffle_order_engine engine.
1130 * The underlying engine is default constructed as well.
1132 shuffle_order_engine()
1134 { _M_initialize(); }
1137 * @brief Copy constructs a %shuffle_order_engine engine.
1139 * Copies an existing base class random number generator.
1140 * @param rng An existing (base class) engine object.
1143 shuffle_order_engine(const _RandomNumberEngine
& __rne
)
1145 { _M_initialize(); }
1148 * @brief Move constructs a %shuffle_order_engine engine.
1150 * Copies an existing base class random number generator.
1151 * @param rng An existing (base class) engine object.
1154 shuffle_order_engine(_RandomNumberEngine
&& __rne
)
1155 : _M_b(std::move(__rne
))
1156 { _M_initialize(); }
1159 * @brief Seed constructs a %shuffle_order_engine engine.
1161 * Constructs the underlying generator engine seeded with @p __s.
1162 * @param __s A seed value for the base class engine.
1165 shuffle_order_engine(result_type __s
)
1167 { _M_initialize(); }
1170 * @brief Generator construct a %shuffle_order_engine engine.
1172 * @param __q A seed sequence.
1175 shuffle_order_engine(seed_seq
& __q
)
1177 { _M_initialize(); }
1180 * @brief Reseeds the %shuffle_order_engine object with the default seed
1181 for the underlying base class generator engine.
1191 * @brief Reseeds the %shuffle_order_engine object with the default seed
1192 * for the underlying base class generator engine.
1195 seed(result_type __s
)
1202 * @brief Reseeds the %shuffle_order_engine object with the given seed
1204 * @param __q A seed generator function.
1214 * Gets a const reference to the underlying generator engine object.
1216 const _RandomNumberEngine
&
1221 * Gets the minimum value in the generated random number range.
1223 * @todo This should be constexpr.
1227 { return _M_b
.min(); }
1230 * Gets the maximum value in the generated random number range.
1232 * @todo This should be constexpr.
1236 { return _M_b
.max(); }
1239 * Discard a sequence of random numbers.
1241 * @todo Look for a faster way to do discard.
1244 discard(unsigned long long __z
)
1246 for (; __z
!= 0ULL; --__z
)
1251 * Gets the next value in the generated random number sequence.
1257 * Compares two %shuffle_order_engine random number generator objects
1258 * of the same type for equality.
1260 * @param __lhs A %shuffle_order_engine random number generator object.
1261 * @param __rhs Another %shuffle_order_engine random number generator
1264 * @returns true if the two objects are equal, false otherwise.
1267 operator==(const shuffle_order_engine
& __lhs
,
1268 const shuffle_order_engine
& __rhs
)
1269 { return __lhs
._M_b
== __rhs
._M_b
; }
1272 * @brief Inserts the current state of a %shuffle_order_engine random
1273 * number generator engine @p __x into the output stream
1276 * @param __os An output stream.
1277 * @param __x A %shuffle_order_engine random number generator engine.
1279 * @returns The output stream with the state of @p __x inserted or in
1282 template<typename _RandomNumberEngine1
, size_t __k1
,
1283 typename _CharT
, typename _Traits
>
1284 friend std::basic_ostream
<_CharT
, _Traits
>&
1285 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1286 const std::shuffle_order_engine
<_RandomNumberEngine1
,
1290 * @brief Extracts the current state of a % subtract_with_carry_engine
1291 * random number generator engine @p __x from the input stream
1294 * @param __is An input stream.
1295 * @param __x A %shuffle_order_engine random number generator engine.
1297 * @returns The input stream with the state of @p __x extracted or in
1300 template<typename _RandomNumberEngine1
, size_t __k1
,
1301 typename _CharT
, typename _Traits
>
1302 friend std::basic_istream
<_CharT
, _Traits
>&
1303 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1304 std::shuffle_order_engine
<_RandomNumberEngine1
, __k1
>&);
1307 void _M_initialize()
1309 for (size_t __i
= 0; __i
< __k
; ++__i
)
1314 _RandomNumberEngine _M_b
;
1315 result_type _M_v
[__k
];
1320 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1322 typedef linear_congruential_engine
<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1326 * An alternative LCR (Lehmer Generator function) .
1328 typedef linear_congruential_engine
<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1332 * The classic Mersenne Twister.
1335 * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
1336 * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
1337 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1339 typedef mersenne_twister_engine
<
1345 0xefc60000UL
, 18, 1812433253UL> mt19937
;
1348 * An alternative Mersenne Twister.
1350 typedef mersenne_twister_engine
<
1353 0xb5026f5aa96619e9ULL
, 29,
1354 0x5555555555555555ULL
, 17,
1355 0x71d67fffeda60000ULL
, 37,
1356 0xfff7eee000000000ULL
, 43,
1357 6364136223846793005ULL> mt19937_64
;
1362 typedef subtract_with_carry_engine
<uint_fast32_t, 24, 10, 24>
1365 typedef discard_block_engine
<ranlux24_base
, 223, 23> ranlux24
;
1367 typedef subtract_with_carry_engine
<uint_fast64_t, 48, 5, 12>
1370 typedef discard_block_engine
<ranlux48_base
, 389, 11> ranlux48
;
1375 typedef shuffle_order_engine
<minstd_rand0
, 256> knuth_b
;
1380 typedef minstd_rand0 default_random_engine
;
1383 * A standard interface to a platform-specific non-deterministic
1384 * random number generator (if any are available).
1389 /** The type of the generated random value. */
1390 typedef unsigned int result_type
;
1392 // constructors, destructors and member functions
1394 #ifdef _GLIBCXX_USE_RANDOM_TR1
1397 random_device(const std::string
& __token
= "/dev/urandom")
1399 if ((__token
!= "/dev/urandom" && __token
!= "/dev/random")
1400 || !(_M_file
= std::fopen(__token
.c_str(), "rb")))
1401 std::__throw_runtime_error(__N("random_device::"
1402 "random_device(const std::string&)"));
1406 { std::fclose(_M_file
); }
1411 random_device(const std::string
& __token
= "mt19937")
1412 : _M_mt(_M_strtoul(__token
)) { }
1415 static unsigned long
1416 _M_strtoul(const std::string
& __str
)
1418 unsigned long __ret
= 5489UL;
1419 if (__str
!= "mt19937")
1421 const char* __nptr
= __str
.c_str();
1423 __ret
= std::strtoul(__nptr
, &__endptr
, 0);
1424 if (*__nptr
== '\0' || *__endptr
!= '\0')
1425 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1426 "(const std::string&)"));
1437 { return std::numeric_limits
<result_type
>::min(); }
1441 { return std::numeric_limits
<result_type
>::max(); }
1450 #ifdef _GLIBCXX_USE_RANDOM_TR1
1452 std::fread(reinterpret_cast<void*>(&__ret
), sizeof(result_type
),
1460 // No copy functions.
1461 random_device(const random_device
&) = delete;
1462 void operator=(const random_device
&) = delete;
1466 #ifdef _GLIBCXX_USE_RANDOM_TR1
1473 /* @} */ // group std_random_generators
1476 * @addtogroup std_random_distributions Random Number Distributions
1477 * @ingroup std_random
1482 * @addtogroup std_random_distributions_uniform Uniform Distributions
1483 * @ingroup std_random_distributions
1488 * @brief Uniform discrete distribution for random numbers.
1489 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1490 * probability throughout the range.
1492 template<typename _IntType
= int>
1493 class uniform_int_distribution
1495 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
1498 /** The type of the range of the distribution. */
1499 typedef _IntType result_type
;
1500 /** Parameter type. */
1503 typedef uniform_int_distribution
<_IntType
> distribution_type
;
1506 param_type(_IntType __a
= 0, _IntType __b
= 9)
1507 : _M_a(__a
), _M_b(__b
)
1509 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1527 * @brief Constructs a uniform distribution object.
1530 uniform_int_distribution(_IntType __a
= 0, _IntType __b
= 9)
1531 : _M_param(__a
, __b
)
1535 uniform_int_distribution(const param_type
& __p
)
1540 * @brief Resets the distribution state.
1542 * Does nothing for the uniform integer distribution.
1549 { return _M_param
.a(); }
1553 { return _M_param
.b(); }
1556 * @brief Returns the inclusive lower bound of the distribution range.
1560 { return this->a(); }
1563 * @brief Returns the inclusive upper bound of the distribution range.
1567 { return this->b(); }
1570 * @brief Returns the parameter set of the distribution.
1574 { return _M_param
; }
1577 * @brief Sets the parameter set of the distribution.
1578 * @param __param The new parameter set of the distribution.
1581 param(const param_type
& __param
)
1582 { _M_param
= __param
; }
1585 * Gets a uniformly distributed random number in the range
1588 template<typename _UniformRandomNumberGenerator
>
1590 operator()(_UniformRandomNumberGenerator
& __urng
)
1592 typedef typename
_UniformRandomNumberGenerator::result_type
1594 return _M_call(__urng
, this->a(), this->b(),
1595 typename is_integral
<_UResult_type
>::type());
1599 * Gets a uniform random number in the range @f$[0, n)@f$.
1601 * This function is aimed at use with std::random_shuffle.
1603 template<typename _UniformRandomNumberGenerator
>
1605 operator()(_UniformRandomNumberGenerator
& __urng
,
1606 const param_type
& __p
)
1608 typedef typename
_UniformRandomNumberGenerator::result_type
1610 return _M_call(__urng
, __p
.a(), __p
.b(),
1611 typename is_integral
<_UResult_type
>::type());
1615 template<typename _UniformRandomNumberGenerator
>
1617 _M_call(_UniformRandomNumberGenerator
& __urng
,
1618 result_type __min
, result_type __max
, true_type
);
1620 template<typename _UniformRandomNumberGenerator
>
1622 _M_call(_UniformRandomNumberGenerator
& __urng
,
1623 result_type __min
, result_type __max
, false_type
)
1625 return result_type((__urng() - __urng
.min())
1626 / (__urng
.max() - __urng
.min())
1627 * (__max
- __min
+ 1)) + __min
;
1630 param_type _M_param
;
1634 * @brief Inserts a %uniform_int_distribution random number
1635 * distribution @p __x into the output stream @p os.
1637 * @param __os An output stream.
1638 * @param __x A %uniform_int_distribution random number distribution.
1640 * @returns The output stream with the state of @p __x inserted or in
1643 template<typename _IntType
, typename _CharT
, typename _Traits
>
1644 std::basic_ostream
<_CharT
, _Traits
>&
1645 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1646 const std::uniform_int_distribution
<_IntType
>&);
1649 * @brief Extracts a %uniform_int_distribution random number distribution
1650 * @p __x from the input stream @p __is.
1652 * @param __is An input stream.
1653 * @param __x A %uniform_int_distribution random number generator engine.
1655 * @returns The input stream with @p __x extracted or in an error state.
1657 template<typename _IntType
, typename _CharT
, typename _Traits
>
1658 std::basic_istream
<_CharT
, _Traits
>&
1659 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1660 std::uniform_int_distribution
<_IntType
>&);
1664 * @brief Uniform continuous distribution for random numbers.
1666 * A continuous random distribution on the range [min, max) with equal
1667 * probability throughout the range. The URNG should be real-valued and
1668 * deliver number in the range [0, 1).
1670 template<typename _RealType
= double>
1671 class uniform_real_distribution
1674 /** The type of the range of the distribution. */
1675 typedef _RealType result_type
;
1676 /** Parameter type. */
1679 typedef uniform_real_distribution
<_RealType
> distribution_type
;
1682 param_type(_RealType __a
= _RealType(0),
1683 _RealType __b
= _RealType(1))
1684 : _M_a(__a
), _M_b(__b
)
1686 _GLIBCXX_DEBUG_ASSERT(_M_a
<= _M_b
);
1704 * @brief Constructs a uniform_real_distribution object.
1706 * @param __min [IN] The lower bound of the distribution.
1707 * @param __max [IN] The upper bound of the distribution.
1710 uniform_real_distribution(_RealType __a
= _RealType(0),
1711 _RealType __b
= _RealType(1))
1712 : _M_param(__a
, __b
)
1716 uniform_real_distribution(const param_type
& __p
)
1721 * @brief Resets the distribution state.
1723 * Does nothing for the uniform real distribution.
1730 { return _M_param
.a(); }
1734 { return _M_param
.b(); }
1737 * @brief Returns the inclusive lower bound of the distribution range.
1741 { return this->a(); }
1744 * @brief Returns the inclusive upper bound of the distribution range.
1748 { return this->b(); }
1751 * @brief Returns the parameter set of the distribution.
1755 { return _M_param
; }
1758 * @brief Sets the parameter set of the distribution.
1759 * @param __param The new parameter set of the distribution.
1762 param(const param_type
& __param
)
1763 { _M_param
= __param
; }
1765 template<typename _UniformRandomNumberGenerator
>
1767 operator()(_UniformRandomNumberGenerator
& __urng
)
1769 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1771 return (__aurng() * (this->b() - this->a())) + this->a();
1774 template<typename _UniformRandomNumberGenerator
>
1776 operator()(_UniformRandomNumberGenerator
& __urng
,
1777 const param_type
& __p
)
1779 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
1781 return (__aurng() * (__p
.b() - __p
.a())) + __p
.a();
1785 param_type _M_param
;
1789 * @brief Inserts a %uniform_real_distribution random number
1790 * distribution @p __x into the output stream @p __os.
1792 * @param __os An output stream.
1793 * @param __x A %uniform_real_distribution random number distribution.
1795 * @returns The output stream with the state of @p __x inserted or in
1798 template<typename _RealType
, typename _CharT
, typename _Traits
>
1799 std::basic_ostream
<_CharT
, _Traits
>&
1800 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1801 const std::uniform_real_distribution
<_RealType
>&);
1804 * @brief Extracts a %uniform_real_distribution random number distribution
1805 * @p __x from the input stream @p __is.
1807 * @param __is An input stream.
1808 * @param __x A %uniform_real_distribution random number generator engine.
1810 * @returns The input stream with @p __x extracted or in an error state.
1812 template<typename _RealType
, typename _CharT
, typename _Traits
>
1813 std::basic_istream
<_CharT
, _Traits
>&
1814 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1815 std::uniform_real_distribution
<_RealType
>&);
1817 /* @} */ // group std_random_distributions_uniform
1820 * @addtogroup std_random_distributions_normal Normal Distributions
1821 * @ingroup std_random_distributions
1826 * @brief A normal continuous distribution for random numbers.
1828 * The formula for the normal probability density function is
1829 * @f$ p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1830 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } @f$.
1832 template<typename _RealType
= double>
1833 class normal_distribution
1836 /** The type of the range of the distribution. */
1837 typedef _RealType result_type
;
1838 /** Parameter type. */
1841 typedef normal_distribution
<_RealType
> distribution_type
;
1844 param_type(_RealType __mean
= _RealType(0),
1845 _RealType __stddev
= _RealType(1))
1846 : _M_mean(__mean
), _M_stddev(__stddev
)
1848 _GLIBCXX_DEBUG_ASSERT(_M_stddev
> _RealType(0));
1857 { return _M_stddev
; }
1861 _RealType _M_stddev
;
1866 * Constructs a normal distribution with parameters @f$ mean @f$ and
1867 * standard deviation.
1870 normal_distribution(result_type __mean
= result_type(0),
1871 result_type __stddev
= result_type(1))
1872 : _M_param(__mean
, __stddev
), _M_saved_available(false)
1876 normal_distribution(const param_type
& __p
)
1877 : _M_param(__p
), _M_saved_available(false)
1881 * @brief Resets the distribution state.
1885 { _M_saved_available
= false; }
1888 * @brief Returns the mean of the distribution.
1892 { return _M_param
.mean(); }
1895 * @brief Returns the standard deviation of the distribution.
1899 { return _M_param
.stddev(); }
1902 * @brief Returns the parameter set of the distribution.
1906 { return _M_param
; }
1909 * @brief Sets the parameter set of the distribution.
1910 * @param __param The new parameter set of the distribution.
1913 param(const param_type
& __param
)
1914 { _M_param
= __param
; }
1917 * @brief Returns the greatest lower bound value of the distribution.
1921 { return std::numeric_limits
<result_type
>::min(); }
1924 * @brief Returns the least upper bound value of the distribution.
1928 { return std::numeric_limits
<result_type
>::max(); }
1930 template<typename _UniformRandomNumberGenerator
>
1932 operator()(_UniformRandomNumberGenerator
& __urng
)
1933 { return this->operator()(__urng
, this->param()); }
1935 template<typename _UniformRandomNumberGenerator
>
1937 operator()(_UniformRandomNumberGenerator
& __urng
,
1938 const param_type
& __p
);
1941 * @brief Inserts a %normal_distribution random number distribution
1942 * @p __x into the output stream @p __os.
1944 * @param __os An output stream.
1945 * @param __x A %normal_distribution random number distribution.
1947 * @returns The output stream with the state of @p __x inserted or in
1950 template<typename _RealType1
, typename _CharT
, typename _Traits
>
1951 friend std::basic_ostream
<_CharT
, _Traits
>&
1952 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
1953 const std::normal_distribution
<_RealType1
>&);
1956 * @brief Extracts a %normal_distribution random number distribution
1957 * @p __x from the input stream @p __is.
1959 * @param __is An input stream.
1960 * @param __x A %normal_distribution random number generator engine.
1962 * @returns The input stream with @p __x extracted or in an error
1965 template<typename _RealType1
, typename _CharT
, typename _Traits
>
1966 friend std::basic_istream
<_CharT
, _Traits
>&
1967 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
1968 std::normal_distribution
<_RealType1
>&);
1971 param_type _M_param
;
1972 result_type _M_saved
;
1973 bool _M_saved_available
;
1978 * @brief A lognormal_distribution random number distribution.
1980 * The formula for the normal probability mass function is
1981 * @f$ p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
1982 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} @f$
1984 template<typename _RealType
= double>
1985 class lognormal_distribution
1988 /** The type of the range of the distribution. */
1989 typedef _RealType result_type
;
1990 /** Parameter type. */
1993 typedef lognormal_distribution
<_RealType
> distribution_type
;
1996 param_type(_RealType __m
= _RealType(0),
1997 _RealType __s
= _RealType(1))
1998 : _M_m(__m
), _M_s(__s
)
2015 lognormal_distribution(_RealType __m
= _RealType(0),
2016 _RealType __s
= _RealType(1))
2017 : _M_param(__m
, __s
)
2021 lognormal_distribution(const param_type
& __p
)
2026 * Resets the distribution state.
2037 { return _M_param
.m(); }
2041 { return _M_param
.s(); }
2044 * @brief Returns the parameter set of the distribution.
2048 { return _M_param
; }
2051 * @brief Sets the parameter set of the distribution.
2052 * @param __param The new parameter set of the distribution.
2055 param(const param_type
& __param
)
2056 { _M_param
= __param
; }
2059 * @brief Returns the greatest lower bound value of the distribution.
2063 { return result_type(0); }
2066 * @brief Returns the least upper bound value of the distribution.
2070 { return std::numeric_limits
<result_type
>::max(); }
2072 template<typename _UniformRandomNumberGenerator
>
2074 operator()(_UniformRandomNumberGenerator
& __urng
)
2075 { return this->operator()(__urng
, this->param()); }
2077 template<typename _UniformRandomNumberGenerator
>
2079 operator()(_UniformRandomNumberGenerator
& __urng
,
2080 const param_type
& __p
);
2083 param_type _M_param
;
2087 * @brief Inserts a %lognormal_distribution random number distribution
2088 * @p __x into the output stream @p __os.
2090 * @param __os An output stream.
2091 * @param __x A %lognormal_distribution random number distribution.
2093 * @returns The output stream with the state of @p __x inserted or in
2096 template<typename _RealType
, typename _CharT
, typename _Traits
>
2097 std::basic_ostream
<_CharT
, _Traits
>&
2098 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2099 const std::lognormal_distribution
<_RealType
>&);
2102 * @brief Extracts a %lognormal_distribution random number distribution
2103 * @p __x from the input stream @p __is.
2105 * @param __is An input stream.
2106 * @param __x A %lognormal_distribution random number
2109 * @returns The input stream with @p __x extracted or in an error state.
2111 template<typename _RealType
, typename _CharT
, typename _Traits
>
2112 std::basic_istream
<_CharT
, _Traits
>&
2113 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2114 std::lognormal_distribution
<_RealType
>&);
2118 * @brief A chi_squared_distribution random number distribution.
2120 * The formula for the normal probability mass function is
2121 * @f$ p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}} @f$
2123 template<typename _RealType
= double>
2124 class chi_squared_distribution
2127 /** The type of the range of the distribution. */
2128 typedef _RealType result_type
;
2129 /** Parameter type. */
2132 typedef chi_squared_distribution
<_RealType
> distribution_type
;
2135 param_type(_RealType __n
= _RealType(1))
2148 chi_squared_distribution(_RealType __n
= _RealType(1))
2153 chi_squared_distribution(const param_type
& __p
)
2158 * @brief Resets the distribution state.
2169 { return _M_param
.n(); }
2172 * @brief Returns the parameter set of the distribution.
2176 { return _M_param
; }
2179 * @brief Sets the parameter set of the distribution.
2180 * @param __param The new parameter set of the distribution.
2183 param(const param_type
& __param
)
2184 { _M_param
= __param
; }
2187 * @brief Returns the greatest lower bound value of the distribution.
2191 { return result_type(0); }
2194 * @brief Returns the least upper bound value of the distribution.
2198 { return std::numeric_limits
<result_type
>::max(); }
2200 template<typename _UniformRandomNumberGenerator
>
2202 operator()(_UniformRandomNumberGenerator
& __urng
)
2203 { return this->operator()(__urng
, this->param()); }
2205 template<typename _UniformRandomNumberGenerator
>
2207 operator()(_UniformRandomNumberGenerator
& __urng
,
2208 const param_type
& __p
);
2211 param_type _M_param
;
2215 * @brief Inserts a %chi_squared_distribution random number distribution
2216 * @p __x into the output stream @p __os.
2218 * @param __os An output stream.
2219 * @param __x A %chi_squared_distribution random number distribution.
2221 * @returns The output stream with the state of @p __x inserted or in
2224 template<typename _RealType
, typename _CharT
, typename _Traits
>
2225 std::basic_ostream
<_CharT
, _Traits
>&
2226 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2227 const std::chi_squared_distribution
<_RealType
>&);
2230 * @brief Extracts a %chi_squared_distribution random number distribution
2231 * @p __x from the input stream @p __is.
2233 * @param __is An input stream.
2234 * @param __x A %chi_squared_distribution random number
2237 * @returns The input stream with @p __x extracted or in an error state.
2239 template<typename _RealType
, typename _CharT
, typename _Traits
>
2240 std::basic_istream
<_CharT
, _Traits
>&
2241 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2242 std::chi_squared_distribution
<_RealType
>&);
2246 * @brief A cauchy_distribution random number distribution.
2248 * The formula for the normal probability mass function is
2249 * @f$ p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1} @f$
2251 template<typename _RealType
= double>
2252 class cauchy_distribution
2255 /** The type of the range of the distribution. */
2256 typedef _RealType result_type
;
2257 /** Parameter type. */
2260 typedef cauchy_distribution
<_RealType
> distribution_type
;
2263 param_type(_RealType __a
= _RealType(0),
2264 _RealType __b
= _RealType(1))
2265 : _M_a(__a
), _M_b(__b
)
2282 cauchy_distribution(_RealType __a
= _RealType(0),
2283 _RealType __b
= _RealType(1))
2284 : _M_param(__a
, __b
)
2288 cauchy_distribution(const param_type
& __p
)
2293 * @brief Resets the distribution state.
2304 { return _M_param
.a(); }
2308 { return _M_param
.b(); }
2311 * @brief Returns the parameter set of the distribution.
2315 { return _M_param
; }
2318 * @brief Sets the parameter set of the distribution.
2319 * @param __param The new parameter set of the distribution.
2322 param(const param_type
& __param
)
2323 { _M_param
= __param
; }
2326 * @brief Returns the greatest lower bound value of the distribution.
2330 { return std::numeric_limits
<result_type
>::min(); }
2333 * @brief Returns the least upper bound value of the distribution.
2337 { return std::numeric_limits
<result_type
>::max(); }
2339 template<typename _UniformRandomNumberGenerator
>
2341 operator()(_UniformRandomNumberGenerator
& __urng
)
2342 { return this->operator()(__urng
, this->param()); }
2344 template<typename _UniformRandomNumberGenerator
>
2346 operator()(_UniformRandomNumberGenerator
& __urng
,
2347 const param_type
& __p
);
2350 param_type _M_param
;
2354 * @brief Inserts a %cauchy_distribution random number distribution
2355 * @p __x into the output stream @p __os.
2357 * @param __os An output stream.
2358 * @param __x A %cauchy_distribution random number distribution.
2360 * @returns The output stream with the state of @p __x inserted or in
2363 template<typename _RealType
, typename _CharT
, typename _Traits
>
2364 std::basic_ostream
<_CharT
, _Traits
>&
2365 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2366 const std::cauchy_distribution
<_RealType
>&);
2369 * @brief Extracts a %cauchy_distribution random number distribution
2370 * @p __x from the input stream @p __is.
2372 * @param __is An input stream.
2373 * @param __x A %cauchy_distribution random number
2376 * @returns The input stream with @p __x extracted or in an error state.
2378 template<typename _RealType
, typename _CharT
, typename _Traits
>
2379 std::basic_istream
<_CharT
, _Traits
>&
2380 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2381 std::cauchy_distribution
<_RealType
>&);
2385 * @brief A fisher_f_distribution random number distribution.
2387 * The formula for the normal probability mass function is
2388 * @f$ p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2389 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2390 * (1 + \frac{mx}{n})^{-(m+n)/2} @f$
2392 template<typename _RealType
= double>
2393 class fisher_f_distribution
2396 /** The type of the range of the distribution. */
2397 typedef _RealType result_type
;
2398 /** Parameter type. */
2401 typedef fisher_f_distribution
<_RealType
> distribution_type
;
2404 param_type(_RealType __m
= _RealType(1),
2405 _RealType __n
= _RealType(1))
2406 : _M_m(__m
), _M_n(__n
)
2423 fisher_f_distribution(_RealType __m
= _RealType(1),
2424 _RealType __n
= _RealType(1))
2425 : _M_param(__m
, __n
)
2429 fisher_f_distribution(const param_type
& __p
)
2434 * @brief Resets the distribution state.
2445 { return _M_param
.m(); }
2449 { return _M_param
.n(); }
2452 * @brief Returns the parameter set of the distribution.
2456 { return _M_param
; }
2459 * @brief Sets the parameter set of the distribution.
2460 * @param __param The new parameter set of the distribution.
2463 param(const param_type
& __param
)
2464 { _M_param
= __param
; }
2467 * @brief Returns the greatest lower bound value of the distribution.
2471 { return result_type(0); }
2474 * @brief Returns the least upper bound value of the distribution.
2478 { return std::numeric_limits
<result_type
>::max(); }
2480 template<typename _UniformRandomNumberGenerator
>
2482 operator()(_UniformRandomNumberGenerator
& __urng
)
2483 { return this->operator()(__urng
, this->param()); }
2485 template<typename _UniformRandomNumberGenerator
>
2487 operator()(_UniformRandomNumberGenerator
& __urng
,
2488 const param_type
& __p
);
2491 param_type _M_param
;
2495 * @brief Inserts a %fisher_f_distribution random number distribution
2496 * @p __x into the output stream @p __os.
2498 * @param __os An output stream.
2499 * @param __x A %fisher_f_distribution random number distribution.
2501 * @returns The output stream with the state of @p __x inserted or in
2504 template<typename _RealType
, typename _CharT
, typename _Traits
>
2505 std::basic_ostream
<_CharT
, _Traits
>&
2506 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2507 const std::fisher_f_distribution
<_RealType
>&);
2510 * @brief Extracts a %fisher_f_distribution random number distribution
2511 * @p __x from the input stream @p __is.
2513 * @param __is An input stream.
2514 * @param __x A %fisher_f_distribution random number
2517 * @returns The input stream with @p __x extracted or in an error state.
2519 template<typename _RealType
, typename _CharT
, typename _Traits
>
2520 std::basic_istream
<_CharT
, _Traits
>&
2521 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2522 std::fisher_f_distribution
<_RealType
>&);
2526 * @brief A student_t_distribution random number distribution.
2528 * The formula for the normal probability mass function is
2529 * @f$ p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
2530 * (1 + \frac{x^2}{n}) ^{-(n+1)/2} @f$
2532 template<typename _RealType
= double>
2533 class student_t_distribution
2536 /** The type of the range of the distribution. */
2537 typedef _RealType result_type
;
2538 /** Parameter type. */
2541 typedef student_t_distribution
<_RealType
> distribution_type
;
2544 param_type(_RealType __n
= _RealType(1))
2557 student_t_distribution(_RealType __n
= _RealType(1))
2562 student_t_distribution(const param_type
& __p
)
2567 * @brief Resets the distribution state.
2578 { return _M_param
.n(); }
2581 * @brief Returns the parameter set of the distribution.
2585 { return _M_param
; }
2588 * @brief Sets the parameter set of the distribution.
2589 * @param __param The new parameter set of the distribution.
2592 param(const param_type
& __param
)
2593 { _M_param
= __param
; }
2596 * @brief Returns the greatest lower bound value of the distribution.
2600 { return std::numeric_limits
<result_type
>::min(); }
2603 * @brief Returns the least upper bound value of the distribution.
2607 { return std::numeric_limits
<result_type
>::max(); }
2609 template<typename _UniformRandomNumberGenerator
>
2611 operator()(_UniformRandomNumberGenerator
& __urng
)
2612 { return this->operator()(__urng
, this->param()); }
2614 template<typename _UniformRandomNumberGenerator
>
2616 operator()(_UniformRandomNumberGenerator
& __urng
,
2617 const param_type
& __p
);
2620 template<typename _UniformRandomNumberGenerator
>
2622 _M_gaussian(_UniformRandomNumberGenerator
& __urng
,
2623 const result_type __sigma
);
2625 param_type _M_param
;
2629 * @brief Inserts a %student_t_distribution random number distribution
2630 * @p __x into the output stream @p __os.
2632 * @param __os An output stream.
2633 * @param __x A %student_t_distribution random number distribution.
2635 * @returns The output stream with the state of @p __x inserted or in
2638 template<typename _RealType
, typename _CharT
, typename _Traits
>
2639 std::basic_ostream
<_CharT
, _Traits
>&
2640 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2641 const std::student_t_distribution
<_RealType
>&);
2644 * @brief Extracts a %student_t_distribution random number distribution
2645 * @p __x from the input stream @p __is.
2647 * @param __is An input stream.
2648 * @param __x A %student_t_distribution random number
2651 * @returns The input stream with @p __x extracted or in an error state.
2653 template<typename _RealType
, typename _CharT
, typename _Traits
>
2654 std::basic_istream
<_CharT
, _Traits
>&
2655 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2656 std::student_t_distribution
<_RealType
>&);
2658 /* @} */ // group std_random_distributions_normal
2661 * @addtogroup std_random_distributions_bernoulli Bernoulli Distributions
2662 * @ingroup std_random_distributions
2667 * @brief A Bernoulli random number distribution.
2669 * Generates a sequence of true and false values with likelihood @f$ p @f$
2670 * that true will come up and @f$ (1 - p) @f$ that false will appear.
2672 class bernoulli_distribution
2675 /** The type of the range of the distribution. */
2676 typedef bool result_type
;
2677 /** Parameter type. */
2680 typedef bernoulli_distribution distribution_type
;
2683 param_type(double __p
= 0.5)
2686 _GLIBCXX_DEBUG_ASSERT((_M_p
>= 0.0) && (_M_p
<= 1.0));
2699 * @brief Constructs a Bernoulli distribution with likelihood @p p.
2701 * @param __p [IN] The likelihood of a true result being returned.
2702 * Must be in the interval @f$ [0, 1] @f$.
2705 bernoulli_distribution(double __p
= 0.5)
2710 bernoulli_distribution(const param_type
& __p
)
2715 * @brief Resets the distribution state.
2717 * Does nothing for a Bernoulli distribution.
2723 * @brief Returns the @p p parameter of the distribution.
2727 { return _M_param
.p(); }
2730 * @brief Returns the parameter set of the distribution.
2734 { return _M_param
; }
2737 * @brief Sets the parameter set of the distribution.
2738 * @param __param The new parameter set of the distribution.
2741 param(const param_type
& __param
)
2742 { _M_param
= __param
; }
2745 * @brief Returns the greatest lower bound value of the distribution.
2749 { return std::numeric_limits
<result_type
>::min(); }
2752 * @brief Returns the least upper bound value of the distribution.
2756 { return std::numeric_limits
<result_type
>::max(); }
2759 * @brief Returns the next value in the Bernoullian sequence.
2761 template<typename _UniformRandomNumberGenerator
>
2763 operator()(_UniformRandomNumberGenerator
& __urng
)
2765 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
2767 if ((__aurng() - __aurng
.min())
2768 < this->p() * (__aurng
.max() - __aurng
.min()))
2773 template<typename _UniformRandomNumberGenerator
>
2775 operator()(_UniformRandomNumberGenerator
& __urng
,
2776 const param_type
& __p
)
2778 __detail::_Adaptor
<_UniformRandomNumberGenerator
, double>
2780 if ((__aurng() - __aurng
.min())
2781 < __p
.p() * (__aurng
.max() - __aurng
.min()))
2787 param_type _M_param
;
2791 * @brief Inserts a %bernoulli_distribution random number distribution
2792 * @p __x into the output stream @p __os.
2794 * @param __os An output stream.
2795 * @param __x A %bernoulli_distribution random number distribution.
2797 * @returns The output stream with the state of @p __x inserted or in
2800 template<typename _CharT
, typename _Traits
>
2801 std::basic_ostream
<_CharT
, _Traits
>&
2802 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2803 const std::bernoulli_distribution
&);
2806 * @brief Extracts a %bernoulli_distribution random number distribution
2807 * @p __x from the input stream @p __is.
2809 * @param __is An input stream.
2810 * @param __x A %bernoulli_distribution random number generator engine.
2812 * @returns The input stream with @p __x extracted or in an error state.
2814 template<typename _CharT
, typename _Traits
>
2815 std::basic_istream
<_CharT
, _Traits
>&
2816 operator>>(std::basic_istream
<_CharT
, _Traits
>& __is
,
2817 std::bernoulli_distribution
& __x
)
2821 __x
.param(bernoulli_distribution::param_type(__p
));
2827 * @brief A discrete binomial random number distribution.
2829 * The formula for the binomial probability density function is
2830 * @f$ p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
2831 * and @f$ p @f$ are the parameters of the distribution.
2833 template<typename _IntType
= int>
2834 class binomial_distribution
2836 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
2839 /** The type of the range of the distribution. */
2840 typedef _IntType result_type
;
2841 /** Parameter type. */
2844 typedef binomial_distribution
<_IntType
> distribution_type
;
2845 friend class binomial_distribution
<_IntType
>;
2848 param_type(_IntType __t
= _IntType(1), double __p
= 0.5)
2849 : _M_t(__t
), _M_p(__p
)
2851 _GLIBCXX_DEBUG_ASSERT((_M_t
>= _IntType(0))
2873 #if _GLIBCXX_USE_C99_MATH_TR1
2874 double _M_d1
, _M_d2
, _M_s1
, _M_s2
, _M_c
,
2875 _M_a1
, _M_a123
, _M_s
, _M_lf
, _M_lp1p
;
2880 // constructors and member function
2882 binomial_distribution(_IntType __t
= _IntType(1),
2884 : _M_param(__t
, __p
), _M_nd()
2888 binomial_distribution(const param_type
& __p
)
2889 : _M_param(__p
), _M_nd()
2893 * @brief Resets the distribution state.
2900 * @brief Returns the distribution @p t parameter.
2904 { return _M_param
.t(); }
2907 * @brief Returns the distribution @p p parameter.
2911 { return _M_param
.p(); }
2914 * @brief Returns the parameter set of the distribution.
2918 { return _M_param
; }
2921 * @brief Sets the parameter set of the distribution.
2922 * @param __param The new parameter set of the distribution.
2925 param(const param_type
& __param
)
2926 { _M_param
= __param
; }
2929 * @brief Returns the greatest lower bound value of the distribution.
2936 * @brief Returns the least upper bound value of the distribution.
2940 { return _M_param
.t(); }
2942 template<typename _UniformRandomNumberGenerator
>
2944 operator()(_UniformRandomNumberGenerator
& __urng
)
2945 { return this->operator()(__urng
, this->param()); }
2947 template<typename _UniformRandomNumberGenerator
>
2949 operator()(_UniformRandomNumberGenerator
& __urng
,
2950 const param_type
& __p
);
2953 * @brief Inserts a %binomial_distribution random number distribution
2954 * @p __x into the output stream @p __os.
2956 * @param __os An output stream.
2957 * @param __x A %binomial_distribution random number distribution.
2959 * @returns The output stream with the state of @p __x inserted or in
2962 template<typename _IntType1
,
2963 typename _CharT
, typename _Traits
>
2964 friend std::basic_ostream
<_CharT
, _Traits
>&
2965 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
2966 const std::binomial_distribution
<_IntType1
>&);
2969 * @brief Extracts a %binomial_distribution random number distribution
2970 * @p __x from the input stream @p __is.
2972 * @param __is An input stream.
2973 * @param __x A %binomial_distribution random number generator engine.
2975 * @returns The input stream with @p __x extracted or in an error
2978 template<typename _IntType1
,
2979 typename _CharT
, typename _Traits
>
2980 friend std::basic_istream
<_CharT
, _Traits
>&
2981 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
2982 std::binomial_distribution
<_IntType1
>&);
2985 template<typename _UniformRandomNumberGenerator
>
2987 _M_waiting(_UniformRandomNumberGenerator
& __urng
, _IntType __t
);
2989 param_type _M_param
;
2991 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
2992 normal_distribution
<double> _M_nd
;
2997 * @brief A discrete geometric random number distribution.
2999 * The formula for the geometric probability density function is
3000 * @f$ p(i|p) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
3003 template<typename _IntType
= int>
3004 class geometric_distribution
3006 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
3009 /** The type of the range of the distribution. */
3010 typedef _IntType result_type
;
3011 /** Parameter type. */
3014 typedef geometric_distribution
<_IntType
> distribution_type
;
3015 friend class geometric_distribution
<_IntType
>;
3018 param_type(double __p
= 0.5)
3021 _GLIBCXX_DEBUG_ASSERT((_M_p
>= 0.0)
3033 { _M_log_p
= std::log(_M_p
); }
3040 // constructors and member function
3042 geometric_distribution(double __p
= 0.5)
3047 geometric_distribution(const param_type
& __p
)
3052 * @brief Resets the distribution state.
3054 * Does nothing for the geometric distribution.
3060 * @brief Returns the distribution parameter @p p.
3064 { return _M_param
.p(); }
3067 * @brief Returns the parameter set of the distribution.
3071 { return _M_param
; }
3074 * @brief Sets the parameter set of the distribution.
3075 * @param __param The new parameter set of the distribution.
3078 param(const param_type
& __param
)
3079 { _M_param
= __param
; }
3082 * @brief Returns the greatest lower bound value of the distribution.
3089 * @brief Returns the least upper bound value of the distribution.
3093 { return std::numeric_limits
<result_type
>::max(); }
3095 template<typename _UniformRandomNumberGenerator
>
3097 operator()(_UniformRandomNumberGenerator
& __urng
)
3098 { return this->operator()(__urng
, this->param()); }
3100 template<typename _UniformRandomNumberGenerator
>
3102 operator()(_UniformRandomNumberGenerator
& __urng
,
3103 const param_type
& __p
);
3106 param_type _M_param
;
3110 * @brief Inserts a %geometric_distribution random number distribution
3111 * @p __x into the output stream @p __os.
3113 * @param __os An output stream.
3114 * @param __x A %geometric_distribution random number distribution.
3116 * @returns The output stream with the state of @p __x inserted or in
3119 template<typename _IntType
,
3120 typename _CharT
, typename _Traits
>
3121 std::basic_ostream
<_CharT
, _Traits
>&
3122 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3123 const std::geometric_distribution
<_IntType
>&);
3126 * @brief Extracts a %geometric_distribution random number distribution
3127 * @p __x from the input stream @p __is.
3129 * @param __is An input stream.
3130 * @param __x A %geometric_distribution random number generator engine.
3132 * @returns The input stream with @p __x extracted or in an error state.
3134 template<typename _IntType
,
3135 typename _CharT
, typename _Traits
>
3136 std::basic_istream
<_CharT
, _Traits
>&
3137 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3138 std::geometric_distribution
<_IntType
>&);
3142 * @brief A negative_binomial_distribution random number distribution.
3144 * The formula for the negative binomial probability mass function is
3145 * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
3146 * and @f$ p @f$ are the parameters of the distribution.
3148 template<typename _IntType
= int>
3149 class negative_binomial_distribution
3151 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
3154 /** The type of the range of the distribution. */
3155 typedef _IntType result_type
;
3156 /** Parameter type. */
3159 typedef negative_binomial_distribution
<_IntType
> distribution_type
;
3162 param_type(_IntType __k
= 1, double __p
= 0.5)
3163 : _M_k(__k
), _M_p(__p
)
3180 negative_binomial_distribution(_IntType __k
= 1, double __p
= 0.5)
3181 : _M_param(__k
, __p
)
3185 negative_binomial_distribution(const param_type
& __p
)
3190 * @brief Resets the distribution state.
3197 * @brief Return the @f$ k @f$ parameter of the distribution.
3201 { return _M_param
.k(); }
3204 * @brief Return the @f$ p @f$ parameter of the distribution.
3208 { return _M_param
.p(); }
3211 * @brief Returns the parameter set of the distribution.
3215 { return _M_param
; }
3218 * @brief Sets the parameter set of the distribution.
3219 * @param __param The new parameter set of the distribution.
3222 param(const param_type
& __param
)
3223 { _M_param
= __param
; }
3226 * @brief Returns the greatest lower bound value of the distribution.
3230 { return result_type(0); }
3233 * @brief Returns the least upper bound value of the distribution.
3237 { return std::numeric_limits
<result_type
>::max(); }
3239 template<typename _UniformRandomNumberGenerator
>
3241 operator()(_UniformRandomNumberGenerator
& __urng
)
3242 { return this->operator()(__urng
, this->param()); }
3244 template<typename _UniformRandomNumberGenerator
>
3246 operator()(_UniformRandomNumberGenerator
& __urng
,
3247 const param_type
& __p
);
3250 param_type _M_param
;
3254 * @brief Inserts a %negative_binomial_distribution random
3255 * number distribution @p __x into the output stream @p __os.
3257 * @param __os An output stream.
3258 * @param __x A %negative_binomial_distribution random number
3261 * @returns The output stream with the state of @p __x inserted or in
3264 template<typename _IntType
, typename _CharT
, typename _Traits
>
3265 std::basic_ostream
<_CharT
, _Traits
>&
3266 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3267 const std::negative_binomial_distribution
<_IntType
>&);
3270 * @brief Extracts a %negative_binomial_distribution random number
3271 * distribution @p __x from the input stream @p __is.
3273 * @param __is An input stream.
3274 * @param __x A %negative_binomial_distribution random number
3277 * @returns The input stream with @p __x extracted or in an error state.
3279 template<typename _IntType
, typename _CharT
, typename _Traits
>
3280 std::basic_istream
<_CharT
, _Traits
>&
3281 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3282 std::negative_binomial_distribution
<_IntType
>&);
3284 /* @} */ // group std_random_distributions_bernoulli
3287 * @addtogroup std_random_distributions_poisson Poisson Distributions
3288 * @ingroup std_random_distributions
3293 * @brief A discrete Poisson random number distribution.
3295 * The formula for the Poisson probability density function is
3296 * @f$ p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu} @f$ where @f$ \mu @f$ is the
3297 * parameter of the distribution.
3299 template<typename _IntType
= int>
3300 class poisson_distribution
3302 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
3305 /** The type of the range of the distribution. */
3306 typedef _IntType result_type
;
3307 /** Parameter type. */
3310 typedef poisson_distribution
<_IntType
> distribution_type
;
3311 friend class poisson_distribution
<_IntType
>;
3314 param_type(double __mean
= 1.0)
3317 _GLIBCXX_DEBUG_ASSERT(_M_mean
> 0.0);
3326 // Hosts either log(mean) or the threshold of the simple method.
3333 #if _GLIBCXX_USE_C99_MATH_TR1
3334 double _M_lfm
, _M_sm
, _M_d
, _M_scx
, _M_1cx
, _M_c2b
, _M_cb
;
3338 // constructors and member function
3340 poisson_distribution(double __mean
= 1.0)
3341 : _M_param(__mean
), _M_nd()
3345 poisson_distribution(const param_type
& __p
)
3346 : _M_param(__p
), _M_nd()
3350 * @brief Resets the distribution state.
3357 * @brief Returns the distribution parameter @p mean.
3361 { return _M_param
.mean(); }
3364 * @brief Returns the parameter set of the distribution.
3368 { return _M_param
; }
3371 * @brief Sets the parameter set of the distribution.
3372 * @param __param The new parameter set of the distribution.
3375 param(const param_type
& __param
)
3376 { _M_param
= __param
; }
3379 * @brief Returns the greatest lower bound value of the distribution.
3386 * @brief Returns the least upper bound value of the distribution.
3390 { return std::numeric_limits
<result_type
>::max(); }
3392 template<typename _UniformRandomNumberGenerator
>
3394 operator()(_UniformRandomNumberGenerator
& __urng
)
3395 { return this->operator()(__urng
, this->param()); }
3397 template<typename _UniformRandomNumberGenerator
>
3399 operator()(_UniformRandomNumberGenerator
& __urng
,
3400 const param_type
& __p
);
3403 * @brief Inserts a %poisson_distribution random number distribution
3404 * @p __x into the output stream @p __os.
3406 * @param __os An output stream.
3407 * @param __x A %poisson_distribution random number distribution.
3409 * @returns The output stream with the state of @p __x inserted or in
3412 template<typename _IntType1
, typename _CharT
, typename _Traits
>
3413 friend std::basic_ostream
<_CharT
, _Traits
>&
3414 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3415 const std::poisson_distribution
<_IntType1
>&);
3418 * @brief Extracts a %poisson_distribution random number distribution
3419 * @p __x from the input stream @p __is.
3421 * @param __is An input stream.
3422 * @param __x A %poisson_distribution random number generator engine.
3424 * @returns The input stream with @p __x extracted or in an error
3427 template<typename _IntType1
, typename _CharT
, typename _Traits
>
3428 friend std::basic_istream
<_CharT
, _Traits
>&
3429 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3430 std::poisson_distribution
<_IntType1
>&);
3433 param_type _M_param
;
3435 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3436 normal_distribution
<double> _M_nd
;
3440 * @brief An exponential continuous distribution for random numbers.
3442 * The formula for the exponential probability density function is
3443 * @f$ p(x|\lambda) = \lambda e^{-\lambda x} @f$.
3445 * <table border=1 cellpadding=10 cellspacing=0>
3446 * <caption align=top>Distribution Statistics</caption>
3447 * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3448 * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
3449 * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
3450 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
3451 * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3454 template<typename _RealType
= double>
3455 class exponential_distribution
3458 /** The type of the range of the distribution. */
3459 typedef _RealType result_type
;
3460 /** Parameter type. */
3463 typedef exponential_distribution
<_RealType
> distribution_type
;
3466 param_type(_RealType __lambda
= _RealType(1))
3467 : _M_lambda(__lambda
)
3469 _GLIBCXX_DEBUG_ASSERT(_M_lambda
> _RealType(0));
3474 { return _M_lambda
; }
3477 _RealType _M_lambda
;
3482 * @brief Constructs an exponential distribution with inverse scale
3483 * parameter @f$ \lambda @f$.
3486 exponential_distribution(const result_type
& __lambda
= result_type(1))
3487 : _M_param(__lambda
)
3491 exponential_distribution(const param_type
& __p
)
3496 * @brief Resets the distribution state.
3498 * Has no effect on exponential distributions.
3504 * @brief Returns the inverse scale parameter of the distribution.
3508 { return _M_param
.lambda(); }
3511 * @brief Returns the parameter set of the distribution.
3515 { return _M_param
; }
3518 * @brief Sets the parameter set of the distribution.
3519 * @param __param The new parameter set of the distribution.
3522 param(const param_type
& __param
)
3523 { _M_param
= __param
; }
3526 * @brief Returns the greatest lower bound value of the distribution.
3530 { return result_type(0); }
3533 * @brief Returns the least upper bound value of the distribution.
3537 { return std::numeric_limits
<result_type
>::max(); }
3539 template<typename _UniformRandomNumberGenerator
>
3541 operator()(_UniformRandomNumberGenerator
& __urng
)
3543 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
3545 return -std::log(__aurng()) / this->lambda();
3548 template<typename _UniformRandomNumberGenerator
>
3550 operator()(_UniformRandomNumberGenerator
& __urng
,
3551 const param_type
& __p
)
3553 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
3555 return -std::log(__aurng()) / __p
.lambda();
3559 param_type _M_param
;
3563 * @brief Inserts a %exponential_distribution random number distribution
3564 * @p __x into the output stream @p __os.
3566 * @param __os An output stream.
3567 * @param __x A %exponential_distribution random number distribution.
3569 * @returns The output stream with the state of @p __x inserted or in
3572 template<typename _RealType
, typename _CharT
, typename _Traits
>
3573 std::basic_ostream
<_CharT
, _Traits
>&
3574 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3575 const std::exponential_distribution
<_RealType
>&);
3578 * @brief Extracts a %exponential_distribution random number distribution
3579 * @p __x from the input stream @p __is.
3581 * @param __is An input stream.
3582 * @param __x A %exponential_distribution random number
3585 * @returns The input stream with @p __x extracted or in an error state.
3587 template<typename _RealType
, typename _CharT
, typename _Traits
>
3588 std::basic_istream
<_CharT
, _Traits
>&
3589 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3590 std::exponential_distribution
<_RealType
>&);
3594 * @brief A gamma continuous distribution for random numbers.
3596 * The formula for the gamma probability density function is
3597 * @f$ p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
3598 * (x/\beta)^{\alpha - 1} e^{-x/\beta} @f$.
3600 template<typename _RealType
= double>
3601 class gamma_distribution
3604 /** The type of the range of the distribution. */
3605 typedef _RealType result_type
;
3606 /** Parameter type. */
3609 typedef gamma_distribution
<_RealType
> distribution_type
;
3610 friend class gamma_distribution
<_RealType
>;
3613 param_type(_RealType __alpha_val
= _RealType(1),
3614 _RealType __beta_val
= _RealType(1))
3615 : _M_alpha(__alpha_val
), _M_beta(__beta_val
)
3617 _GLIBCXX_DEBUG_ASSERT(_M_alpha
> _RealType(0));
3623 { return _M_alpha
; }
3636 // Hosts either lambda of GB or d of modified Vaduva's.
3642 * @brief Constructs a gamma distribution with parameters
3643 * @f$ \alpha @f$ and @f$ \beta @f$.
3646 gamma_distribution(_RealType __alpha_val
= _RealType(1),
3647 _RealType __beta_val
= _RealType(1))
3648 : _M_param(__alpha_val
, __beta_val
)
3652 gamma_distribution(const param_type
& __p
)
3657 * @brief Resets the distribution state.
3659 * Does nothing for the gamma distribution.
3665 * @brief Returns the @f$ \alpha @f$ of the distribution.
3669 { return _M_param
.alpha(); }
3672 * @brief Returns the @f$ \beta @f$ of the distribution.
3676 { return _M_param
.beta(); }
3679 * @brief Returns the parameter set of the distribution.
3683 { return _M_param
; }
3686 * @brief Sets the parameter set of the distribution.
3687 * @param __param The new parameter set of the distribution.
3690 param(const param_type
& __param
)
3691 { _M_param
= __param
; }
3694 * @brief Returns the greatest lower bound value of the distribution.
3698 { return result_type(0); }
3701 * @brief Returns the least upper bound value of the distribution.
3705 { return std::numeric_limits
<result_type
>::max(); }
3707 template<typename _UniformRandomNumberGenerator
>
3709 operator()(_UniformRandomNumberGenerator
& __urng
)
3710 { return this->operator()(__urng
, this->param()); }
3712 template<typename _UniformRandomNumberGenerator
>
3714 operator()(_UniformRandomNumberGenerator
& __urng
,
3715 const param_type
& __p
);
3718 param_type _M_param
;
3722 * @brief Inserts a %gamma_distribution random number distribution
3723 * @p __x into the output stream @p __os.
3725 * @param __os An output stream.
3726 * @param __x A %gamma_distribution random number distribution.
3728 * @returns The output stream with the state of @p __x inserted or in
3731 template<typename _RealType
, typename _CharT
, typename _Traits
>
3732 std::basic_ostream
<_CharT
, _Traits
>&
3733 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3734 const std::gamma_distribution
<_RealType
>&);
3737 * @brief Extracts a %gamma_distribution random number distribution
3738 * @p __x from the input stream @p __is.
3740 * @param __is An input stream.
3741 * @param __x A %gamma_distribution random number generator engine.
3743 * @returns The input stream with @p __x extracted or in an error state.
3745 template<typename _RealType
, typename _CharT
, typename _Traits
>
3746 std::basic_istream
<_CharT
, _Traits
>&
3747 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3748 std::gamma_distribution
<_RealType
>&);
3752 * @brief A weibull_distribution random number distribution.
3754 * The formula for the normal probability density function is
3755 * @f$ p(x|\alpha,\beta) = \frac{a}{b} (frac{x}{b})^{a-1}
3756 * \exp{(-(frac{x}{b})^a)} @f$.
3758 template<typename _RealType
= double>
3759 class weibull_distribution
3762 /** The type of the range of the distribution. */
3763 typedef _RealType result_type
;
3764 /** Parameter type. */
3767 typedef weibull_distribution
<_RealType
> distribution_type
;
3770 param_type(_RealType __a
= _RealType(1),
3771 _RealType __b
= _RealType(1))
3772 : _M_a(__a
), _M_b(__b
)
3789 weibull_distribution(_RealType __a
= _RealType(1),
3790 _RealType __b
= _RealType(1))
3791 : _M_param(__a
, __b
)
3795 weibull_distribution(const param_type
& __p
)
3800 * @brief Resets the distribution state.
3807 * @brief Return the @f$ a @f$ parameter of the distribution.
3811 { return _M_param
.a(); }
3814 * @brief Return the @f$ b @f$ parameter of the distribution.
3818 { return _M_param
.b(); }
3821 * @brief Returns the parameter set of the distribution.
3825 { return _M_param
; }
3828 * @brief Sets the parameter set of the distribution.
3829 * @param __param The new parameter set of the distribution.
3832 param(const param_type
& __param
)
3833 { _M_param
= __param
; }
3836 * @brief Returns the greatest lower bound value of the distribution.
3840 { return result_type(0); }
3843 * @brief Returns the least upper bound value of the distribution.
3847 { return std::numeric_limits
<result_type
>::max(); }
3849 template<typename _UniformRandomNumberGenerator
>
3851 operator()(_UniformRandomNumberGenerator
& __urng
)
3852 { return this->operator()(__urng
, this->param()); }
3854 template<typename _UniformRandomNumberGenerator
>
3856 operator()(_UniformRandomNumberGenerator
& __urng
,
3857 const param_type
& __p
)
3859 __detail::_Adaptor
<_UniformRandomNumberGenerator
, result_type
>
3861 return __p
.b() * std::pow(-std::log(__aurng()),
3862 result_type(1) / __p
.a());
3866 param_type _M_param
;
3870 * @brief Inserts a %weibull_distribution random number distribution
3871 * @p __x into the output stream @p __os.
3873 * @param __os An output stream.
3874 * @param __x A %weibull_distribution random number distribution.
3876 * @returns The output stream with the state of @p __x inserted or in
3879 template<typename _RealType
, typename _CharT
, typename _Traits
>
3880 std::basic_ostream
<_CharT
, _Traits
>&
3881 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
3882 const std::weibull_distribution
<_RealType
>&);
3885 * @brief Extracts a %weibull_distribution random number distribution
3886 * @p __x from the input stream @p __is.
3888 * @param __is An input stream.
3889 * @param __x A %weibull_distribution random number
3892 * @returns The input stream with @p __x extracted or in an error state.
3894 template<typename _RealType
, typename _CharT
, typename _Traits
>
3895 std::basic_istream
<_CharT
, _Traits
>&
3896 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
3897 std::weibull_distribution
<_RealType
>&);
3901 * @brief A extreme_value_distribution random number distribution.
3903 * The formula for the normal probability mass function is
3904 * @f$ p(x|a,b) = \frac{1}{b}
3905 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) @f$
3907 template<typename _RealType
= double>
3908 class extreme_value_distribution
3911 /** The type of the range of the distribution. */
3912 typedef _RealType result_type
;
3913 /** Parameter type. */
3916 typedef extreme_value_distribution
<_RealType
> distribution_type
;
3919 param_type(_RealType __a
= _RealType(0),
3920 _RealType __b
= _RealType(1))
3921 : _M_a(__a
), _M_b(__b
)
3938 extreme_value_distribution(_RealType __a
= _RealType(0),
3939 _RealType __b
= _RealType(1))
3940 : _M_param(__a
, __b
)
3944 extreme_value_distribution(const param_type
& __p
)
3949 * @brief Resets the distribution state.
3956 * @brief Return the @f$ a @f$ parameter of the distribution.
3960 { return _M_param
.a(); }
3963 * @brief Return the @f$ b @f$ parameter of the distribution.
3967 { return _M_param
.b(); }
3970 * @brief Returns the parameter set of the distribution.
3974 { return _M_param
; }
3977 * @brief Sets the parameter set of the distribution.
3978 * @param __param The new parameter set of the distribution.
3981 param(const param_type
& __param
)
3982 { _M_param
= __param
; }
3985 * @brief Returns the greatest lower bound value of the distribution.
3989 { return std::numeric_limits
<result_type
>::min(); }
3992 * @brief Returns the least upper bound value of the distribution.
3996 { return std::numeric_limits
<result_type
>::max(); }
3998 template<typename _UniformRandomNumberGenerator
>
4000 operator()(_UniformRandomNumberGenerator
& __urng
)
4001 { return this->operator()(__urng
, this->param()); }
4003 template<typename _UniformRandomNumberGenerator
>
4005 operator()(_UniformRandomNumberGenerator
& __urng
,
4006 const param_type
& __p
);
4009 param_type _M_param
;
4013 * @brief Inserts a %extreme_value_distribution random number distribution
4014 * @p __x into the output stream @p __os.
4016 * @param __os An output stream.
4017 * @param __x A %extreme_value_distribution random number distribution.
4019 * @returns The output stream with the state of @p __x inserted or in
4022 template<typename _RealType
, typename _CharT
, typename _Traits
>
4023 std::basic_ostream
<_CharT
, _Traits
>&
4024 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
4025 const std::extreme_value_distribution
<_RealType
>&);
4028 * @brief Extracts a %extreme_value_distribution random number
4029 * distribution @p __x from the input stream @p __is.
4031 * @param __is An input stream.
4032 * @param __x A %extreme_value_distribution random number
4035 * @returns The input stream with @p __x extracted or in an error state.
4037 template<typename _RealType
, typename _CharT
, typename _Traits
>
4038 std::basic_istream
<_CharT
, _Traits
>&
4039 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
4040 std::extreme_value_distribution
<_RealType
>&);
4044 * @brief A discrete_distribution random number distribution.
4046 * The formula for the discrete probability mass function is
4049 template<typename _IntType
= int>
4050 class discrete_distribution
4052 __glibcxx_class_requires(_IntType
, _IntegerConcept
)
4055 /** The type of the range of the distribution. */
4056 typedef _IntType result_type
;
4057 /** Parameter type. */
4060 typedef discrete_distribution
<_IntType
> distribution_type
;
4061 friend class discrete_distribution
<_IntType
>;
4064 : _M_prob(), _M_cp()
4065 { _M_initialize(); }
4067 template<typename _InputIterator
>
4068 param_type(_InputIterator __wbegin
,
4069 _InputIterator __wend
)
4070 : _M_prob(__wbegin
, __wend
), _M_cp()
4071 { _M_initialize(); }
4073 param_type(initializer_list
<double> __wil
)
4074 : _M_prob(__wil
.begin(), __wil
.end()), _M_cp()
4075 { _M_initialize(); }
4077 template<typename _Func
>
4078 param_type(size_t __nw
, double __xmin
, double __xmax
,
4082 probabilities() const
4089 std::vector
<double> _M_prob
;
4090 std::vector
<double> _M_cp
;
4093 discrete_distribution()
4097 template<typename _InputIterator
>
4098 discrete_distribution(_InputIterator __wbegin
,
4099 _InputIterator __wend
)
4100 : _M_param(__wbegin
, __wend
)
4103 discrete_distribution(initializer_list
<double> __wil
)
4107 template<typename _Func
>
4108 discrete_distribution(size_t __nw
, double __xmin
, double __xmax
,
4110 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
4114 discrete_distribution(const param_type
& __p
)
4119 * @brief Resets the distribution state.
4126 * @brief Returns the probabilities of the distribution.
4129 probabilities() const
4130 { return _M_param
.probabilities(); }
4133 * @brief Returns the parameter set of the distribution.
4137 { return _M_param
; }
4140 * @brief Sets the parameter set of the distribution.
4141 * @param __param The new parameter set of the distribution.
4144 param(const param_type
& __param
)
4145 { _M_param
= __param
; }
4148 * @brief Returns the greatest lower bound value of the distribution.
4152 { return result_type(0); }
4155 * @brief Returns the least upper bound value of the distribution.
4159 { return this->_M_param
._M_prob
.size() - 1; }
4161 template<typename _UniformRandomNumberGenerator
>
4163 operator()(_UniformRandomNumberGenerator
& __urng
)
4164 { return this->operator()(__urng
, this->param()); }
4166 template<typename _UniformRandomNumberGenerator
>
4168 operator()(_UniformRandomNumberGenerator
& __urng
,
4169 const param_type
& __p
);
4172 * @brief Inserts a %discrete_distribution random number distribution
4173 * @p __x into the output stream @p __os.
4175 * @param __os An output stream.
4176 * @param __x A %discrete_distribution random number distribution.
4178 * @returns The output stream with the state of @p __x inserted or in
4181 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4182 friend std::basic_ostream
<_CharT
, _Traits
>&
4183 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
4184 const std::discrete_distribution
<_IntType1
>&);
4187 * @brief Extracts a %discrete_distribution random number distribution
4188 * @p __x from the input stream @p __is.
4190 * @param __is An input stream.
4191 * @param __x A %discrete_distribution random number
4194 * @returns The input stream with @p __x extracted or in an error
4197 template<typename _IntType1
, typename _CharT
, typename _Traits
>
4198 friend std::basic_istream
<_CharT
, _Traits
>&
4199 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
4200 std::discrete_distribution
<_IntType1
>&);
4203 param_type _M_param
;
4208 * @brief A piecewise_constant_distribution random number distribution.
4210 * The formula for the piecewise constant probability mass function is
4213 template<typename _RealType
= double>
4214 class piecewise_constant_distribution
4217 /** The type of the range of the distribution. */
4218 typedef _RealType result_type
;
4219 /** Parameter type. */
4222 typedef piecewise_constant_distribution
<_RealType
> distribution_type
;
4223 friend class piecewise_constant_distribution
<_RealType
>;
4227 template<typename _InputIteratorB
, typename _InputIteratorW
>
4228 param_type(_InputIteratorB __bfirst
,
4229 _InputIteratorB __bend
,
4230 _InputIteratorW __wbegin
);
4232 template<typename _Func
>
4233 param_type(initializer_list
<_RealType
> __bil
, _Func __fw
);
4235 template<typename _Func
>
4236 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
4239 std::vector
<_RealType
>
4251 std::vector
<_RealType
> _M_int
;
4252 std::vector
<double> _M_den
;
4253 std::vector
<double> _M_cp
;
4257 piecewise_constant_distribution()
4261 template<typename _InputIteratorB
, typename _InputIteratorW
>
4262 piecewise_constant_distribution(_InputIteratorB __bfirst
,
4263 _InputIteratorB __bend
,
4264 _InputIteratorW __wbegin
)
4265 : _M_param(__bfirst
, __bend
, __wbegin
)
4268 template<typename _Func
>
4269 piecewise_constant_distribution(initializer_list
<_RealType
> __bil
,
4271 : _M_param(__bil
, __fw
)
4274 template<typename _Func
>
4275 piecewise_constant_distribution(size_t __nw
,
4276 _RealType __xmin
, _RealType __xmax
,
4278 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
4282 piecewise_constant_distribution(const param_type
& __p
)
4287 * @brief Resets the distribution state.
4294 * @brief Returns a vector of the intervals.
4296 std::vector
<_RealType
>
4298 { return _M_param
.intervals(); }
4301 * @brief Returns a vector of the probability densities.
4305 { return _M_param
.densities(); }
4308 * @brief Returns the parameter set of the distribution.
4312 { return _M_param
; }
4315 * @brief Sets the parameter set of the distribution.
4316 * @param __param The new parameter set of the distribution.
4319 param(const param_type
& __param
)
4320 { _M_param
= __param
; }
4323 * @brief Returns the greatest lower bound value of the distribution.
4327 { return this->_M_param
._M_int
.front(); }
4330 * @brief Returns the least upper bound value of the distribution.
4334 { return this->_M_param
._M_int
.back(); }
4336 template<typename _UniformRandomNumberGenerator
>
4338 operator()(_UniformRandomNumberGenerator
& __urng
)
4339 { return this->operator()(__urng
, this->param()); }
4341 template<typename _UniformRandomNumberGenerator
>
4343 operator()(_UniformRandomNumberGenerator
& __urng
,
4344 const param_type
& __p
);
4347 * @brief Inserts a %piecewise_constan_distribution random
4348 * number distribution @p __x into the output stream @p __os.
4350 * @param __os An output stream.
4351 * @param __x A %piecewise_constan_distribution random number
4354 * @returns The output stream with the state of @p __x inserted or in
4357 template<typename _RealType1
, typename _CharT
, typename _Traits
>
4358 friend std::basic_ostream
<_CharT
, _Traits
>&
4359 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
4360 const std::piecewise_constant_distribution
<_RealType1
>&);
4363 * @brief Extracts a %piecewise_constan_distribution random
4364 * number distribution @p __x from the input stream @p __is.
4366 * @param __is An input stream.
4367 * @param __x A %piecewise_constan_distribution random number
4370 * @returns The input stream with @p __x extracted or in an error
4373 template<typename _RealType1
, typename _CharT
, typename _Traits
>
4374 friend std::basic_istream
<_CharT
, _Traits
>&
4375 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
4376 std::piecewise_constant_distribution
<_RealType1
>&);
4379 param_type _M_param
;
4384 * @brief A piecewise_linear_distribution random number distribution.
4386 * The formula for the piecewise linear probability mass function is
4389 template<typename _RealType
= double>
4390 class piecewise_linear_distribution
4393 /** The type of the range of the distribution. */
4394 typedef _RealType result_type
;
4395 /** Parameter type. */
4398 typedef piecewise_linear_distribution
<_RealType
> distribution_type
;
4399 friend class piecewise_linear_distribution
<_RealType
>;
4403 template<typename _InputIteratorB
, typename _InputIteratorW
>
4404 param_type(_InputIteratorB __bfirst
,
4405 _InputIteratorB __bend
,
4406 _InputIteratorW __wbegin
);
4408 template<typename _Func
>
4409 param_type(initializer_list
<_RealType
> __bil
, _Func __fw
);
4411 template<typename _Func
>
4412 param_type(size_t __nw
, _RealType __xmin
, _RealType __xmax
,
4415 std::vector
<_RealType
>
4427 std::vector
<_RealType
> _M_int
;
4428 std::vector
<double> _M_den
;
4429 std::vector
<double> _M_cp
;
4430 std::vector
<double> _M_m
;
4434 piecewise_linear_distribution()
4438 template<typename _InputIteratorB
, typename _InputIteratorW
>
4439 piecewise_linear_distribution(_InputIteratorB __bfirst
,
4440 _InputIteratorB __bend
,
4441 _InputIteratorW __wbegin
)
4442 : _M_param(__bfirst
, __bend
, __wbegin
)
4445 template<typename _Func
>
4446 piecewise_linear_distribution(initializer_list
<_RealType
> __bil
,
4448 : _M_param(__bil
, __fw
)
4451 template<typename _Func
>
4452 piecewise_linear_distribution(size_t __nw
,
4453 _RealType __xmin
, _RealType __xmax
,
4455 : _M_param(__nw
, __xmin
, __xmax
, __fw
)
4459 piecewise_linear_distribution(const param_type
& __p
)
4464 * Resets the distribution state.
4471 * @brief Return the intervals of the distribution.
4473 std::vector
<_RealType
>
4475 { return _M_param
.intervals(); }
4478 * @brief Return a vector of the probability densities of the
4483 { return _M_param
.densities(); }
4486 * @brief Returns the parameter set of the distribution.
4490 { return _M_param
; }
4493 * @brief Sets the parameter set of the distribution.
4494 * @param __param The new parameter set of the distribution.
4497 param(const param_type
& __param
)
4498 { _M_param
= __param
; }
4501 * @brief Returns the greatest lower bound value of the distribution.
4505 { return this->_M_param
._M_int
.front(); }
4508 * @brief Returns the least upper bound value of the distribution.
4512 { return this->_M_param
._M_int
.back(); }
4514 template<typename _UniformRandomNumberGenerator
>
4516 operator()(_UniformRandomNumberGenerator
& __urng
)
4517 { return this->operator()(__urng
, this->param()); }
4519 template<typename _UniformRandomNumberGenerator
>
4521 operator()(_UniformRandomNumberGenerator
& __urng
,
4522 const param_type
& __p
);
4525 * @brief Inserts a %piecewise_linear_distribution random number
4526 * distribution @p __x into the output stream @p __os.
4528 * @param __os An output stream.
4529 * @param __x A %piecewise_linear_distribution random number
4532 * @returns The output stream with the state of @p __x inserted or in
4535 template<typename _RealType1
, typename _CharT
, typename _Traits
>
4536 friend std::basic_ostream
<_CharT
, _Traits
>&
4537 operator<<(std::basic_ostream
<_CharT
, _Traits
>&,
4538 const std::piecewise_linear_distribution
<_RealType1
>&);
4541 * @brief Extracts a %piecewise_linear_distribution random number
4542 * distribution @p __x from the input stream @p __is.
4544 * @param __is An input stream.
4545 * @param __x A %piecewise_linear_distribution random number
4548 * @returns The input stream with @p __x extracted or in an error
4551 template<typename _RealType1
, typename _CharT
, typename _Traits
>
4552 friend std::basic_istream
<_CharT
, _Traits
>&
4553 operator>>(std::basic_istream
<_CharT
, _Traits
>&,
4554 std::piecewise_linear_distribution
<_RealType1
>&);
4557 param_type _M_param
;
4561 /* @} */ // group std_random_distributions_poisson
4563 /* @} */ // group std_random_distributions
4566 * @addtogroup std_random_utilities Random Number Utilities
4567 * @ingroup std_random
4572 * @brief The seed_seq class generates sequences of seeds for random
4573 * number generators.
4579 /** The type of the seed vales. */
4580 typedef uint_least32_t result_type
;
4582 /** Default constructor. */
4587 template<typename _IntType
>
4588 seed_seq(std::initializer_list
<_IntType
> il
);
4590 template<typename _InputIterator
>
4591 seed_seq(_InputIterator __begin
, _InputIterator __end
);
4593 // generating functions
4594 template<typename _RandomAccessIterator
>
4596 generate(_RandomAccessIterator __begin
, _RandomAccessIterator __end
);
4598 // property functions
4600 { return _M_v
.size(); }
4602 template<typename OutputIterator
>
4604 param(OutputIterator __dest
) const
4605 { std::copy(_M_v
.begin(), _M_v
.end(), __dest
); }
4609 std::vector
<result_type
> _M_v
;
4612 /* @} */ // group std_random_utilities
4614 /* @} */ // group std_random