Make FDO more tolerant to source changes
[official-gcc.git] / libstdc++-v3 / include / bits / random.h
bloba466a45ba4d227d11558e47de75a90f1512d107e
1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2014 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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/>.
25 /**
26 * @file bits/random.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
31 #ifndef _RANDOM_H
32 #define _RANDOM_H 1
34 #include <vector>
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 // [26.4] Random number generation
42 /**
43 * @defgroup random Random Number Generation
44 * @ingroup numerics
46 * A facility for generating random numbers on selected distributions.
47 * @{
50 /**
51 * @brief A function template for converting the output of a (integral)
52 * uniform random number generator to a floatng point result in the range
53 * [0-1).
55 template<typename _RealType, size_t __bits,
56 typename _UniformRandomNumberGenerator>
57 _RealType
58 generate_canonical(_UniformRandomNumberGenerator& __g);
60 _GLIBCXX_END_NAMESPACE_VERSION
63 * Implementation-space details.
65 namespace __detail
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _UIntType, size_t __w,
70 bool = __w < static_cast<size_t>
71 (std::numeric_limits<_UIntType>::digits)>
72 struct _Shift
73 { static const _UIntType __value = 0; };
75 template<typename _UIntType, size_t __w>
76 struct _Shift<_UIntType, __w, true>
77 { static const _UIntType __value = _UIntType(1) << __w; };
79 template<int __s,
80 int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
81 + (__s <= __CHAR_BIT__ * sizeof (long))
82 + (__s <= __CHAR_BIT__ * sizeof (long long))
83 /* assume long long no bigger than __int128 */
84 + (__s <= 128))>
85 struct _Select_uint_least_t
87 static_assert(__which < 0, /* needs to be dependent */
88 "sorry, would be too much trouble for a slow result");
91 template<int __s>
92 struct _Select_uint_least_t<__s, 4>
93 { typedef unsigned int type; };
95 template<int __s>
96 struct _Select_uint_least_t<__s, 3>
97 { typedef unsigned long type; };
99 template<int __s>
100 struct _Select_uint_least_t<__s, 2>
101 { typedef unsigned long long type; };
103 #ifdef _GLIBCXX_USE_INT128
104 template<int __s>
105 struct _Select_uint_least_t<__s, 1>
106 { typedef unsigned __int128 type; };
107 #endif
109 // Assume a != 0, a < m, c < m, x < m.
110 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
111 bool __big_enough = (!(__m & (__m - 1))
112 || (_Tp(-1) - __c) / __a >= __m - 1),
113 bool __schrage_ok = __m % __a < __m / __a>
114 struct _Mod
116 typedef typename _Select_uint_least_t<std::__lg(__a)
117 + std::__lg(__m) + 2>::type _Tp2;
118 static _Tp
119 __calc(_Tp __x)
120 { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); }
123 // Schrage.
124 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
125 struct _Mod<_Tp, __m, __a, __c, false, true>
127 static _Tp
128 __calc(_Tp __x);
131 // Special cases:
132 // - for m == 2^n or m == 0, unsigned integer overflow is safe.
133 // - a * (m - 1) + c fits in _Tp, there is no overflow.
134 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
135 struct _Mod<_Tp, __m, __a, __c, true, __s>
137 static _Tp
138 __calc(_Tp __x)
140 _Tp __res = __a * __x + __c;
141 if (__m)
142 __res %= __m;
143 return __res;
147 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
148 inline _Tp
149 __mod(_Tp __x)
150 { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
152 /* Determine whether number is a power of 2. */
153 template<typename _Tp>
154 inline bool
155 _Power_of_2(_Tp __x)
157 return ((__x - 1) & __x) == 0;
161 * An adaptor class for converting the output of any Generator into
162 * the input for a specific Distribution.
164 template<typename _Engine, typename _DInputType>
165 struct _Adaptor
168 public:
169 _Adaptor(_Engine& __g)
170 : _M_g(__g) { }
172 _DInputType
173 min() const
174 { return _DInputType(0); }
176 _DInputType
177 max() const
178 { return _DInputType(1); }
181 * Converts a value generated by the adapted random number generator
182 * into a value in the input domain for the dependent random number
183 * distribution.
185 _DInputType
186 operator()()
188 return std::generate_canonical<_DInputType,
189 std::numeric_limits<_DInputType>::digits,
190 _Engine>(_M_g);
193 private:
194 _Engine& _M_g;
197 _GLIBCXX_END_NAMESPACE_VERSION
198 } // namespace __detail
200 _GLIBCXX_BEGIN_NAMESPACE_VERSION
203 * @addtogroup random_generators Random Number Generators
204 * @ingroup random
206 * These classes define objects which provide random or pseudorandom
207 * numbers, either from a discrete or a continuous interval. The
208 * random number generator supplied as a part of this library are
209 * all uniform random number generators which provide a sequence of
210 * random number uniformly distributed over their range.
212 * A number generator is a function object with an operator() that
213 * takes zero arguments and returns a number.
215 * A compliant random number generator must satisfy the following
216 * requirements. <table border=1 cellpadding=10 cellspacing=0>
217 * <caption align=top>Random Number Generator Requirements</caption>
218 * <tr><td>To be documented.</td></tr> </table>
220 * @{
224 * @brief A model of a linear congruential random number generator.
226 * A random number generator that produces pseudorandom numbers via
227 * linear function:
228 * @f[
229 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
230 * @f]
232 * The template parameter @p _UIntType must be an unsigned integral type
233 * large enough to store values up to (__m-1). If the template parameter
234 * @p __m is 0, the modulus @p __m used is
235 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
236 * parameters @p __a and @p __c must be less than @p __m.
238 * The size of the state is @f$1@f$.
240 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
241 class linear_congruential_engine
243 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
244 "substituting _UIntType not an unsigned integral type");
245 static_assert(__m == 0u || (__a < __m && __c < __m),
246 "template argument substituting __m out of bounds");
248 public:
249 /** The type of the generated random value. */
250 typedef _UIntType result_type;
252 /** The multiplier. */
253 static constexpr result_type multiplier = __a;
254 /** An increment. */
255 static constexpr result_type increment = __c;
256 /** The modulus. */
257 static constexpr result_type modulus = __m;
258 static constexpr result_type default_seed = 1u;
261 * @brief Constructs a %linear_congruential_engine random number
262 * generator engine with seed @p __s. The default seed value
263 * is 1.
265 * @param __s The initial seed value.
267 explicit
268 linear_congruential_engine(result_type __s = default_seed)
269 { seed(__s); }
272 * @brief Constructs a %linear_congruential_engine random number
273 * generator engine seeded from the seed sequence @p __q.
275 * @param __q the seed sequence.
277 template<typename _Sseq, typename = typename
278 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
279 ::type>
280 explicit
281 linear_congruential_engine(_Sseq& __q)
282 { seed(__q); }
285 * @brief Reseeds the %linear_congruential_engine random number generator
286 * engine sequence to the seed @p __s.
288 * @param __s The new seed.
290 void
291 seed(result_type __s = default_seed);
294 * @brief Reseeds the %linear_congruential_engine random number generator
295 * engine
296 * sequence using values from the seed sequence @p __q.
298 * @param __q the seed sequence.
300 template<typename _Sseq>
301 typename std::enable_if<std::is_class<_Sseq>::value>::type
302 seed(_Sseq& __q);
305 * @brief Gets the smallest possible value in the output range.
307 * The minimum depends on the @p __c parameter: if it is zero, the
308 * minimum generated must be > 0, otherwise 0 is allowed.
310 static constexpr result_type
311 min()
312 { return __c == 0u ? 1u : 0u; }
315 * @brief Gets the largest possible value in the output range.
317 static constexpr result_type
318 max()
319 { return __m - 1u; }
322 * @brief Discard a sequence of random numbers.
324 void
325 discard(unsigned long long __z)
327 for (; __z != 0ULL; --__z)
328 (*this)();
332 * @brief Gets the next random number in the sequence.
334 result_type
335 operator()()
337 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
338 return _M_x;
342 * @brief Compares two linear congruential random number generator
343 * objects of the same type for equality.
345 * @param __lhs A linear congruential random number generator object.
346 * @param __rhs Another linear congruential random number generator
347 * object.
349 * @returns true if the infinite sequences of generated values
350 * would be equal, false otherwise.
352 friend bool
353 operator==(const linear_congruential_engine& __lhs,
354 const linear_congruential_engine& __rhs)
355 { return __lhs._M_x == __rhs._M_x; }
358 * @brief Writes the textual representation of the state x(i) of x to
359 * @p __os.
361 * @param __os The output stream.
362 * @param __lcr A % linear_congruential_engine random number generator.
363 * @returns __os.
365 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
366 _UIntType1 __m1, typename _CharT, typename _Traits>
367 friend std::basic_ostream<_CharT, _Traits>&
368 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
369 const std::linear_congruential_engine<_UIntType1,
370 __a1, __c1, __m1>& __lcr);
373 * @brief Sets the state of the engine by reading its textual
374 * representation from @p __is.
376 * The textual representation must have been previously written using
377 * an output stream whose imbued locale and whose type's template
378 * specialization arguments _CharT and _Traits were the same as those
379 * of @p __is.
381 * @param __is The input stream.
382 * @param __lcr A % linear_congruential_engine random number generator.
383 * @returns __is.
385 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
386 _UIntType1 __m1, typename _CharT, typename _Traits>
387 friend std::basic_istream<_CharT, _Traits>&
388 operator>>(std::basic_istream<_CharT, _Traits>& __is,
389 std::linear_congruential_engine<_UIntType1, __a1,
390 __c1, __m1>& __lcr);
392 private:
393 _UIntType _M_x;
397 * @brief Compares two linear congruential random number generator
398 * objects of the same type for inequality.
400 * @param __lhs A linear congruential random number generator object.
401 * @param __rhs Another linear congruential random number generator
402 * object.
404 * @returns true if the infinite sequences of generated values
405 * would be different, false otherwise.
407 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
408 inline bool
409 operator!=(const std::linear_congruential_engine<_UIntType, __a,
410 __c, __m>& __lhs,
411 const std::linear_congruential_engine<_UIntType, __a,
412 __c, __m>& __rhs)
413 { return !(__lhs == __rhs); }
417 * A generalized feedback shift register discrete random number generator.
419 * This algorithm avoids multiplication and division and is designed to be
420 * friendly to a pipelined architecture. If the parameters are chosen
421 * correctly, this generator will produce numbers with a very long period and
422 * fairly good apparent entropy, although still not cryptographically strong.
424 * The best way to use this generator is with the predefined mt19937 class.
426 * This algorithm was originally invented by Makoto Matsumoto and
427 * Takuji Nishimura.
429 * @tparam __w Word size, the number of bits in each element of
430 * the state vector.
431 * @tparam __n The degree of recursion.
432 * @tparam __m The period parameter.
433 * @tparam __r The separation point bit index.
434 * @tparam __a The last row of the twist matrix.
435 * @tparam __u The first right-shift tempering matrix parameter.
436 * @tparam __d The first right-shift tempering matrix mask.
437 * @tparam __s The first left-shift tempering matrix parameter.
438 * @tparam __b The first left-shift tempering matrix mask.
439 * @tparam __t The second left-shift tempering matrix parameter.
440 * @tparam __c The second left-shift tempering matrix mask.
441 * @tparam __l The second right-shift tempering matrix parameter.
442 * @tparam __f Initialization multiplier.
444 template<typename _UIntType, size_t __w,
445 size_t __n, size_t __m, size_t __r,
446 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
447 _UIntType __b, size_t __t,
448 _UIntType __c, size_t __l, _UIntType __f>
449 class mersenne_twister_engine
451 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
452 "substituting _UIntType not an unsigned integral type");
453 static_assert(1u <= __m && __m <= __n,
454 "template argument substituting __m out of bounds");
455 static_assert(__r <= __w, "template argument substituting "
456 "__r out of bound");
457 static_assert(__u <= __w, "template argument substituting "
458 "__u out of bound");
459 static_assert(__s <= __w, "template argument substituting "
460 "__s out of bound");
461 static_assert(__t <= __w, "template argument substituting "
462 "__t out of bound");
463 static_assert(__l <= __w, "template argument substituting "
464 "__l out of bound");
465 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
466 "template argument substituting __w out of bound");
467 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
468 "template argument substituting __a out of bound");
469 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
470 "template argument substituting __b out of bound");
471 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
472 "template argument substituting __c out of bound");
473 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
474 "template argument substituting __d out of bound");
475 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
476 "template argument substituting __f out of bound");
478 public:
479 /** The type of the generated random value. */
480 typedef _UIntType result_type;
482 // parameter values
483 static constexpr size_t word_size = __w;
484 static constexpr size_t state_size = __n;
485 static constexpr size_t shift_size = __m;
486 static constexpr size_t mask_bits = __r;
487 static constexpr result_type xor_mask = __a;
488 static constexpr size_t tempering_u = __u;
489 static constexpr result_type tempering_d = __d;
490 static constexpr size_t tempering_s = __s;
491 static constexpr result_type tempering_b = __b;
492 static constexpr size_t tempering_t = __t;
493 static constexpr result_type tempering_c = __c;
494 static constexpr size_t tempering_l = __l;
495 static constexpr result_type initialization_multiplier = __f;
496 static constexpr result_type default_seed = 5489u;
498 // constructors and member function
499 explicit
500 mersenne_twister_engine(result_type __sd = default_seed)
501 { seed(__sd); }
504 * @brief Constructs a %mersenne_twister_engine random number generator
505 * engine seeded from the seed sequence @p __q.
507 * @param __q the seed sequence.
509 template<typename _Sseq, typename = typename
510 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
511 ::type>
512 explicit
513 mersenne_twister_engine(_Sseq& __q)
514 { seed(__q); }
516 void
517 seed(result_type __sd = default_seed);
519 template<typename _Sseq>
520 typename std::enable_if<std::is_class<_Sseq>::value>::type
521 seed(_Sseq& __q);
524 * @brief Gets the smallest possible value in the output range.
526 static constexpr result_type
527 min()
528 { return 0; };
531 * @brief Gets the largest possible value in the output range.
533 static constexpr result_type
534 max()
535 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
538 * @brief Discard a sequence of random numbers.
540 void
541 discard(unsigned long long __z);
543 result_type
544 operator()();
547 * @brief Compares two % mersenne_twister_engine random number generator
548 * objects of the same type for equality.
550 * @param __lhs A % mersenne_twister_engine random number generator
551 * object.
552 * @param __rhs Another % mersenne_twister_engine random number
553 * generator object.
555 * @returns true if the infinite sequences of generated values
556 * would be equal, false otherwise.
558 friend bool
559 operator==(const mersenne_twister_engine& __lhs,
560 const mersenne_twister_engine& __rhs)
561 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
562 && __lhs._M_p == __rhs._M_p); }
565 * @brief Inserts the current state of a % mersenne_twister_engine
566 * random number generator engine @p __x into the output stream
567 * @p __os.
569 * @param __os An output stream.
570 * @param __x A % mersenne_twister_engine random number generator
571 * engine.
573 * @returns The output stream with the state of @p __x inserted or in
574 * an error state.
576 template<typename _UIntType1,
577 size_t __w1, size_t __n1,
578 size_t __m1, size_t __r1,
579 _UIntType1 __a1, size_t __u1,
580 _UIntType1 __d1, size_t __s1,
581 _UIntType1 __b1, size_t __t1,
582 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
583 typename _CharT, typename _Traits>
584 friend std::basic_ostream<_CharT, _Traits>&
585 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
586 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
587 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
588 __l1, __f1>& __x);
591 * @brief Extracts the current state of a % mersenne_twister_engine
592 * random number generator engine @p __x from the input stream
593 * @p __is.
595 * @param __is An input stream.
596 * @param __x A % mersenne_twister_engine random number generator
597 * engine.
599 * @returns The input stream with the state of @p __x extracted or in
600 * an error state.
602 template<typename _UIntType1,
603 size_t __w1, size_t __n1,
604 size_t __m1, size_t __r1,
605 _UIntType1 __a1, size_t __u1,
606 _UIntType1 __d1, size_t __s1,
607 _UIntType1 __b1, size_t __t1,
608 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
609 typename _CharT, typename _Traits>
610 friend std::basic_istream<_CharT, _Traits>&
611 operator>>(std::basic_istream<_CharT, _Traits>& __is,
612 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
613 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
614 __l1, __f1>& __x);
616 private:
617 void _M_gen_rand();
619 _UIntType _M_x[state_size];
620 size_t _M_p;
624 * @brief Compares two % mersenne_twister_engine random number generator
625 * objects of the same type for inequality.
627 * @param __lhs A % mersenne_twister_engine random number generator
628 * object.
629 * @param __rhs Another % mersenne_twister_engine random number
630 * generator object.
632 * @returns true if the infinite sequences of generated values
633 * would be different, false otherwise.
635 template<typename _UIntType, size_t __w,
636 size_t __n, size_t __m, size_t __r,
637 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
638 _UIntType __b, size_t __t,
639 _UIntType __c, size_t __l, _UIntType __f>
640 inline bool
641 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
642 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
643 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
644 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
645 { return !(__lhs == __rhs); }
649 * @brief The Marsaglia-Zaman generator.
651 * This is a model of a Generalized Fibonacci discrete random number
652 * generator, sometimes referred to as the SWC generator.
654 * A discrete random number generator that produces pseudorandom
655 * numbers using:
656 * @f[
657 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
658 * @f]
660 * The size of the state is @f$r@f$
661 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
663 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
664 class subtract_with_carry_engine
666 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
667 "substituting _UIntType not an unsigned integral type");
668 static_assert(0u < __s && __s < __r,
669 "template argument substituting __s out of bounds");
670 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
671 "template argument substituting __w out of bounds");
673 public:
674 /** The type of the generated random value. */
675 typedef _UIntType result_type;
677 // parameter values
678 static constexpr size_t word_size = __w;
679 static constexpr size_t short_lag = __s;
680 static constexpr size_t long_lag = __r;
681 static constexpr result_type default_seed = 19780503u;
684 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
685 * random number generator.
687 explicit
688 subtract_with_carry_engine(result_type __sd = default_seed)
689 { seed(__sd); }
692 * @brief Constructs a %subtract_with_carry_engine random number engine
693 * seeded from the seed sequence @p __q.
695 * @param __q the seed sequence.
697 template<typename _Sseq, typename = typename
698 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
699 ::type>
700 explicit
701 subtract_with_carry_engine(_Sseq& __q)
702 { seed(__q); }
705 * @brief Seeds the initial state @f$x_0@f$ of the random number
706 * generator.
708 * N1688[4.19] modifies this as follows. If @p __value == 0,
709 * sets value to 19780503. In any case, with a linear
710 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
711 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
712 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
713 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
714 * set carry to 1, otherwise sets carry to 0.
716 void
717 seed(result_type __sd = default_seed);
720 * @brief Seeds the initial state @f$x_0@f$ of the
721 * % subtract_with_carry_engine random number generator.
723 template<typename _Sseq>
724 typename std::enable_if<std::is_class<_Sseq>::value>::type
725 seed(_Sseq& __q);
728 * @brief Gets the inclusive minimum value of the range of random
729 * integers returned by this generator.
731 static constexpr result_type
732 min()
733 { return 0; }
736 * @brief Gets the inclusive maximum value of the range of random
737 * integers returned by this generator.
739 static constexpr result_type
740 max()
741 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
744 * @brief Discard a sequence of random numbers.
746 void
747 discard(unsigned long long __z)
749 for (; __z != 0ULL; --__z)
750 (*this)();
754 * @brief Gets the next random number in the sequence.
756 result_type
757 operator()();
760 * @brief Compares two % subtract_with_carry_engine random number
761 * generator objects of the same type for equality.
763 * @param __lhs A % subtract_with_carry_engine random number generator
764 * object.
765 * @param __rhs Another % subtract_with_carry_engine random number
766 * generator object.
768 * @returns true if the infinite sequences of generated values
769 * would be equal, false otherwise.
771 friend bool
772 operator==(const subtract_with_carry_engine& __lhs,
773 const subtract_with_carry_engine& __rhs)
774 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
775 && __lhs._M_carry == __rhs._M_carry
776 && __lhs._M_p == __rhs._M_p); }
779 * @brief Inserts the current state of a % subtract_with_carry_engine
780 * random number generator engine @p __x into the output stream
781 * @p __os.
783 * @param __os An output stream.
784 * @param __x A % subtract_with_carry_engine random number generator
785 * engine.
787 * @returns The output stream with the state of @p __x inserted or in
788 * an error state.
790 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
791 typename _CharT, typename _Traits>
792 friend std::basic_ostream<_CharT, _Traits>&
793 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
794 const std::subtract_with_carry_engine<_UIntType1, __w1,
795 __s1, __r1>& __x);
798 * @brief Extracts the current state of a % subtract_with_carry_engine
799 * random number generator engine @p __x from the input stream
800 * @p __is.
802 * @param __is An input stream.
803 * @param __x A % subtract_with_carry_engine random number generator
804 * engine.
806 * @returns The input stream with the state of @p __x extracted or in
807 * an error state.
809 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
810 typename _CharT, typename _Traits>
811 friend std::basic_istream<_CharT, _Traits>&
812 operator>>(std::basic_istream<_CharT, _Traits>& __is,
813 std::subtract_with_carry_engine<_UIntType1, __w1,
814 __s1, __r1>& __x);
816 private:
817 /// The state of the generator. This is a ring buffer.
818 _UIntType _M_x[long_lag];
819 _UIntType _M_carry; ///< The carry
820 size_t _M_p; ///< Current index of x(i - r).
824 * @brief Compares two % subtract_with_carry_engine random number
825 * generator objects of the same type for inequality.
827 * @param __lhs A % subtract_with_carry_engine random number generator
828 * object.
829 * @param __rhs Another % subtract_with_carry_engine random number
830 * generator object.
832 * @returns true if the infinite sequences of generated values
833 * would be different, false otherwise.
835 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
836 inline bool
837 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
838 __s, __r>& __lhs,
839 const std::subtract_with_carry_engine<_UIntType, __w,
840 __s, __r>& __rhs)
841 { return !(__lhs == __rhs); }
845 * Produces random numbers from some base engine by discarding blocks of
846 * data.
848 * 0 <= @p __r <= @p __p
850 template<typename _RandomNumberEngine, size_t __p, size_t __r>
851 class discard_block_engine
853 static_assert(1 <= __r && __r <= __p,
854 "template argument substituting __r out of bounds");
856 public:
857 /** The type of the generated random value. */
858 typedef typename _RandomNumberEngine::result_type result_type;
860 // parameter values
861 static constexpr size_t block_size = __p;
862 static constexpr size_t used_block = __r;
865 * @brief Constructs a default %discard_block_engine engine.
867 * The underlying engine is default constructed as well.
869 discard_block_engine()
870 : _M_b(), _M_n(0) { }
873 * @brief Copy constructs a %discard_block_engine engine.
875 * Copies an existing base class random number generator.
876 * @param __rng An existing (base class) engine object.
878 explicit
879 discard_block_engine(const _RandomNumberEngine& __rng)
880 : _M_b(__rng), _M_n(0) { }
883 * @brief Move constructs a %discard_block_engine engine.
885 * Copies an existing base class random number generator.
886 * @param __rng An existing (base class) engine object.
888 explicit
889 discard_block_engine(_RandomNumberEngine&& __rng)
890 : _M_b(std::move(__rng)), _M_n(0) { }
893 * @brief Seed constructs a %discard_block_engine engine.
895 * Constructs the underlying generator engine seeded with @p __s.
896 * @param __s A seed value for the base class engine.
898 explicit
899 discard_block_engine(result_type __s)
900 : _M_b(__s), _M_n(0) { }
903 * @brief Generator construct a %discard_block_engine engine.
905 * @param __q A seed sequence.
907 template<typename _Sseq, typename = typename
908 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
909 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
910 ::type>
911 explicit
912 discard_block_engine(_Sseq& __q)
913 : _M_b(__q), _M_n(0)
917 * @brief Reseeds the %discard_block_engine object with the default
918 * seed for the underlying base class generator engine.
920 void
921 seed()
923 _M_b.seed();
924 _M_n = 0;
928 * @brief Reseeds the %discard_block_engine object with the default
929 * seed for the underlying base class generator engine.
931 void
932 seed(result_type __s)
934 _M_b.seed(__s);
935 _M_n = 0;
939 * @brief Reseeds the %discard_block_engine object with the given seed
940 * sequence.
941 * @param __q A seed generator function.
943 template<typename _Sseq>
944 void
945 seed(_Sseq& __q)
947 _M_b.seed(__q);
948 _M_n = 0;
952 * @brief Gets a const reference to the underlying generator engine
953 * object.
955 const _RandomNumberEngine&
956 base() const noexcept
957 { return _M_b; }
960 * @brief Gets the minimum value in the generated random number range.
962 static constexpr result_type
963 min()
964 { return _RandomNumberEngine::min(); }
967 * @brief Gets the maximum value in the generated random number range.
969 static constexpr result_type
970 max()
971 { return _RandomNumberEngine::max(); }
974 * @brief Discard a sequence of random numbers.
976 void
977 discard(unsigned long long __z)
979 for (; __z != 0ULL; --__z)
980 (*this)();
984 * @brief Gets the next value in the generated random number sequence.
986 result_type
987 operator()();
990 * @brief Compares two %discard_block_engine random number generator
991 * objects of the same type for equality.
993 * @param __lhs A %discard_block_engine random number generator object.
994 * @param __rhs Another %discard_block_engine random number generator
995 * object.
997 * @returns true if the infinite sequences of generated values
998 * would be equal, false otherwise.
1000 friend bool
1001 operator==(const discard_block_engine& __lhs,
1002 const discard_block_engine& __rhs)
1003 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
1006 * @brief Inserts the current state of a %discard_block_engine random
1007 * number generator engine @p __x into the output stream
1008 * @p __os.
1010 * @param __os An output stream.
1011 * @param __x A %discard_block_engine random number generator engine.
1013 * @returns The output stream with the state of @p __x inserted or in
1014 * an error state.
1016 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1017 typename _CharT, typename _Traits>
1018 friend std::basic_ostream<_CharT, _Traits>&
1019 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1020 const std::discard_block_engine<_RandomNumberEngine1,
1021 __p1, __r1>& __x);
1024 * @brief Extracts the current state of a % subtract_with_carry_engine
1025 * random number generator engine @p __x from the input stream
1026 * @p __is.
1028 * @param __is An input stream.
1029 * @param __x A %discard_block_engine random number generator engine.
1031 * @returns The input stream with the state of @p __x extracted or in
1032 * an error state.
1034 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1035 typename _CharT, typename _Traits>
1036 friend std::basic_istream<_CharT, _Traits>&
1037 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1038 std::discard_block_engine<_RandomNumberEngine1,
1039 __p1, __r1>& __x);
1041 private:
1042 _RandomNumberEngine _M_b;
1043 size_t _M_n;
1047 * @brief Compares two %discard_block_engine random number generator
1048 * objects of the same type for inequality.
1050 * @param __lhs A %discard_block_engine random number generator object.
1051 * @param __rhs Another %discard_block_engine random number generator
1052 * object.
1054 * @returns true if the infinite sequences of generated values
1055 * would be different, false otherwise.
1057 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1058 inline bool
1059 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1060 __r>& __lhs,
1061 const std::discard_block_engine<_RandomNumberEngine, __p,
1062 __r>& __rhs)
1063 { return !(__lhs == __rhs); }
1067 * Produces random numbers by combining random numbers from some base
1068 * engine to produce random numbers with a specifies number of bits @p __w.
1070 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1071 class independent_bits_engine
1073 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1074 "substituting _UIntType not an unsigned integral type");
1075 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1076 "template argument substituting __w out of bounds");
1078 public:
1079 /** The type of the generated random value. */
1080 typedef _UIntType result_type;
1083 * @brief Constructs a default %independent_bits_engine engine.
1085 * The underlying engine is default constructed as well.
1087 independent_bits_engine()
1088 : _M_b() { }
1091 * @brief Copy constructs a %independent_bits_engine engine.
1093 * Copies an existing base class random number generator.
1094 * @param __rng An existing (base class) engine object.
1096 explicit
1097 independent_bits_engine(const _RandomNumberEngine& __rng)
1098 : _M_b(__rng) { }
1101 * @brief Move constructs a %independent_bits_engine engine.
1103 * Copies an existing base class random number generator.
1104 * @param __rng An existing (base class) engine object.
1106 explicit
1107 independent_bits_engine(_RandomNumberEngine&& __rng)
1108 : _M_b(std::move(__rng)) { }
1111 * @brief Seed constructs a %independent_bits_engine engine.
1113 * Constructs the underlying generator engine seeded with @p __s.
1114 * @param __s A seed value for the base class engine.
1116 explicit
1117 independent_bits_engine(result_type __s)
1118 : _M_b(__s) { }
1121 * @brief Generator construct a %independent_bits_engine engine.
1123 * @param __q A seed sequence.
1125 template<typename _Sseq, typename = typename
1126 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1127 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1128 ::type>
1129 explicit
1130 independent_bits_engine(_Sseq& __q)
1131 : _M_b(__q)
1135 * @brief Reseeds the %independent_bits_engine object with the default
1136 * seed for the underlying base class generator engine.
1138 void
1139 seed()
1140 { _M_b.seed(); }
1143 * @brief Reseeds the %independent_bits_engine object with the default
1144 * seed for the underlying base class generator engine.
1146 void
1147 seed(result_type __s)
1148 { _M_b.seed(__s); }
1151 * @brief Reseeds the %independent_bits_engine object with the given
1152 * seed sequence.
1153 * @param __q A seed generator function.
1155 template<typename _Sseq>
1156 void
1157 seed(_Sseq& __q)
1158 { _M_b.seed(__q); }
1161 * @brief Gets a const reference to the underlying generator engine
1162 * object.
1164 const _RandomNumberEngine&
1165 base() const noexcept
1166 { return _M_b; }
1169 * @brief Gets the minimum value in the generated random number range.
1171 static constexpr result_type
1172 min()
1173 { return 0U; }
1176 * @brief Gets the maximum value in the generated random number range.
1178 static constexpr result_type
1179 max()
1180 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1183 * @brief Discard a sequence of random numbers.
1185 void
1186 discard(unsigned long long __z)
1188 for (; __z != 0ULL; --__z)
1189 (*this)();
1193 * @brief Gets the next value in the generated random number sequence.
1195 result_type
1196 operator()();
1199 * @brief Compares two %independent_bits_engine random number generator
1200 * objects of the same type for equality.
1202 * @param __lhs A %independent_bits_engine random number generator
1203 * object.
1204 * @param __rhs Another %independent_bits_engine random number generator
1205 * object.
1207 * @returns true if the infinite sequences of generated values
1208 * would be equal, false otherwise.
1210 friend bool
1211 operator==(const independent_bits_engine& __lhs,
1212 const independent_bits_engine& __rhs)
1213 { return __lhs._M_b == __rhs._M_b; }
1216 * @brief Extracts the current state of a % subtract_with_carry_engine
1217 * random number generator engine @p __x from the input stream
1218 * @p __is.
1220 * @param __is An input stream.
1221 * @param __x A %independent_bits_engine random number generator
1222 * engine.
1224 * @returns The input stream with the state of @p __x extracted or in
1225 * an error state.
1227 template<typename _CharT, typename _Traits>
1228 friend std::basic_istream<_CharT, _Traits>&
1229 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1230 std::independent_bits_engine<_RandomNumberEngine,
1231 __w, _UIntType>& __x)
1233 __is >> __x._M_b;
1234 return __is;
1237 private:
1238 _RandomNumberEngine _M_b;
1242 * @brief Compares two %independent_bits_engine random number generator
1243 * objects of the same type for inequality.
1245 * @param __lhs A %independent_bits_engine random number generator
1246 * object.
1247 * @param __rhs Another %independent_bits_engine random number generator
1248 * object.
1250 * @returns true if the infinite sequences of generated values
1251 * would be different, false otherwise.
1253 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1254 inline bool
1255 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1256 _UIntType>& __lhs,
1257 const std::independent_bits_engine<_RandomNumberEngine, __w,
1258 _UIntType>& __rhs)
1259 { return !(__lhs == __rhs); }
1262 * @brief Inserts the current state of a %independent_bits_engine random
1263 * number generator engine @p __x into the output stream @p __os.
1265 * @param __os An output stream.
1266 * @param __x A %independent_bits_engine random number generator engine.
1268 * @returns The output stream with the state of @p __x inserted or in
1269 * an error state.
1271 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1272 typename _CharT, typename _Traits>
1273 std::basic_ostream<_CharT, _Traits>&
1274 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1275 const std::independent_bits_engine<_RandomNumberEngine,
1276 __w, _UIntType>& __x)
1278 __os << __x.base();
1279 return __os;
1284 * @brief Produces random numbers by combining random numbers from some
1285 * base engine to produce random numbers with a specifies number of bits
1286 * @p __w.
1288 template<typename _RandomNumberEngine, size_t __k>
1289 class shuffle_order_engine
1291 static_assert(1u <= __k, "template argument substituting "
1292 "__k out of bound");
1294 public:
1295 /** The type of the generated random value. */
1296 typedef typename _RandomNumberEngine::result_type result_type;
1298 static constexpr size_t table_size = __k;
1301 * @brief Constructs a default %shuffle_order_engine engine.
1303 * The underlying engine is default constructed as well.
1305 shuffle_order_engine()
1306 : _M_b()
1307 { _M_initialize(); }
1310 * @brief Copy constructs a %shuffle_order_engine engine.
1312 * Copies an existing base class random number generator.
1313 * @param __rng An existing (base class) engine object.
1315 explicit
1316 shuffle_order_engine(const _RandomNumberEngine& __rng)
1317 : _M_b(__rng)
1318 { _M_initialize(); }
1321 * @brief Move constructs a %shuffle_order_engine engine.
1323 * Copies an existing base class random number generator.
1324 * @param __rng An existing (base class) engine object.
1326 explicit
1327 shuffle_order_engine(_RandomNumberEngine&& __rng)
1328 : _M_b(std::move(__rng))
1329 { _M_initialize(); }
1332 * @brief Seed constructs a %shuffle_order_engine engine.
1334 * Constructs the underlying generator engine seeded with @p __s.
1335 * @param __s A seed value for the base class engine.
1337 explicit
1338 shuffle_order_engine(result_type __s)
1339 : _M_b(__s)
1340 { _M_initialize(); }
1343 * @brief Generator construct a %shuffle_order_engine engine.
1345 * @param __q A seed sequence.
1347 template<typename _Sseq, typename = typename
1348 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1349 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1350 ::type>
1351 explicit
1352 shuffle_order_engine(_Sseq& __q)
1353 : _M_b(__q)
1354 { _M_initialize(); }
1357 * @brief Reseeds the %shuffle_order_engine object with the default seed
1358 for the underlying base class generator engine.
1360 void
1361 seed()
1363 _M_b.seed();
1364 _M_initialize();
1368 * @brief Reseeds the %shuffle_order_engine object with the default seed
1369 * for the underlying base class generator engine.
1371 void
1372 seed(result_type __s)
1374 _M_b.seed(__s);
1375 _M_initialize();
1379 * @brief Reseeds the %shuffle_order_engine object with the given seed
1380 * sequence.
1381 * @param __q A seed generator function.
1383 template<typename _Sseq>
1384 void
1385 seed(_Sseq& __q)
1387 _M_b.seed(__q);
1388 _M_initialize();
1392 * Gets a const reference to the underlying generator engine object.
1394 const _RandomNumberEngine&
1395 base() const noexcept
1396 { return _M_b; }
1399 * Gets the minimum value in the generated random number range.
1401 static constexpr result_type
1402 min()
1403 { return _RandomNumberEngine::min(); }
1406 * Gets the maximum value in the generated random number range.
1408 static constexpr result_type
1409 max()
1410 { return _RandomNumberEngine::max(); }
1413 * Discard a sequence of random numbers.
1415 void
1416 discard(unsigned long long __z)
1418 for (; __z != 0ULL; --__z)
1419 (*this)();
1423 * Gets the next value in the generated random number sequence.
1425 result_type
1426 operator()();
1429 * Compares two %shuffle_order_engine random number generator objects
1430 * of the same type for equality.
1432 * @param __lhs A %shuffle_order_engine random number generator object.
1433 * @param __rhs Another %shuffle_order_engine random number generator
1434 * object.
1436 * @returns true if the infinite sequences of generated values
1437 * would be equal, false otherwise.
1439 friend bool
1440 operator==(const shuffle_order_engine& __lhs,
1441 const shuffle_order_engine& __rhs)
1442 { return (__lhs._M_b == __rhs._M_b
1443 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1444 && __lhs._M_y == __rhs._M_y); }
1447 * @brief Inserts the current state of a %shuffle_order_engine random
1448 * number generator engine @p __x into the output stream
1449 @p __os.
1451 * @param __os An output stream.
1452 * @param __x A %shuffle_order_engine random number generator engine.
1454 * @returns The output stream with the state of @p __x inserted or in
1455 * an error state.
1457 template<typename _RandomNumberEngine1, size_t __k1,
1458 typename _CharT, typename _Traits>
1459 friend std::basic_ostream<_CharT, _Traits>&
1460 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1461 const std::shuffle_order_engine<_RandomNumberEngine1,
1462 __k1>& __x);
1465 * @brief Extracts the current state of a % subtract_with_carry_engine
1466 * random number generator engine @p __x from the input stream
1467 * @p __is.
1469 * @param __is An input stream.
1470 * @param __x A %shuffle_order_engine random number generator engine.
1472 * @returns The input stream with the state of @p __x extracted or in
1473 * an error state.
1475 template<typename _RandomNumberEngine1, size_t __k1,
1476 typename _CharT, typename _Traits>
1477 friend std::basic_istream<_CharT, _Traits>&
1478 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1479 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
1481 private:
1482 void _M_initialize()
1484 for (size_t __i = 0; __i < __k; ++__i)
1485 _M_v[__i] = _M_b();
1486 _M_y = _M_b();
1489 _RandomNumberEngine _M_b;
1490 result_type _M_v[__k];
1491 result_type _M_y;
1495 * Compares two %shuffle_order_engine random number generator objects
1496 * of the same type for inequality.
1498 * @param __lhs A %shuffle_order_engine random number generator object.
1499 * @param __rhs Another %shuffle_order_engine random number generator
1500 * object.
1502 * @returns true if the infinite sequences of generated values
1503 * would be different, false otherwise.
1505 template<typename _RandomNumberEngine, size_t __k>
1506 inline bool
1507 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1508 __k>& __lhs,
1509 const std::shuffle_order_engine<_RandomNumberEngine,
1510 __k>& __rhs)
1511 { return !(__lhs == __rhs); }
1515 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1517 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1518 minstd_rand0;
1521 * An alternative LCR (Lehmer Generator function).
1523 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1524 minstd_rand;
1527 * The classic Mersenne Twister.
1529 * Reference:
1530 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1531 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1532 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1534 typedef mersenne_twister_engine<
1535 uint_fast32_t,
1536 32, 624, 397, 31,
1537 0x9908b0dfUL, 11,
1538 0xffffffffUL, 7,
1539 0x9d2c5680UL, 15,
1540 0xefc60000UL, 18, 1812433253UL> mt19937;
1543 * An alternative Mersenne Twister.
1545 typedef mersenne_twister_engine<
1546 uint_fast64_t,
1547 64, 312, 156, 31,
1548 0xb5026f5aa96619e9ULL, 29,
1549 0x5555555555555555ULL, 17,
1550 0x71d67fffeda60000ULL, 37,
1551 0xfff7eee000000000ULL, 43,
1552 6364136223846793005ULL> mt19937_64;
1554 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1555 ranlux24_base;
1557 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1558 ranlux48_base;
1560 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1562 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1564 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1566 typedef minstd_rand0 default_random_engine;
1569 * A standard interface to a platform-specific non-deterministic
1570 * random number generator (if any are available).
1572 class random_device
1574 public:
1575 /** The type of the generated random value. */
1576 typedef unsigned int result_type;
1578 // constructors, destructors and member functions
1580 #ifdef _GLIBCXX_USE_RANDOM_TR1
1582 explicit
1583 random_device(const std::string& __token = "default")
1585 _M_init(__token);
1588 ~random_device()
1589 { _M_fini(); }
1591 #else
1593 explicit
1594 random_device(const std::string& __token = "mt19937")
1595 { _M_init_pretr1(__token); }
1597 public:
1599 #endif
1601 static constexpr result_type
1602 min()
1603 { return std::numeric_limits<result_type>::min(); }
1605 static constexpr result_type
1606 max()
1607 { return std::numeric_limits<result_type>::max(); }
1609 double
1610 entropy() const noexcept
1611 { return 0.0; }
1613 result_type
1614 operator()()
1616 #ifdef _GLIBCXX_USE_RANDOM_TR1
1617 return this->_M_getval();
1618 #else
1619 return this->_M_getval_pretr1();
1620 #endif
1623 // No copy functions.
1624 random_device(const random_device&) = delete;
1625 void operator=(const random_device&) = delete;
1627 private:
1629 void _M_init(const std::string& __token);
1630 void _M_init_pretr1(const std::string& __token);
1631 void _M_fini();
1633 result_type _M_getval();
1634 result_type _M_getval_pretr1();
1636 union
1638 void* _M_file;
1639 mt19937 _M_mt;
1643 /* @} */ // group random_generators
1646 * @addtogroup random_distributions Random Number Distributions
1647 * @ingroup random
1648 * @{
1652 * @addtogroup random_distributions_uniform Uniform Distributions
1653 * @ingroup random_distributions
1654 * @{
1658 * @brief Uniform discrete distribution for random numbers.
1659 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1660 * probability throughout the range.
1662 template<typename _IntType = int>
1663 class uniform_int_distribution
1665 static_assert(std::is_integral<_IntType>::value,
1666 "template argument not an integral type");
1668 public:
1669 /** The type of the range of the distribution. */
1670 typedef _IntType result_type;
1671 /** Parameter type. */
1672 struct param_type
1674 typedef uniform_int_distribution<_IntType> distribution_type;
1676 explicit
1677 param_type(_IntType __a = 0,
1678 _IntType __b = std::numeric_limits<_IntType>::max())
1679 : _M_a(__a), _M_b(__b)
1681 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1684 result_type
1685 a() const
1686 { return _M_a; }
1688 result_type
1689 b() const
1690 { return _M_b; }
1692 friend bool
1693 operator==(const param_type& __p1, const param_type& __p2)
1694 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1696 private:
1697 _IntType _M_a;
1698 _IntType _M_b;
1701 public:
1703 * @brief Constructs a uniform distribution object.
1705 explicit
1706 uniform_int_distribution(_IntType __a = 0,
1707 _IntType __b = std::numeric_limits<_IntType>::max())
1708 : _M_param(__a, __b)
1711 explicit
1712 uniform_int_distribution(const param_type& __p)
1713 : _M_param(__p)
1717 * @brief Resets the distribution state.
1719 * Does nothing for the uniform integer distribution.
1721 void
1722 reset() { }
1724 result_type
1725 a() const
1726 { return _M_param.a(); }
1728 result_type
1729 b() const
1730 { return _M_param.b(); }
1733 * @brief Returns the parameter set of the distribution.
1735 param_type
1736 param() const
1737 { return _M_param; }
1740 * @brief Sets the parameter set of the distribution.
1741 * @param __param The new parameter set of the distribution.
1743 void
1744 param(const param_type& __param)
1745 { _M_param = __param; }
1748 * @brief Returns the inclusive lower bound of the distribution range.
1750 result_type
1751 min() const
1752 { return this->a(); }
1755 * @brief Returns the inclusive upper bound of the distribution range.
1757 result_type
1758 max() const
1759 { return this->b(); }
1762 * @brief Generating functions.
1764 template<typename _UniformRandomNumberGenerator>
1765 result_type
1766 operator()(_UniformRandomNumberGenerator& __urng)
1767 { return this->operator()(__urng, _M_param); }
1769 template<typename _UniformRandomNumberGenerator>
1770 result_type
1771 operator()(_UniformRandomNumberGenerator& __urng,
1772 const param_type& __p);
1774 template<typename _ForwardIterator,
1775 typename _UniformRandomNumberGenerator>
1776 void
1777 __generate(_ForwardIterator __f, _ForwardIterator __t,
1778 _UniformRandomNumberGenerator& __urng)
1779 { this->__generate(__f, __t, __urng, _M_param); }
1781 template<typename _ForwardIterator,
1782 typename _UniformRandomNumberGenerator>
1783 void
1784 __generate(_ForwardIterator __f, _ForwardIterator __t,
1785 _UniformRandomNumberGenerator& __urng,
1786 const param_type& __p)
1787 { this->__generate_impl(__f, __t, __urng, __p); }
1789 template<typename _UniformRandomNumberGenerator>
1790 void
1791 __generate(result_type* __f, result_type* __t,
1792 _UniformRandomNumberGenerator& __urng,
1793 const param_type& __p)
1794 { this->__generate_impl(__f, __t, __urng, __p); }
1797 * @brief Return true if two uniform integer distributions have
1798 * the same parameters.
1800 friend bool
1801 operator==(const uniform_int_distribution& __d1,
1802 const uniform_int_distribution& __d2)
1803 { return __d1._M_param == __d2._M_param; }
1805 private:
1806 template<typename _ForwardIterator,
1807 typename _UniformRandomNumberGenerator>
1808 void
1809 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1810 _UniformRandomNumberGenerator& __urng,
1811 const param_type& __p);
1813 param_type _M_param;
1817 * @brief Return true if two uniform integer distributions have
1818 * different parameters.
1820 template<typename _IntType>
1821 inline bool
1822 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1823 const std::uniform_int_distribution<_IntType>& __d2)
1824 { return !(__d1 == __d2); }
1827 * @brief Inserts a %uniform_int_distribution random number
1828 * distribution @p __x into the output stream @p os.
1830 * @param __os An output stream.
1831 * @param __x A %uniform_int_distribution random number distribution.
1833 * @returns The output stream with the state of @p __x inserted or in
1834 * an error state.
1836 template<typename _IntType, typename _CharT, typename _Traits>
1837 std::basic_ostream<_CharT, _Traits>&
1838 operator<<(std::basic_ostream<_CharT, _Traits>&,
1839 const std::uniform_int_distribution<_IntType>&);
1842 * @brief Extracts a %uniform_int_distribution random number distribution
1843 * @p __x from the input stream @p __is.
1845 * @param __is An input stream.
1846 * @param __x A %uniform_int_distribution random number generator engine.
1848 * @returns The input stream with @p __x extracted or in an error state.
1850 template<typename _IntType, typename _CharT, typename _Traits>
1851 std::basic_istream<_CharT, _Traits>&
1852 operator>>(std::basic_istream<_CharT, _Traits>&,
1853 std::uniform_int_distribution<_IntType>&);
1857 * @brief Uniform continuous distribution for random numbers.
1859 * A continuous random distribution on the range [min, max) with equal
1860 * probability throughout the range. The URNG should be real-valued and
1861 * deliver number in the range [0, 1).
1863 template<typename _RealType = double>
1864 class uniform_real_distribution
1866 static_assert(std::is_floating_point<_RealType>::value,
1867 "template argument not a floating point type");
1869 public:
1870 /** The type of the range of the distribution. */
1871 typedef _RealType result_type;
1872 /** Parameter type. */
1873 struct param_type
1875 typedef uniform_real_distribution<_RealType> distribution_type;
1877 explicit
1878 param_type(_RealType __a = _RealType(0),
1879 _RealType __b = _RealType(1))
1880 : _M_a(__a), _M_b(__b)
1882 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1885 result_type
1886 a() const
1887 { return _M_a; }
1889 result_type
1890 b() const
1891 { return _M_b; }
1893 friend bool
1894 operator==(const param_type& __p1, const param_type& __p2)
1895 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1897 private:
1898 _RealType _M_a;
1899 _RealType _M_b;
1902 public:
1904 * @brief Constructs a uniform_real_distribution object.
1906 * @param __a [IN] The lower bound of the distribution.
1907 * @param __b [IN] The upper bound of the distribution.
1909 explicit
1910 uniform_real_distribution(_RealType __a = _RealType(0),
1911 _RealType __b = _RealType(1))
1912 : _M_param(__a, __b)
1915 explicit
1916 uniform_real_distribution(const param_type& __p)
1917 : _M_param(__p)
1921 * @brief Resets the distribution state.
1923 * Does nothing for the uniform real distribution.
1925 void
1926 reset() { }
1928 result_type
1929 a() const
1930 { return _M_param.a(); }
1932 result_type
1933 b() const
1934 { return _M_param.b(); }
1937 * @brief Returns the parameter set of the distribution.
1939 param_type
1940 param() const
1941 { return _M_param; }
1944 * @brief Sets the parameter set of the distribution.
1945 * @param __param The new parameter set of the distribution.
1947 void
1948 param(const param_type& __param)
1949 { _M_param = __param; }
1952 * @brief Returns the inclusive lower bound of the distribution range.
1954 result_type
1955 min() const
1956 { return this->a(); }
1959 * @brief Returns the inclusive upper bound of the distribution range.
1961 result_type
1962 max() const
1963 { return this->b(); }
1966 * @brief Generating functions.
1968 template<typename _UniformRandomNumberGenerator>
1969 result_type
1970 operator()(_UniformRandomNumberGenerator& __urng)
1971 { return this->operator()(__urng, _M_param); }
1973 template<typename _UniformRandomNumberGenerator>
1974 result_type
1975 operator()(_UniformRandomNumberGenerator& __urng,
1976 const param_type& __p)
1978 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1979 __aurng(__urng);
1980 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1983 template<typename _ForwardIterator,
1984 typename _UniformRandomNumberGenerator>
1985 void
1986 __generate(_ForwardIterator __f, _ForwardIterator __t,
1987 _UniformRandomNumberGenerator& __urng)
1988 { this->__generate(__f, __t, __urng, _M_param); }
1990 template<typename _ForwardIterator,
1991 typename _UniformRandomNumberGenerator>
1992 void
1993 __generate(_ForwardIterator __f, _ForwardIterator __t,
1994 _UniformRandomNumberGenerator& __urng,
1995 const param_type& __p)
1996 { this->__generate_impl(__f, __t, __urng, __p); }
1998 template<typename _UniformRandomNumberGenerator>
1999 void
2000 __generate(result_type* __f, result_type* __t,
2001 _UniformRandomNumberGenerator& __urng,
2002 const param_type& __p)
2003 { this->__generate_impl(__f, __t, __urng, __p); }
2006 * @brief Return true if two uniform real distributions have
2007 * the same parameters.
2009 friend bool
2010 operator==(const uniform_real_distribution& __d1,
2011 const uniform_real_distribution& __d2)
2012 { return __d1._M_param == __d2._M_param; }
2014 private:
2015 template<typename _ForwardIterator,
2016 typename _UniformRandomNumberGenerator>
2017 void
2018 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2019 _UniformRandomNumberGenerator& __urng,
2020 const param_type& __p);
2022 param_type _M_param;
2026 * @brief Return true if two uniform real distributions have
2027 * different parameters.
2029 template<typename _IntType>
2030 inline bool
2031 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
2032 const std::uniform_real_distribution<_IntType>& __d2)
2033 { return !(__d1 == __d2); }
2036 * @brief Inserts a %uniform_real_distribution random number
2037 * distribution @p __x into the output stream @p __os.
2039 * @param __os An output stream.
2040 * @param __x A %uniform_real_distribution random number distribution.
2042 * @returns The output stream with the state of @p __x inserted or in
2043 * an error state.
2045 template<typename _RealType, typename _CharT, typename _Traits>
2046 std::basic_ostream<_CharT, _Traits>&
2047 operator<<(std::basic_ostream<_CharT, _Traits>&,
2048 const std::uniform_real_distribution<_RealType>&);
2051 * @brief Extracts a %uniform_real_distribution random number distribution
2052 * @p __x from the input stream @p __is.
2054 * @param __is An input stream.
2055 * @param __x A %uniform_real_distribution random number generator engine.
2057 * @returns The input stream with @p __x extracted or in an error state.
2059 template<typename _RealType, typename _CharT, typename _Traits>
2060 std::basic_istream<_CharT, _Traits>&
2061 operator>>(std::basic_istream<_CharT, _Traits>&,
2062 std::uniform_real_distribution<_RealType>&);
2064 /* @} */ // group random_distributions_uniform
2067 * @addtogroup random_distributions_normal Normal Distributions
2068 * @ingroup random_distributions
2069 * @{
2073 * @brief A normal continuous distribution for random numbers.
2075 * The formula for the normal probability density function is
2076 * @f[
2077 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
2078 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
2079 * @f]
2081 template<typename _RealType = double>
2082 class normal_distribution
2084 static_assert(std::is_floating_point<_RealType>::value,
2085 "template argument not a floating point type");
2087 public:
2088 /** The type of the range of the distribution. */
2089 typedef _RealType result_type;
2090 /** Parameter type. */
2091 struct param_type
2093 typedef normal_distribution<_RealType> distribution_type;
2095 explicit
2096 param_type(_RealType __mean = _RealType(0),
2097 _RealType __stddev = _RealType(1))
2098 : _M_mean(__mean), _M_stddev(__stddev)
2100 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
2103 _RealType
2104 mean() const
2105 { return _M_mean; }
2107 _RealType
2108 stddev() const
2109 { return _M_stddev; }
2111 friend bool
2112 operator==(const param_type& __p1, const param_type& __p2)
2113 { return (__p1._M_mean == __p2._M_mean
2114 && __p1._M_stddev == __p2._M_stddev); }
2116 private:
2117 _RealType _M_mean;
2118 _RealType _M_stddev;
2121 public:
2123 * Constructs a normal distribution with parameters @f$mean@f$ and
2124 * standard deviation.
2126 explicit
2127 normal_distribution(result_type __mean = result_type(0),
2128 result_type __stddev = result_type(1))
2129 : _M_param(__mean, __stddev), _M_saved_available(false)
2132 explicit
2133 normal_distribution(const param_type& __p)
2134 : _M_param(__p), _M_saved_available(false)
2138 * @brief Resets the distribution state.
2140 void
2141 reset()
2142 { _M_saved_available = false; }
2145 * @brief Returns the mean of the distribution.
2147 _RealType
2148 mean() const
2149 { return _M_param.mean(); }
2152 * @brief Returns the standard deviation of the distribution.
2154 _RealType
2155 stddev() const
2156 { return _M_param.stddev(); }
2159 * @brief Returns the parameter set of the distribution.
2161 param_type
2162 param() const
2163 { return _M_param; }
2166 * @brief Sets the parameter set of the distribution.
2167 * @param __param The new parameter set of the distribution.
2169 void
2170 param(const param_type& __param)
2171 { _M_param = __param; }
2174 * @brief Returns the greatest lower bound value of the distribution.
2176 result_type
2177 min() const
2178 { return std::numeric_limits<result_type>::lowest(); }
2181 * @brief Returns the least upper bound value of the distribution.
2183 result_type
2184 max() const
2185 { return std::numeric_limits<result_type>::max(); }
2188 * @brief Generating functions.
2190 template<typename _UniformRandomNumberGenerator>
2191 result_type
2192 operator()(_UniformRandomNumberGenerator& __urng)
2193 { return this->operator()(__urng, _M_param); }
2195 template<typename _UniformRandomNumberGenerator>
2196 result_type
2197 operator()(_UniformRandomNumberGenerator& __urng,
2198 const param_type& __p);
2200 template<typename _ForwardIterator,
2201 typename _UniformRandomNumberGenerator>
2202 void
2203 __generate(_ForwardIterator __f, _ForwardIterator __t,
2204 _UniformRandomNumberGenerator& __urng)
2205 { this->__generate(__f, __t, __urng, _M_param); }
2207 template<typename _ForwardIterator,
2208 typename _UniformRandomNumberGenerator>
2209 void
2210 __generate(_ForwardIterator __f, _ForwardIterator __t,
2211 _UniformRandomNumberGenerator& __urng,
2212 const param_type& __p)
2213 { this->__generate_impl(__f, __t, __urng, __p); }
2215 template<typename _UniformRandomNumberGenerator>
2216 void
2217 __generate(result_type* __f, result_type* __t,
2218 _UniformRandomNumberGenerator& __urng,
2219 const param_type& __p)
2220 { this->__generate_impl(__f, __t, __urng, __p); }
2223 * @brief Return true if two normal distributions have
2224 * the same parameters and the sequences that would
2225 * be generated are equal.
2227 template<typename _RealType1>
2228 friend bool
2229 operator==(const std::normal_distribution<_RealType1>& __d1,
2230 const std::normal_distribution<_RealType1>& __d2);
2233 * @brief Inserts a %normal_distribution random number distribution
2234 * @p __x into the output stream @p __os.
2236 * @param __os An output stream.
2237 * @param __x A %normal_distribution random number distribution.
2239 * @returns The output stream with the state of @p __x inserted or in
2240 * an error state.
2242 template<typename _RealType1, typename _CharT, typename _Traits>
2243 friend std::basic_ostream<_CharT, _Traits>&
2244 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2245 const std::normal_distribution<_RealType1>& __x);
2248 * @brief Extracts a %normal_distribution random number distribution
2249 * @p __x from the input stream @p __is.
2251 * @param __is An input stream.
2252 * @param __x A %normal_distribution random number generator engine.
2254 * @returns The input stream with @p __x extracted or in an error
2255 * state.
2257 template<typename _RealType1, typename _CharT, typename _Traits>
2258 friend std::basic_istream<_CharT, _Traits>&
2259 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2260 std::normal_distribution<_RealType1>& __x);
2262 private:
2263 template<typename _ForwardIterator,
2264 typename _UniformRandomNumberGenerator>
2265 void
2266 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2267 _UniformRandomNumberGenerator& __urng,
2268 const param_type& __p);
2270 param_type _M_param;
2271 result_type _M_saved;
2272 bool _M_saved_available;
2276 * @brief Return true if two normal distributions are different.
2278 template<typename _RealType>
2279 inline bool
2280 operator!=(const std::normal_distribution<_RealType>& __d1,
2281 const std::normal_distribution<_RealType>& __d2)
2282 { return !(__d1 == __d2); }
2286 * @brief A lognormal_distribution random number distribution.
2288 * The formula for the normal probability mass function is
2289 * @f[
2290 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2291 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2292 * @f]
2294 template<typename _RealType = double>
2295 class lognormal_distribution
2297 static_assert(std::is_floating_point<_RealType>::value,
2298 "template argument not a floating point type");
2300 public:
2301 /** The type of the range of the distribution. */
2302 typedef _RealType result_type;
2303 /** Parameter type. */
2304 struct param_type
2306 typedef lognormal_distribution<_RealType> distribution_type;
2308 explicit
2309 param_type(_RealType __m = _RealType(0),
2310 _RealType __s = _RealType(1))
2311 : _M_m(__m), _M_s(__s)
2314 _RealType
2315 m() const
2316 { return _M_m; }
2318 _RealType
2319 s() const
2320 { return _M_s; }
2322 friend bool
2323 operator==(const param_type& __p1, const param_type& __p2)
2324 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2326 private:
2327 _RealType _M_m;
2328 _RealType _M_s;
2331 explicit
2332 lognormal_distribution(_RealType __m = _RealType(0),
2333 _RealType __s = _RealType(1))
2334 : _M_param(__m, __s), _M_nd()
2337 explicit
2338 lognormal_distribution(const param_type& __p)
2339 : _M_param(__p), _M_nd()
2343 * Resets the distribution state.
2345 void
2346 reset()
2347 { _M_nd.reset(); }
2352 _RealType
2353 m() const
2354 { return _M_param.m(); }
2356 _RealType
2357 s() const
2358 { return _M_param.s(); }
2361 * @brief Returns the parameter set of the distribution.
2363 param_type
2364 param() const
2365 { return _M_param; }
2368 * @brief Sets the parameter set of the distribution.
2369 * @param __param The new parameter set of the distribution.
2371 void
2372 param(const param_type& __param)
2373 { _M_param = __param; }
2376 * @brief Returns the greatest lower bound value of the distribution.
2378 result_type
2379 min() const
2380 { return result_type(0); }
2383 * @brief Returns the least upper bound value of the distribution.
2385 result_type
2386 max() const
2387 { return std::numeric_limits<result_type>::max(); }
2390 * @brief Generating functions.
2392 template<typename _UniformRandomNumberGenerator>
2393 result_type
2394 operator()(_UniformRandomNumberGenerator& __urng)
2395 { return this->operator()(__urng, _M_param); }
2397 template<typename _UniformRandomNumberGenerator>
2398 result_type
2399 operator()(_UniformRandomNumberGenerator& __urng,
2400 const param_type& __p)
2401 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2403 template<typename _ForwardIterator,
2404 typename _UniformRandomNumberGenerator>
2405 void
2406 __generate(_ForwardIterator __f, _ForwardIterator __t,
2407 _UniformRandomNumberGenerator& __urng)
2408 { this->__generate(__f, __t, __urng, _M_param); }
2410 template<typename _ForwardIterator,
2411 typename _UniformRandomNumberGenerator>
2412 void
2413 __generate(_ForwardIterator __f, _ForwardIterator __t,
2414 _UniformRandomNumberGenerator& __urng,
2415 const param_type& __p)
2416 { this->__generate_impl(__f, __t, __urng, __p); }
2418 template<typename _UniformRandomNumberGenerator>
2419 void
2420 __generate(result_type* __f, result_type* __t,
2421 _UniformRandomNumberGenerator& __urng,
2422 const param_type& __p)
2423 { this->__generate_impl(__f, __t, __urng, __p); }
2426 * @brief Return true if two lognormal distributions have
2427 * the same parameters and the sequences that would
2428 * be generated are equal.
2430 friend bool
2431 operator==(const lognormal_distribution& __d1,
2432 const lognormal_distribution& __d2)
2433 { return (__d1._M_param == __d2._M_param
2434 && __d1._M_nd == __d2._M_nd); }
2437 * @brief Inserts a %lognormal_distribution random number distribution
2438 * @p __x into the output stream @p __os.
2440 * @param __os An output stream.
2441 * @param __x A %lognormal_distribution random number distribution.
2443 * @returns The output stream with the state of @p __x inserted or in
2444 * an error state.
2446 template<typename _RealType1, typename _CharT, typename _Traits>
2447 friend std::basic_ostream<_CharT, _Traits>&
2448 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2449 const std::lognormal_distribution<_RealType1>& __x);
2452 * @brief Extracts a %lognormal_distribution random number distribution
2453 * @p __x from the input stream @p __is.
2455 * @param __is An input stream.
2456 * @param __x A %lognormal_distribution random number
2457 * generator engine.
2459 * @returns The input stream with @p __x extracted or in an error state.
2461 template<typename _RealType1, typename _CharT, typename _Traits>
2462 friend std::basic_istream<_CharT, _Traits>&
2463 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2464 std::lognormal_distribution<_RealType1>& __x);
2466 private:
2467 template<typename _ForwardIterator,
2468 typename _UniformRandomNumberGenerator>
2469 void
2470 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2471 _UniformRandomNumberGenerator& __urng,
2472 const param_type& __p);
2474 param_type _M_param;
2476 std::normal_distribution<result_type> _M_nd;
2480 * @brief Return true if two lognormal distributions are different.
2482 template<typename _RealType>
2483 inline bool
2484 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2485 const std::lognormal_distribution<_RealType>& __d2)
2486 { return !(__d1 == __d2); }
2490 * @brief A gamma continuous distribution for random numbers.
2492 * The formula for the gamma probability density function is:
2493 * @f[
2494 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2495 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2496 * @f]
2498 template<typename _RealType = double>
2499 class gamma_distribution
2501 static_assert(std::is_floating_point<_RealType>::value,
2502 "template argument not a floating point type");
2504 public:
2505 /** The type of the range of the distribution. */
2506 typedef _RealType result_type;
2507 /** Parameter type. */
2508 struct param_type
2510 typedef gamma_distribution<_RealType> distribution_type;
2511 friend class gamma_distribution<_RealType>;
2513 explicit
2514 param_type(_RealType __alpha_val = _RealType(1),
2515 _RealType __beta_val = _RealType(1))
2516 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2518 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2519 _M_initialize();
2522 _RealType
2523 alpha() const
2524 { return _M_alpha; }
2526 _RealType
2527 beta() const
2528 { return _M_beta; }
2530 friend bool
2531 operator==(const param_type& __p1, const param_type& __p2)
2532 { return (__p1._M_alpha == __p2._M_alpha
2533 && __p1._M_beta == __p2._M_beta); }
2535 private:
2536 void
2537 _M_initialize();
2539 _RealType _M_alpha;
2540 _RealType _M_beta;
2542 _RealType _M_malpha, _M_a2;
2545 public:
2547 * @brief Constructs a gamma distribution with parameters
2548 * @f$\alpha@f$ and @f$\beta@f$.
2550 explicit
2551 gamma_distribution(_RealType __alpha_val = _RealType(1),
2552 _RealType __beta_val = _RealType(1))
2553 : _M_param(__alpha_val, __beta_val), _M_nd()
2556 explicit
2557 gamma_distribution(const param_type& __p)
2558 : _M_param(__p), _M_nd()
2562 * @brief Resets the distribution state.
2564 void
2565 reset()
2566 { _M_nd.reset(); }
2569 * @brief Returns the @f$\alpha@f$ of the distribution.
2571 _RealType
2572 alpha() const
2573 { return _M_param.alpha(); }
2576 * @brief Returns the @f$\beta@f$ of the distribution.
2578 _RealType
2579 beta() const
2580 { return _M_param.beta(); }
2583 * @brief Returns the parameter set of the distribution.
2585 param_type
2586 param() const
2587 { return _M_param; }
2590 * @brief Sets the parameter set of the distribution.
2591 * @param __param The new parameter set of the distribution.
2593 void
2594 param(const param_type& __param)
2595 { _M_param = __param; }
2598 * @brief Returns the greatest lower bound value of the distribution.
2600 result_type
2601 min() const
2602 { return result_type(0); }
2605 * @brief Returns the least upper bound value of the distribution.
2607 result_type
2608 max() const
2609 { return std::numeric_limits<result_type>::max(); }
2612 * @brief Generating functions.
2614 template<typename _UniformRandomNumberGenerator>
2615 result_type
2616 operator()(_UniformRandomNumberGenerator& __urng)
2617 { return this->operator()(__urng, _M_param); }
2619 template<typename _UniformRandomNumberGenerator>
2620 result_type
2621 operator()(_UniformRandomNumberGenerator& __urng,
2622 const param_type& __p);
2624 template<typename _ForwardIterator,
2625 typename _UniformRandomNumberGenerator>
2626 void
2627 __generate(_ForwardIterator __f, _ForwardIterator __t,
2628 _UniformRandomNumberGenerator& __urng)
2629 { this->__generate(__f, __t, __urng, _M_param); }
2631 template<typename _ForwardIterator,
2632 typename _UniformRandomNumberGenerator>
2633 void
2634 __generate(_ForwardIterator __f, _ForwardIterator __t,
2635 _UniformRandomNumberGenerator& __urng,
2636 const param_type& __p)
2637 { this->__generate_impl(__f, __t, __urng, __p); }
2639 template<typename _UniformRandomNumberGenerator>
2640 void
2641 __generate(result_type* __f, result_type* __t,
2642 _UniformRandomNumberGenerator& __urng,
2643 const param_type& __p)
2644 { this->__generate_impl(__f, __t, __urng, __p); }
2647 * @brief Return true if two gamma distributions have the same
2648 * parameters and the sequences that would be generated
2649 * are equal.
2651 friend bool
2652 operator==(const gamma_distribution& __d1,
2653 const gamma_distribution& __d2)
2654 { return (__d1._M_param == __d2._M_param
2655 && __d1._M_nd == __d2._M_nd); }
2658 * @brief Inserts a %gamma_distribution random number distribution
2659 * @p __x into the output stream @p __os.
2661 * @param __os An output stream.
2662 * @param __x A %gamma_distribution random number distribution.
2664 * @returns The output stream with the state of @p __x inserted or in
2665 * an error state.
2667 template<typename _RealType1, typename _CharT, typename _Traits>
2668 friend std::basic_ostream<_CharT, _Traits>&
2669 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2670 const std::gamma_distribution<_RealType1>& __x);
2673 * @brief Extracts a %gamma_distribution random number distribution
2674 * @p __x from the input stream @p __is.
2676 * @param __is An input stream.
2677 * @param __x A %gamma_distribution random number generator engine.
2679 * @returns The input stream with @p __x extracted or in an error state.
2681 template<typename _RealType1, typename _CharT, typename _Traits>
2682 friend std::basic_istream<_CharT, _Traits>&
2683 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2684 std::gamma_distribution<_RealType1>& __x);
2686 private:
2687 template<typename _ForwardIterator,
2688 typename _UniformRandomNumberGenerator>
2689 void
2690 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2691 _UniformRandomNumberGenerator& __urng,
2692 const param_type& __p);
2694 param_type _M_param;
2696 std::normal_distribution<result_type> _M_nd;
2700 * @brief Return true if two gamma distributions are different.
2702 template<typename _RealType>
2703 inline bool
2704 operator!=(const std::gamma_distribution<_RealType>& __d1,
2705 const std::gamma_distribution<_RealType>& __d2)
2706 { return !(__d1 == __d2); }
2710 * @brief A chi_squared_distribution random number distribution.
2712 * The formula for the normal probability mass function is
2713 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2715 template<typename _RealType = double>
2716 class chi_squared_distribution
2718 static_assert(std::is_floating_point<_RealType>::value,
2719 "template argument not a floating point type");
2721 public:
2722 /** The type of the range of the distribution. */
2723 typedef _RealType result_type;
2724 /** Parameter type. */
2725 struct param_type
2727 typedef chi_squared_distribution<_RealType> distribution_type;
2729 explicit
2730 param_type(_RealType __n = _RealType(1))
2731 : _M_n(__n)
2734 _RealType
2735 n() const
2736 { return _M_n; }
2738 friend bool
2739 operator==(const param_type& __p1, const param_type& __p2)
2740 { return __p1._M_n == __p2._M_n; }
2742 private:
2743 _RealType _M_n;
2746 explicit
2747 chi_squared_distribution(_RealType __n = _RealType(1))
2748 : _M_param(__n), _M_gd(__n / 2)
2751 explicit
2752 chi_squared_distribution(const param_type& __p)
2753 : _M_param(__p), _M_gd(__p.n() / 2)
2757 * @brief Resets the distribution state.
2759 void
2760 reset()
2761 { _M_gd.reset(); }
2766 _RealType
2767 n() const
2768 { return _M_param.n(); }
2771 * @brief Returns the parameter set of the distribution.
2773 param_type
2774 param() const
2775 { return _M_param; }
2778 * @brief Sets the parameter set of the distribution.
2779 * @param __param The new parameter set of the distribution.
2781 void
2782 param(const param_type& __param)
2783 { _M_param = __param; }
2786 * @brief Returns the greatest lower bound value of the distribution.
2788 result_type
2789 min() const
2790 { return result_type(0); }
2793 * @brief Returns the least upper bound value of the distribution.
2795 result_type
2796 max() const
2797 { return std::numeric_limits<result_type>::max(); }
2800 * @brief Generating functions.
2802 template<typename _UniformRandomNumberGenerator>
2803 result_type
2804 operator()(_UniformRandomNumberGenerator& __urng)
2805 { return 2 * _M_gd(__urng); }
2807 template<typename _UniformRandomNumberGenerator>
2808 result_type
2809 operator()(_UniformRandomNumberGenerator& __urng,
2810 const param_type& __p)
2812 typedef typename std::gamma_distribution<result_type>::param_type
2813 param_type;
2814 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2817 template<typename _ForwardIterator,
2818 typename _UniformRandomNumberGenerator>
2819 void
2820 __generate(_ForwardIterator __f, _ForwardIterator __t,
2821 _UniformRandomNumberGenerator& __urng)
2822 { this->__generate_impl(__f, __t, __urng); }
2824 template<typename _ForwardIterator,
2825 typename _UniformRandomNumberGenerator>
2826 void
2827 __generate(_ForwardIterator __f, _ForwardIterator __t,
2828 _UniformRandomNumberGenerator& __urng,
2829 const param_type& __p)
2830 { typename std::gamma_distribution<result_type>::param_type
2831 __p2(__p.n() / 2);
2832 this->__generate_impl(__f, __t, __urng, __p2); }
2834 template<typename _UniformRandomNumberGenerator>
2835 void
2836 __generate(result_type* __f, result_type* __t,
2837 _UniformRandomNumberGenerator& __urng)
2838 { this->__generate_impl(__f, __t, __urng); }
2840 template<typename _UniformRandomNumberGenerator>
2841 void
2842 __generate(result_type* __f, result_type* __t,
2843 _UniformRandomNumberGenerator& __urng,
2844 const param_type& __p)
2845 { typename std::gamma_distribution<result_type>::param_type
2846 __p2(__p.n() / 2);
2847 this->__generate_impl(__f, __t, __urng, __p2); }
2850 * @brief Return true if two Chi-squared distributions have
2851 * the same parameters and the sequences that would be
2852 * generated are equal.
2854 friend bool
2855 operator==(const chi_squared_distribution& __d1,
2856 const chi_squared_distribution& __d2)
2857 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
2860 * @brief Inserts a %chi_squared_distribution random number distribution
2861 * @p __x into the output stream @p __os.
2863 * @param __os An output stream.
2864 * @param __x A %chi_squared_distribution random number distribution.
2866 * @returns The output stream with the state of @p __x inserted or in
2867 * an error state.
2869 template<typename _RealType1, typename _CharT, typename _Traits>
2870 friend std::basic_ostream<_CharT, _Traits>&
2871 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2872 const std::chi_squared_distribution<_RealType1>& __x);
2875 * @brief Extracts a %chi_squared_distribution random number distribution
2876 * @p __x from the input stream @p __is.
2878 * @param __is An input stream.
2879 * @param __x A %chi_squared_distribution random number
2880 * generator engine.
2882 * @returns The input stream with @p __x extracted or in an error state.
2884 template<typename _RealType1, typename _CharT, typename _Traits>
2885 friend std::basic_istream<_CharT, _Traits>&
2886 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2887 std::chi_squared_distribution<_RealType1>& __x);
2889 private:
2890 template<typename _ForwardIterator,
2891 typename _UniformRandomNumberGenerator>
2892 void
2893 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2894 _UniformRandomNumberGenerator& __urng);
2896 template<typename _ForwardIterator,
2897 typename _UniformRandomNumberGenerator>
2898 void
2899 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2900 _UniformRandomNumberGenerator& __urng,
2901 const typename
2902 std::gamma_distribution<result_type>::param_type& __p);
2904 param_type _M_param;
2906 std::gamma_distribution<result_type> _M_gd;
2910 * @brief Return true if two Chi-squared distributions are different.
2912 template<typename _RealType>
2913 inline bool
2914 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2915 const std::chi_squared_distribution<_RealType>& __d2)
2916 { return !(__d1 == __d2); }
2920 * @brief A cauchy_distribution random number distribution.
2922 * The formula for the normal probability mass function is
2923 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2925 template<typename _RealType = double>
2926 class cauchy_distribution
2928 static_assert(std::is_floating_point<_RealType>::value,
2929 "template argument not a floating point type");
2931 public:
2932 /** The type of the range of the distribution. */
2933 typedef _RealType result_type;
2934 /** Parameter type. */
2935 struct param_type
2937 typedef cauchy_distribution<_RealType> distribution_type;
2939 explicit
2940 param_type(_RealType __a = _RealType(0),
2941 _RealType __b = _RealType(1))
2942 : _M_a(__a), _M_b(__b)
2945 _RealType
2946 a() const
2947 { return _M_a; }
2949 _RealType
2950 b() const
2951 { return _M_b; }
2953 friend bool
2954 operator==(const param_type& __p1, const param_type& __p2)
2955 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2957 private:
2958 _RealType _M_a;
2959 _RealType _M_b;
2962 explicit
2963 cauchy_distribution(_RealType __a = _RealType(0),
2964 _RealType __b = _RealType(1))
2965 : _M_param(__a, __b)
2968 explicit
2969 cauchy_distribution(const param_type& __p)
2970 : _M_param(__p)
2974 * @brief Resets the distribution state.
2976 void
2977 reset()
2983 _RealType
2984 a() const
2985 { return _M_param.a(); }
2987 _RealType
2988 b() const
2989 { return _M_param.b(); }
2992 * @brief Returns the parameter set of the distribution.
2994 param_type
2995 param() const
2996 { return _M_param; }
2999 * @brief Sets the parameter set of the distribution.
3000 * @param __param The new parameter set of the distribution.
3002 void
3003 param(const param_type& __param)
3004 { _M_param = __param; }
3007 * @brief Returns the greatest lower bound value of the distribution.
3009 result_type
3010 min() const
3011 { return std::numeric_limits<result_type>::lowest(); }
3014 * @brief Returns the least upper bound value of the distribution.
3016 result_type
3017 max() const
3018 { return std::numeric_limits<result_type>::max(); }
3021 * @brief Generating functions.
3023 template<typename _UniformRandomNumberGenerator>
3024 result_type
3025 operator()(_UniformRandomNumberGenerator& __urng)
3026 { return this->operator()(__urng, _M_param); }
3028 template<typename _UniformRandomNumberGenerator>
3029 result_type
3030 operator()(_UniformRandomNumberGenerator& __urng,
3031 const param_type& __p);
3033 template<typename _ForwardIterator,
3034 typename _UniformRandomNumberGenerator>
3035 void
3036 __generate(_ForwardIterator __f, _ForwardIterator __t,
3037 _UniformRandomNumberGenerator& __urng)
3038 { this->__generate(__f, __t, __urng, _M_param); }
3040 template<typename _ForwardIterator,
3041 typename _UniformRandomNumberGenerator>
3042 void
3043 __generate(_ForwardIterator __f, _ForwardIterator __t,
3044 _UniformRandomNumberGenerator& __urng,
3045 const param_type& __p)
3046 { this->__generate_impl(__f, __t, __urng, __p); }
3048 template<typename _UniformRandomNumberGenerator>
3049 void
3050 __generate(result_type* __f, result_type* __t,
3051 _UniformRandomNumberGenerator& __urng,
3052 const param_type& __p)
3053 { this->__generate_impl(__f, __t, __urng, __p); }
3056 * @brief Return true if two Cauchy distributions have
3057 * the same parameters.
3059 friend bool
3060 operator==(const cauchy_distribution& __d1,
3061 const cauchy_distribution& __d2)
3062 { return __d1._M_param == __d2._M_param; }
3064 private:
3065 template<typename _ForwardIterator,
3066 typename _UniformRandomNumberGenerator>
3067 void
3068 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3069 _UniformRandomNumberGenerator& __urng,
3070 const param_type& __p);
3072 param_type _M_param;
3076 * @brief Return true if two Cauchy distributions have
3077 * different parameters.
3079 template<typename _RealType>
3080 inline bool
3081 operator!=(const std::cauchy_distribution<_RealType>& __d1,
3082 const std::cauchy_distribution<_RealType>& __d2)
3083 { return !(__d1 == __d2); }
3086 * @brief Inserts a %cauchy_distribution random number distribution
3087 * @p __x into the output stream @p __os.
3089 * @param __os An output stream.
3090 * @param __x A %cauchy_distribution random number distribution.
3092 * @returns The output stream with the state of @p __x inserted or in
3093 * an error state.
3095 template<typename _RealType, typename _CharT, typename _Traits>
3096 std::basic_ostream<_CharT, _Traits>&
3097 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3098 const std::cauchy_distribution<_RealType>& __x);
3101 * @brief Extracts a %cauchy_distribution random number distribution
3102 * @p __x from the input stream @p __is.
3104 * @param __is An input stream.
3105 * @param __x A %cauchy_distribution random number
3106 * generator engine.
3108 * @returns The input stream with @p __x extracted or in an error state.
3110 template<typename _RealType, typename _CharT, typename _Traits>
3111 std::basic_istream<_CharT, _Traits>&
3112 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3113 std::cauchy_distribution<_RealType>& __x);
3117 * @brief A fisher_f_distribution random number distribution.
3119 * The formula for the normal probability mass function is
3120 * @f[
3121 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3122 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3123 * (1 + \frac{mx}{n})^{-(m+n)/2}
3124 * @f]
3126 template<typename _RealType = double>
3127 class fisher_f_distribution
3129 static_assert(std::is_floating_point<_RealType>::value,
3130 "template argument not a floating point type");
3132 public:
3133 /** The type of the range of the distribution. */
3134 typedef _RealType result_type;
3135 /** Parameter type. */
3136 struct param_type
3138 typedef fisher_f_distribution<_RealType> distribution_type;
3140 explicit
3141 param_type(_RealType __m = _RealType(1),
3142 _RealType __n = _RealType(1))
3143 : _M_m(__m), _M_n(__n)
3146 _RealType
3147 m() const
3148 { return _M_m; }
3150 _RealType
3151 n() const
3152 { return _M_n; }
3154 friend bool
3155 operator==(const param_type& __p1, const param_type& __p2)
3156 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
3158 private:
3159 _RealType _M_m;
3160 _RealType _M_n;
3163 explicit
3164 fisher_f_distribution(_RealType __m = _RealType(1),
3165 _RealType __n = _RealType(1))
3166 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
3169 explicit
3170 fisher_f_distribution(const param_type& __p)
3171 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
3175 * @brief Resets the distribution state.
3177 void
3178 reset()
3180 _M_gd_x.reset();
3181 _M_gd_y.reset();
3187 _RealType
3188 m() const
3189 { return _M_param.m(); }
3191 _RealType
3192 n() const
3193 { return _M_param.n(); }
3196 * @brief Returns the parameter set of the distribution.
3198 param_type
3199 param() const
3200 { return _M_param; }
3203 * @brief Sets the parameter set of the distribution.
3204 * @param __param The new parameter set of the distribution.
3206 void
3207 param(const param_type& __param)
3208 { _M_param = __param; }
3211 * @brief Returns the greatest lower bound value of the distribution.
3213 result_type
3214 min() const
3215 { return result_type(0); }
3218 * @brief Returns the least upper bound value of the distribution.
3220 result_type
3221 max() const
3222 { return std::numeric_limits<result_type>::max(); }
3225 * @brief Generating functions.
3227 template<typename _UniformRandomNumberGenerator>
3228 result_type
3229 operator()(_UniformRandomNumberGenerator& __urng)
3230 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
3232 template<typename _UniformRandomNumberGenerator>
3233 result_type
3234 operator()(_UniformRandomNumberGenerator& __urng,
3235 const param_type& __p)
3237 typedef typename std::gamma_distribution<result_type>::param_type
3238 param_type;
3239 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
3240 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
3243 template<typename _ForwardIterator,
3244 typename _UniformRandomNumberGenerator>
3245 void
3246 __generate(_ForwardIterator __f, _ForwardIterator __t,
3247 _UniformRandomNumberGenerator& __urng)
3248 { this->__generate_impl(__f, __t, __urng); }
3250 template<typename _ForwardIterator,
3251 typename _UniformRandomNumberGenerator>
3252 void
3253 __generate(_ForwardIterator __f, _ForwardIterator __t,
3254 _UniformRandomNumberGenerator& __urng,
3255 const param_type& __p)
3256 { this->__generate_impl(__f, __t, __urng, __p); }
3258 template<typename _UniformRandomNumberGenerator>
3259 void
3260 __generate(result_type* __f, result_type* __t,
3261 _UniformRandomNumberGenerator& __urng)
3262 { this->__generate_impl(__f, __t, __urng); }
3264 template<typename _UniformRandomNumberGenerator>
3265 void
3266 __generate(result_type* __f, result_type* __t,
3267 _UniformRandomNumberGenerator& __urng,
3268 const param_type& __p)
3269 { this->__generate_impl(__f, __t, __urng, __p); }
3272 * @brief Return true if two Fisher f distributions have
3273 * the same parameters and the sequences that would
3274 * be generated are equal.
3276 friend bool
3277 operator==(const fisher_f_distribution& __d1,
3278 const fisher_f_distribution& __d2)
3279 { return (__d1._M_param == __d2._M_param
3280 && __d1._M_gd_x == __d2._M_gd_x
3281 && __d1._M_gd_y == __d2._M_gd_y); }
3284 * @brief Inserts a %fisher_f_distribution random number distribution
3285 * @p __x into the output stream @p __os.
3287 * @param __os An output stream.
3288 * @param __x A %fisher_f_distribution random number distribution.
3290 * @returns The output stream with the state of @p __x inserted or in
3291 * an error state.
3293 template<typename _RealType1, typename _CharT, typename _Traits>
3294 friend std::basic_ostream<_CharT, _Traits>&
3295 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3296 const std::fisher_f_distribution<_RealType1>& __x);
3299 * @brief Extracts a %fisher_f_distribution random number distribution
3300 * @p __x from the input stream @p __is.
3302 * @param __is An input stream.
3303 * @param __x A %fisher_f_distribution random number
3304 * generator engine.
3306 * @returns The input stream with @p __x extracted or in an error state.
3308 template<typename _RealType1, typename _CharT, typename _Traits>
3309 friend std::basic_istream<_CharT, _Traits>&
3310 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3311 std::fisher_f_distribution<_RealType1>& __x);
3313 private:
3314 template<typename _ForwardIterator,
3315 typename _UniformRandomNumberGenerator>
3316 void
3317 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3318 _UniformRandomNumberGenerator& __urng);
3320 template<typename _ForwardIterator,
3321 typename _UniformRandomNumberGenerator>
3322 void
3323 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3324 _UniformRandomNumberGenerator& __urng,
3325 const param_type& __p);
3327 param_type _M_param;
3329 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3333 * @brief Return true if two Fisher f distributions are different.
3335 template<typename _RealType>
3336 inline bool
3337 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3338 const std::fisher_f_distribution<_RealType>& __d2)
3339 { return !(__d1 == __d2); }
3342 * @brief A student_t_distribution random number distribution.
3344 * The formula for the normal probability mass function is:
3345 * @f[
3346 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3347 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3348 * @f]
3350 template<typename _RealType = double>
3351 class student_t_distribution
3353 static_assert(std::is_floating_point<_RealType>::value,
3354 "template argument not a floating point type");
3356 public:
3357 /** The type of the range of the distribution. */
3358 typedef _RealType result_type;
3359 /** Parameter type. */
3360 struct param_type
3362 typedef student_t_distribution<_RealType> distribution_type;
3364 explicit
3365 param_type(_RealType __n = _RealType(1))
3366 : _M_n(__n)
3369 _RealType
3370 n() const
3371 { return _M_n; }
3373 friend bool
3374 operator==(const param_type& __p1, const param_type& __p2)
3375 { return __p1._M_n == __p2._M_n; }
3377 private:
3378 _RealType _M_n;
3381 explicit
3382 student_t_distribution(_RealType __n = _RealType(1))
3383 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3386 explicit
3387 student_t_distribution(const param_type& __p)
3388 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3392 * @brief Resets the distribution state.
3394 void
3395 reset()
3397 _M_nd.reset();
3398 _M_gd.reset();
3404 _RealType
3405 n() const
3406 { return _M_param.n(); }
3409 * @brief Returns the parameter set of the distribution.
3411 param_type
3412 param() const
3413 { return _M_param; }
3416 * @brief Sets the parameter set of the distribution.
3417 * @param __param The new parameter set of the distribution.
3419 void
3420 param(const param_type& __param)
3421 { _M_param = __param; }
3424 * @brief Returns the greatest lower bound value of the distribution.
3426 result_type
3427 min() const
3428 { return std::numeric_limits<result_type>::lowest(); }
3431 * @brief Returns the least upper bound value of the distribution.
3433 result_type
3434 max() const
3435 { return std::numeric_limits<result_type>::max(); }
3438 * @brief Generating functions.
3440 template<typename _UniformRandomNumberGenerator>
3441 result_type
3442 operator()(_UniformRandomNumberGenerator& __urng)
3443 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3445 template<typename _UniformRandomNumberGenerator>
3446 result_type
3447 operator()(_UniformRandomNumberGenerator& __urng,
3448 const param_type& __p)
3450 typedef typename std::gamma_distribution<result_type>::param_type
3451 param_type;
3453 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3454 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3457 template<typename _ForwardIterator,
3458 typename _UniformRandomNumberGenerator>
3459 void
3460 __generate(_ForwardIterator __f, _ForwardIterator __t,
3461 _UniformRandomNumberGenerator& __urng)
3462 { this->__generate_impl(__f, __t, __urng); }
3464 template<typename _ForwardIterator,
3465 typename _UniformRandomNumberGenerator>
3466 void
3467 __generate(_ForwardIterator __f, _ForwardIterator __t,
3468 _UniformRandomNumberGenerator& __urng,
3469 const param_type& __p)
3470 { this->__generate_impl(__f, __t, __urng, __p); }
3472 template<typename _UniformRandomNumberGenerator>
3473 void
3474 __generate(result_type* __f, result_type* __t,
3475 _UniformRandomNumberGenerator& __urng)
3476 { this->__generate_impl(__f, __t, __urng); }
3478 template<typename _UniformRandomNumberGenerator>
3479 void
3480 __generate(result_type* __f, result_type* __t,
3481 _UniformRandomNumberGenerator& __urng,
3482 const param_type& __p)
3483 { this->__generate_impl(__f, __t, __urng, __p); }
3486 * @brief Return true if two Student t distributions have
3487 * the same parameters and the sequences that would
3488 * be generated are equal.
3490 friend bool
3491 operator==(const student_t_distribution& __d1,
3492 const student_t_distribution& __d2)
3493 { return (__d1._M_param == __d2._M_param
3494 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3497 * @brief Inserts a %student_t_distribution random number distribution
3498 * @p __x into the output stream @p __os.
3500 * @param __os An output stream.
3501 * @param __x A %student_t_distribution random number distribution.
3503 * @returns The output stream with the state of @p __x inserted or in
3504 * an error state.
3506 template<typename _RealType1, typename _CharT, typename _Traits>
3507 friend std::basic_ostream<_CharT, _Traits>&
3508 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3509 const std::student_t_distribution<_RealType1>& __x);
3512 * @brief Extracts a %student_t_distribution random number distribution
3513 * @p __x from the input stream @p __is.
3515 * @param __is An input stream.
3516 * @param __x A %student_t_distribution random number
3517 * generator engine.
3519 * @returns The input stream with @p __x extracted or in an error state.
3521 template<typename _RealType1, typename _CharT, typename _Traits>
3522 friend std::basic_istream<_CharT, _Traits>&
3523 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3524 std::student_t_distribution<_RealType1>& __x);
3526 private:
3527 template<typename _ForwardIterator,
3528 typename _UniformRandomNumberGenerator>
3529 void
3530 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3531 _UniformRandomNumberGenerator& __urng);
3532 template<typename _ForwardIterator,
3533 typename _UniformRandomNumberGenerator>
3534 void
3535 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3536 _UniformRandomNumberGenerator& __urng,
3537 const param_type& __p);
3539 param_type _M_param;
3541 std::normal_distribution<result_type> _M_nd;
3542 std::gamma_distribution<result_type> _M_gd;
3546 * @brief Return true if two Student t distributions are different.
3548 template<typename _RealType>
3549 inline bool
3550 operator!=(const std::student_t_distribution<_RealType>& __d1,
3551 const std::student_t_distribution<_RealType>& __d2)
3552 { return !(__d1 == __d2); }
3555 /* @} */ // group random_distributions_normal
3558 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3559 * @ingroup random_distributions
3560 * @{
3564 * @brief A Bernoulli random number distribution.
3566 * Generates a sequence of true and false values with likelihood @f$p@f$
3567 * that true will come up and @f$(1 - p)@f$ that false will appear.
3569 class bernoulli_distribution
3571 public:
3572 /** The type of the range of the distribution. */
3573 typedef bool result_type;
3574 /** Parameter type. */
3575 struct param_type
3577 typedef bernoulli_distribution distribution_type;
3579 explicit
3580 param_type(double __p = 0.5)
3581 : _M_p(__p)
3583 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3586 double
3587 p() const
3588 { return _M_p; }
3590 friend bool
3591 operator==(const param_type& __p1, const param_type& __p2)
3592 { return __p1._M_p == __p2._M_p; }
3594 private:
3595 double _M_p;
3598 public:
3600 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3602 * @param __p [IN] The likelihood of a true result being returned.
3603 * Must be in the interval @f$[0, 1]@f$.
3605 explicit
3606 bernoulli_distribution(double __p = 0.5)
3607 : _M_param(__p)
3610 explicit
3611 bernoulli_distribution(const param_type& __p)
3612 : _M_param(__p)
3616 * @brief Resets the distribution state.
3618 * Does nothing for a Bernoulli distribution.
3620 void
3621 reset() { }
3624 * @brief Returns the @p p parameter of the distribution.
3626 double
3627 p() const
3628 { return _M_param.p(); }
3631 * @brief Returns the parameter set of the distribution.
3633 param_type
3634 param() const
3635 { return _M_param; }
3638 * @brief Sets the parameter set of the distribution.
3639 * @param __param The new parameter set of the distribution.
3641 void
3642 param(const param_type& __param)
3643 { _M_param = __param; }
3646 * @brief Returns the greatest lower bound value of the distribution.
3648 result_type
3649 min() const
3650 { return std::numeric_limits<result_type>::min(); }
3653 * @brief Returns the least upper bound value of the distribution.
3655 result_type
3656 max() const
3657 { return std::numeric_limits<result_type>::max(); }
3660 * @brief Generating functions.
3662 template<typename _UniformRandomNumberGenerator>
3663 result_type
3664 operator()(_UniformRandomNumberGenerator& __urng)
3665 { return this->operator()(__urng, _M_param); }
3667 template<typename _UniformRandomNumberGenerator>
3668 result_type
3669 operator()(_UniformRandomNumberGenerator& __urng,
3670 const param_type& __p)
3672 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3673 __aurng(__urng);
3674 if ((__aurng() - __aurng.min())
3675 < __p.p() * (__aurng.max() - __aurng.min()))
3676 return true;
3677 return false;
3680 template<typename _ForwardIterator,
3681 typename _UniformRandomNumberGenerator>
3682 void
3683 __generate(_ForwardIterator __f, _ForwardIterator __t,
3684 _UniformRandomNumberGenerator& __urng)
3685 { this->__generate(__f, __t, __urng, _M_param); }
3687 template<typename _ForwardIterator,
3688 typename _UniformRandomNumberGenerator>
3689 void
3690 __generate(_ForwardIterator __f, _ForwardIterator __t,
3691 _UniformRandomNumberGenerator& __urng, const param_type& __p)
3692 { this->__generate_impl(__f, __t, __urng, __p); }
3694 template<typename _UniformRandomNumberGenerator>
3695 void
3696 __generate(result_type* __f, result_type* __t,
3697 _UniformRandomNumberGenerator& __urng,
3698 const param_type& __p)
3699 { this->__generate_impl(__f, __t, __urng, __p); }
3702 * @brief Return true if two Bernoulli distributions have
3703 * the same parameters.
3705 friend bool
3706 operator==(const bernoulli_distribution& __d1,
3707 const bernoulli_distribution& __d2)
3708 { return __d1._M_param == __d2._M_param; }
3710 private:
3711 template<typename _ForwardIterator,
3712 typename _UniformRandomNumberGenerator>
3713 void
3714 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3715 _UniformRandomNumberGenerator& __urng,
3716 const param_type& __p);
3718 param_type _M_param;
3722 * @brief Return true if two Bernoulli distributions have
3723 * different parameters.
3725 inline bool
3726 operator!=(const std::bernoulli_distribution& __d1,
3727 const std::bernoulli_distribution& __d2)
3728 { return !(__d1 == __d2); }
3731 * @brief Inserts a %bernoulli_distribution random number distribution
3732 * @p __x into the output stream @p __os.
3734 * @param __os An output stream.
3735 * @param __x A %bernoulli_distribution random number distribution.
3737 * @returns The output stream with the state of @p __x inserted or in
3738 * an error state.
3740 template<typename _CharT, typename _Traits>
3741 std::basic_ostream<_CharT, _Traits>&
3742 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3743 const std::bernoulli_distribution& __x);
3746 * @brief Extracts a %bernoulli_distribution random number distribution
3747 * @p __x from the input stream @p __is.
3749 * @param __is An input stream.
3750 * @param __x A %bernoulli_distribution random number generator engine.
3752 * @returns The input stream with @p __x extracted or in an error state.
3754 template<typename _CharT, typename _Traits>
3755 std::basic_istream<_CharT, _Traits>&
3756 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3757 std::bernoulli_distribution& __x)
3759 double __p;
3760 __is >> __p;
3761 __x.param(bernoulli_distribution::param_type(__p));
3762 return __is;
3767 * @brief A discrete binomial random number distribution.
3769 * The formula for the binomial probability density function is
3770 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3771 * and @f$p@f$ are the parameters of the distribution.
3773 template<typename _IntType = int>
3774 class binomial_distribution
3776 static_assert(std::is_integral<_IntType>::value,
3777 "template argument not an integral type");
3779 public:
3780 /** The type of the range of the distribution. */
3781 typedef _IntType result_type;
3782 /** Parameter type. */
3783 struct param_type
3785 typedef binomial_distribution<_IntType> distribution_type;
3786 friend class binomial_distribution<_IntType>;
3788 explicit
3789 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3790 : _M_t(__t), _M_p(__p)
3792 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3793 && (_M_p >= 0.0)
3794 && (_M_p <= 1.0));
3795 _M_initialize();
3798 _IntType
3799 t() const
3800 { return _M_t; }
3802 double
3803 p() const
3804 { return _M_p; }
3806 friend bool
3807 operator==(const param_type& __p1, const param_type& __p2)
3808 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3810 private:
3811 void
3812 _M_initialize();
3814 _IntType _M_t;
3815 double _M_p;
3817 double _M_q;
3818 #if _GLIBCXX_USE_C99_MATH_TR1
3819 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3820 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3821 #endif
3822 bool _M_easy;
3825 // constructors and member function
3826 explicit
3827 binomial_distribution(_IntType __t = _IntType(1),
3828 double __p = 0.5)
3829 : _M_param(__t, __p), _M_nd()
3832 explicit
3833 binomial_distribution(const param_type& __p)
3834 : _M_param(__p), _M_nd()
3838 * @brief Resets the distribution state.
3840 void
3841 reset()
3842 { _M_nd.reset(); }
3845 * @brief Returns the distribution @p t parameter.
3847 _IntType
3848 t() const
3849 { return _M_param.t(); }
3852 * @brief Returns the distribution @p p parameter.
3854 double
3855 p() const
3856 { return _M_param.p(); }
3859 * @brief Returns the parameter set of the distribution.
3861 param_type
3862 param() const
3863 { return _M_param; }
3866 * @brief Sets the parameter set of the distribution.
3867 * @param __param The new parameter set of the distribution.
3869 void
3870 param(const param_type& __param)
3871 { _M_param = __param; }
3874 * @brief Returns the greatest lower bound value of the distribution.
3876 result_type
3877 min() const
3878 { return 0; }
3881 * @brief Returns the least upper bound value of the distribution.
3883 result_type
3884 max() const
3885 { return _M_param.t(); }
3888 * @brief Generating functions.
3890 template<typename _UniformRandomNumberGenerator>
3891 result_type
3892 operator()(_UniformRandomNumberGenerator& __urng)
3893 { return this->operator()(__urng, _M_param); }
3895 template<typename _UniformRandomNumberGenerator>
3896 result_type
3897 operator()(_UniformRandomNumberGenerator& __urng,
3898 const param_type& __p);
3900 template<typename _ForwardIterator,
3901 typename _UniformRandomNumberGenerator>
3902 void
3903 __generate(_ForwardIterator __f, _ForwardIterator __t,
3904 _UniformRandomNumberGenerator& __urng)
3905 { this->__generate(__f, __t, __urng, _M_param); }
3907 template<typename _ForwardIterator,
3908 typename _UniformRandomNumberGenerator>
3909 void
3910 __generate(_ForwardIterator __f, _ForwardIterator __t,
3911 _UniformRandomNumberGenerator& __urng,
3912 const param_type& __p)
3913 { this->__generate_impl(__f, __t, __urng, __p); }
3915 template<typename _UniformRandomNumberGenerator>
3916 void
3917 __generate(result_type* __f, result_type* __t,
3918 _UniformRandomNumberGenerator& __urng,
3919 const param_type& __p)
3920 { this->__generate_impl(__f, __t, __urng, __p); }
3923 * @brief Return true if two binomial distributions have
3924 * the same parameters and the sequences that would
3925 * be generated are equal.
3927 friend bool
3928 operator==(const binomial_distribution& __d1,
3929 const binomial_distribution& __d2)
3930 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3931 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
3932 #else
3933 { return __d1._M_param == __d2._M_param; }
3934 #endif
3937 * @brief Inserts a %binomial_distribution random number distribution
3938 * @p __x into the output stream @p __os.
3940 * @param __os An output stream.
3941 * @param __x A %binomial_distribution random number distribution.
3943 * @returns The output stream with the state of @p __x inserted or in
3944 * an error state.
3946 template<typename _IntType1,
3947 typename _CharT, typename _Traits>
3948 friend std::basic_ostream<_CharT, _Traits>&
3949 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3950 const std::binomial_distribution<_IntType1>& __x);
3953 * @brief Extracts a %binomial_distribution random number distribution
3954 * @p __x from the input stream @p __is.
3956 * @param __is An input stream.
3957 * @param __x A %binomial_distribution random number generator engine.
3959 * @returns The input stream with @p __x extracted or in an error
3960 * state.
3962 template<typename _IntType1,
3963 typename _CharT, typename _Traits>
3964 friend std::basic_istream<_CharT, _Traits>&
3965 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3966 std::binomial_distribution<_IntType1>& __x);
3968 private:
3969 template<typename _ForwardIterator,
3970 typename _UniformRandomNumberGenerator>
3971 void
3972 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3973 _UniformRandomNumberGenerator& __urng,
3974 const param_type& __p);
3976 template<typename _UniformRandomNumberGenerator>
3977 result_type
3978 _M_waiting(_UniformRandomNumberGenerator& __urng,
3979 _IntType __t, double __q);
3981 param_type _M_param;
3983 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3984 std::normal_distribution<double> _M_nd;
3988 * @brief Return true if two binomial distributions are different.
3990 template<typename _IntType>
3991 inline bool
3992 operator!=(const std::binomial_distribution<_IntType>& __d1,
3993 const std::binomial_distribution<_IntType>& __d2)
3994 { return !(__d1 == __d2); }
3998 * @brief A discrete geometric random number distribution.
4000 * The formula for the geometric probability density function is
4001 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
4002 * distribution.
4004 template<typename _IntType = int>
4005 class geometric_distribution
4007 static_assert(std::is_integral<_IntType>::value,
4008 "template argument not an integral type");
4010 public:
4011 /** The type of the range of the distribution. */
4012 typedef _IntType result_type;
4013 /** Parameter type. */
4014 struct param_type
4016 typedef geometric_distribution<_IntType> distribution_type;
4017 friend class geometric_distribution<_IntType>;
4019 explicit
4020 param_type(double __p = 0.5)
4021 : _M_p(__p)
4023 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
4024 _M_initialize();
4027 double
4028 p() const
4029 { return _M_p; }
4031 friend bool
4032 operator==(const param_type& __p1, const param_type& __p2)
4033 { return __p1._M_p == __p2._M_p; }
4035 private:
4036 void
4037 _M_initialize()
4038 { _M_log_1_p = std::log(1.0 - _M_p); }
4040 double _M_p;
4042 double _M_log_1_p;
4045 // constructors and member function
4046 explicit
4047 geometric_distribution(double __p = 0.5)
4048 : _M_param(__p)
4051 explicit
4052 geometric_distribution(const param_type& __p)
4053 : _M_param(__p)
4057 * @brief Resets the distribution state.
4059 * Does nothing for the geometric distribution.
4061 void
4062 reset() { }
4065 * @brief Returns the distribution parameter @p p.
4067 double
4068 p() const
4069 { return _M_param.p(); }
4072 * @brief Returns the parameter set of the distribution.
4074 param_type
4075 param() const
4076 { return _M_param; }
4079 * @brief Sets the parameter set of the distribution.
4080 * @param __param The new parameter set of the distribution.
4082 void
4083 param(const param_type& __param)
4084 { _M_param = __param; }
4087 * @brief Returns the greatest lower bound value of the distribution.
4089 result_type
4090 min() const
4091 { return 0; }
4094 * @brief Returns the least upper bound value of the distribution.
4096 result_type
4097 max() const
4098 { return std::numeric_limits<result_type>::max(); }
4101 * @brief Generating functions.
4103 template<typename _UniformRandomNumberGenerator>
4104 result_type
4105 operator()(_UniformRandomNumberGenerator& __urng)
4106 { return this->operator()(__urng, _M_param); }
4108 template<typename _UniformRandomNumberGenerator>
4109 result_type
4110 operator()(_UniformRandomNumberGenerator& __urng,
4111 const param_type& __p);
4113 template<typename _ForwardIterator,
4114 typename _UniformRandomNumberGenerator>
4115 void
4116 __generate(_ForwardIterator __f, _ForwardIterator __t,
4117 _UniformRandomNumberGenerator& __urng)
4118 { this->__generate(__f, __t, __urng, _M_param); }
4120 template<typename _ForwardIterator,
4121 typename _UniformRandomNumberGenerator>
4122 void
4123 __generate(_ForwardIterator __f, _ForwardIterator __t,
4124 _UniformRandomNumberGenerator& __urng,
4125 const param_type& __p)
4126 { this->__generate_impl(__f, __t, __urng, __p); }
4128 template<typename _UniformRandomNumberGenerator>
4129 void
4130 __generate(result_type* __f, result_type* __t,
4131 _UniformRandomNumberGenerator& __urng,
4132 const param_type& __p)
4133 { this->__generate_impl(__f, __t, __urng, __p); }
4136 * @brief Return true if two geometric distributions have
4137 * the same parameters.
4139 friend bool
4140 operator==(const geometric_distribution& __d1,
4141 const geometric_distribution& __d2)
4142 { return __d1._M_param == __d2._M_param; }
4144 private:
4145 template<typename _ForwardIterator,
4146 typename _UniformRandomNumberGenerator>
4147 void
4148 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4149 _UniformRandomNumberGenerator& __urng,
4150 const param_type& __p);
4152 param_type _M_param;
4156 * @brief Return true if two geometric distributions have
4157 * different parameters.
4159 template<typename _IntType>
4160 inline bool
4161 operator!=(const std::geometric_distribution<_IntType>& __d1,
4162 const std::geometric_distribution<_IntType>& __d2)
4163 { return !(__d1 == __d2); }
4166 * @brief Inserts a %geometric_distribution random number distribution
4167 * @p __x into the output stream @p __os.
4169 * @param __os An output stream.
4170 * @param __x A %geometric_distribution random number distribution.
4172 * @returns The output stream with the state of @p __x inserted or in
4173 * an error state.
4175 template<typename _IntType,
4176 typename _CharT, typename _Traits>
4177 std::basic_ostream<_CharT, _Traits>&
4178 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4179 const std::geometric_distribution<_IntType>& __x);
4182 * @brief Extracts a %geometric_distribution random number distribution
4183 * @p __x from the input stream @p __is.
4185 * @param __is An input stream.
4186 * @param __x A %geometric_distribution random number generator engine.
4188 * @returns The input stream with @p __x extracted or in an error state.
4190 template<typename _IntType,
4191 typename _CharT, typename _Traits>
4192 std::basic_istream<_CharT, _Traits>&
4193 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4194 std::geometric_distribution<_IntType>& __x);
4198 * @brief A negative_binomial_distribution random number distribution.
4200 * The formula for the negative binomial probability mass function is
4201 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4202 * and @f$p@f$ are the parameters of the distribution.
4204 template<typename _IntType = int>
4205 class negative_binomial_distribution
4207 static_assert(std::is_integral<_IntType>::value,
4208 "template argument not an integral type");
4210 public:
4211 /** The type of the range of the distribution. */
4212 typedef _IntType result_type;
4213 /** Parameter type. */
4214 struct param_type
4216 typedef negative_binomial_distribution<_IntType> distribution_type;
4218 explicit
4219 param_type(_IntType __k = 1, double __p = 0.5)
4220 : _M_k(__k), _M_p(__p)
4222 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
4225 _IntType
4226 k() const
4227 { return _M_k; }
4229 double
4230 p() const
4231 { return _M_p; }
4233 friend bool
4234 operator==(const param_type& __p1, const param_type& __p2)
4235 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
4237 private:
4238 _IntType _M_k;
4239 double _M_p;
4242 explicit
4243 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
4244 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
4247 explicit
4248 negative_binomial_distribution(const param_type& __p)
4249 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
4253 * @brief Resets the distribution state.
4255 void
4256 reset()
4257 { _M_gd.reset(); }
4260 * @brief Return the @f$k@f$ parameter of the distribution.
4262 _IntType
4263 k() const
4264 { return _M_param.k(); }
4267 * @brief Return the @f$p@f$ parameter of the distribution.
4269 double
4270 p() const
4271 { return _M_param.p(); }
4274 * @brief Returns the parameter set of the distribution.
4276 param_type
4277 param() const
4278 { return _M_param; }
4281 * @brief Sets the parameter set of the distribution.
4282 * @param __param The new parameter set of the distribution.
4284 void
4285 param(const param_type& __param)
4286 { _M_param = __param; }
4289 * @brief Returns the greatest lower bound value of the distribution.
4291 result_type
4292 min() const
4293 { return result_type(0); }
4296 * @brief Returns the least upper bound value of the distribution.
4298 result_type
4299 max() const
4300 { return std::numeric_limits<result_type>::max(); }
4303 * @brief Generating functions.
4305 template<typename _UniformRandomNumberGenerator>
4306 result_type
4307 operator()(_UniformRandomNumberGenerator& __urng);
4309 template<typename _UniformRandomNumberGenerator>
4310 result_type
4311 operator()(_UniformRandomNumberGenerator& __urng,
4312 const param_type& __p);
4314 template<typename _ForwardIterator,
4315 typename _UniformRandomNumberGenerator>
4316 void
4317 __generate(_ForwardIterator __f, _ForwardIterator __t,
4318 _UniformRandomNumberGenerator& __urng)
4319 { this->__generate_impl(__f, __t, __urng); }
4321 template<typename _ForwardIterator,
4322 typename _UniformRandomNumberGenerator>
4323 void
4324 __generate(_ForwardIterator __f, _ForwardIterator __t,
4325 _UniformRandomNumberGenerator& __urng,
4326 const param_type& __p)
4327 { this->__generate_impl(__f, __t, __urng, __p); }
4329 template<typename _UniformRandomNumberGenerator>
4330 void
4331 __generate(result_type* __f, result_type* __t,
4332 _UniformRandomNumberGenerator& __urng)
4333 { this->__generate_impl(__f, __t, __urng); }
4335 template<typename _UniformRandomNumberGenerator>
4336 void
4337 __generate(result_type* __f, result_type* __t,
4338 _UniformRandomNumberGenerator& __urng,
4339 const param_type& __p)
4340 { this->__generate_impl(__f, __t, __urng, __p); }
4343 * @brief Return true if two negative binomial distributions have
4344 * the same parameters and the sequences that would be
4345 * generated are equal.
4347 friend bool
4348 operator==(const negative_binomial_distribution& __d1,
4349 const negative_binomial_distribution& __d2)
4350 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
4353 * @brief Inserts a %negative_binomial_distribution random
4354 * number distribution @p __x into the output stream @p __os.
4356 * @param __os An output stream.
4357 * @param __x A %negative_binomial_distribution random number
4358 * distribution.
4360 * @returns The output stream with the state of @p __x inserted or in
4361 * an error state.
4363 template<typename _IntType1, typename _CharT, typename _Traits>
4364 friend std::basic_ostream<_CharT, _Traits>&
4365 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4366 const std::negative_binomial_distribution<_IntType1>& __x);
4369 * @brief Extracts a %negative_binomial_distribution random number
4370 * distribution @p __x from the input stream @p __is.
4372 * @param __is An input stream.
4373 * @param __x A %negative_binomial_distribution random number
4374 * generator engine.
4376 * @returns The input stream with @p __x extracted or in an error state.
4378 template<typename _IntType1, typename _CharT, typename _Traits>
4379 friend std::basic_istream<_CharT, _Traits>&
4380 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4381 std::negative_binomial_distribution<_IntType1>& __x);
4383 private:
4384 template<typename _ForwardIterator,
4385 typename _UniformRandomNumberGenerator>
4386 void
4387 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4388 _UniformRandomNumberGenerator& __urng);
4389 template<typename _ForwardIterator,
4390 typename _UniformRandomNumberGenerator>
4391 void
4392 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4393 _UniformRandomNumberGenerator& __urng,
4394 const param_type& __p);
4396 param_type _M_param;
4398 std::gamma_distribution<double> _M_gd;
4402 * @brief Return true if two negative binomial distributions are different.
4404 template<typename _IntType>
4405 inline bool
4406 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
4407 const std::negative_binomial_distribution<_IntType>& __d2)
4408 { return !(__d1 == __d2); }
4411 /* @} */ // group random_distributions_bernoulli
4414 * @addtogroup random_distributions_poisson Poisson Distributions
4415 * @ingroup random_distributions
4416 * @{
4420 * @brief A discrete Poisson random number distribution.
4422 * The formula for the Poisson probability density function is
4423 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4424 * parameter of the distribution.
4426 template<typename _IntType = int>
4427 class poisson_distribution
4429 static_assert(std::is_integral<_IntType>::value,
4430 "template argument not an integral type");
4432 public:
4433 /** The type of the range of the distribution. */
4434 typedef _IntType result_type;
4435 /** Parameter type. */
4436 struct param_type
4438 typedef poisson_distribution<_IntType> distribution_type;
4439 friend class poisson_distribution<_IntType>;
4441 explicit
4442 param_type(double __mean = 1.0)
4443 : _M_mean(__mean)
4445 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
4446 _M_initialize();
4449 double
4450 mean() const
4451 { return _M_mean; }
4453 friend bool
4454 operator==(const param_type& __p1, const param_type& __p2)
4455 { return __p1._M_mean == __p2._M_mean; }
4457 private:
4458 // Hosts either log(mean) or the threshold of the simple method.
4459 void
4460 _M_initialize();
4462 double _M_mean;
4464 double _M_lm_thr;
4465 #if _GLIBCXX_USE_C99_MATH_TR1
4466 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4467 #endif
4470 // constructors and member function
4471 explicit
4472 poisson_distribution(double __mean = 1.0)
4473 : _M_param(__mean), _M_nd()
4476 explicit
4477 poisson_distribution(const param_type& __p)
4478 : _M_param(__p), _M_nd()
4482 * @brief Resets the distribution state.
4484 void
4485 reset()
4486 { _M_nd.reset(); }
4489 * @brief Returns the distribution parameter @p mean.
4491 double
4492 mean() const
4493 { return _M_param.mean(); }
4496 * @brief Returns the parameter set of the distribution.
4498 param_type
4499 param() const
4500 { return _M_param; }
4503 * @brief Sets the parameter set of the distribution.
4504 * @param __param The new parameter set of the distribution.
4506 void
4507 param(const param_type& __param)
4508 { _M_param = __param; }
4511 * @brief Returns the greatest lower bound value of the distribution.
4513 result_type
4514 min() const
4515 { return 0; }
4518 * @brief Returns the least upper bound value of the distribution.
4520 result_type
4521 max() const
4522 { return std::numeric_limits<result_type>::max(); }
4525 * @brief Generating functions.
4527 template<typename _UniformRandomNumberGenerator>
4528 result_type
4529 operator()(_UniformRandomNumberGenerator& __urng)
4530 { return this->operator()(__urng, _M_param); }
4532 template<typename _UniformRandomNumberGenerator>
4533 result_type
4534 operator()(_UniformRandomNumberGenerator& __urng,
4535 const param_type& __p);
4537 template<typename _ForwardIterator,
4538 typename _UniformRandomNumberGenerator>
4539 void
4540 __generate(_ForwardIterator __f, _ForwardIterator __t,
4541 _UniformRandomNumberGenerator& __urng)
4542 { this->__generate(__f, __t, __urng, _M_param); }
4544 template<typename _ForwardIterator,
4545 typename _UniformRandomNumberGenerator>
4546 void
4547 __generate(_ForwardIterator __f, _ForwardIterator __t,
4548 _UniformRandomNumberGenerator& __urng,
4549 const param_type& __p)
4550 { this->__generate_impl(__f, __t, __urng, __p); }
4552 template<typename _UniformRandomNumberGenerator>
4553 void
4554 __generate(result_type* __f, result_type* __t,
4555 _UniformRandomNumberGenerator& __urng,
4556 const param_type& __p)
4557 { this->__generate_impl(__f, __t, __urng, __p); }
4560 * @brief Return true if two Poisson distributions have the same
4561 * parameters and the sequences that would be generated
4562 * are equal.
4564 friend bool
4565 operator==(const poisson_distribution& __d1,
4566 const poisson_distribution& __d2)
4567 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4568 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4569 #else
4570 { return __d1._M_param == __d2._M_param; }
4571 #endif
4574 * @brief Inserts a %poisson_distribution random number distribution
4575 * @p __x into the output stream @p __os.
4577 * @param __os An output stream.
4578 * @param __x A %poisson_distribution random number distribution.
4580 * @returns The output stream with the state of @p __x inserted or in
4581 * an error state.
4583 template<typename _IntType1, typename _CharT, typename _Traits>
4584 friend std::basic_ostream<_CharT, _Traits>&
4585 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4586 const std::poisson_distribution<_IntType1>& __x);
4589 * @brief Extracts a %poisson_distribution random number distribution
4590 * @p __x from the input stream @p __is.
4592 * @param __is An input stream.
4593 * @param __x A %poisson_distribution random number generator engine.
4595 * @returns The input stream with @p __x extracted or in an error
4596 * state.
4598 template<typename _IntType1, typename _CharT, typename _Traits>
4599 friend std::basic_istream<_CharT, _Traits>&
4600 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4601 std::poisson_distribution<_IntType1>& __x);
4603 private:
4604 template<typename _ForwardIterator,
4605 typename _UniformRandomNumberGenerator>
4606 void
4607 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4608 _UniformRandomNumberGenerator& __urng,
4609 const param_type& __p);
4611 param_type _M_param;
4613 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4614 std::normal_distribution<double> _M_nd;
4618 * @brief Return true if two Poisson distributions are different.
4620 template<typename _IntType>
4621 inline bool
4622 operator!=(const std::poisson_distribution<_IntType>& __d1,
4623 const std::poisson_distribution<_IntType>& __d2)
4624 { return !(__d1 == __d2); }
4628 * @brief An exponential continuous distribution for random numbers.
4630 * The formula for the exponential probability density function is
4631 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4633 * <table border=1 cellpadding=10 cellspacing=0>
4634 * <caption align=top>Distribution Statistics</caption>
4635 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4636 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4637 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4638 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4639 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4640 * </table>
4642 template<typename _RealType = double>
4643 class exponential_distribution
4645 static_assert(std::is_floating_point<_RealType>::value,
4646 "template argument not a floating point type");
4648 public:
4649 /** The type of the range of the distribution. */
4650 typedef _RealType result_type;
4651 /** Parameter type. */
4652 struct param_type
4654 typedef exponential_distribution<_RealType> distribution_type;
4656 explicit
4657 param_type(_RealType __lambda = _RealType(1))
4658 : _M_lambda(__lambda)
4660 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4663 _RealType
4664 lambda() const
4665 { return _M_lambda; }
4667 friend bool
4668 operator==(const param_type& __p1, const param_type& __p2)
4669 { return __p1._M_lambda == __p2._M_lambda; }
4671 private:
4672 _RealType _M_lambda;
4675 public:
4677 * @brief Constructs an exponential distribution with inverse scale
4678 * parameter @f$\lambda@f$.
4680 explicit
4681 exponential_distribution(const result_type& __lambda = result_type(1))
4682 : _M_param(__lambda)
4685 explicit
4686 exponential_distribution(const param_type& __p)
4687 : _M_param(__p)
4691 * @brief Resets the distribution state.
4693 * Has no effect on exponential distributions.
4695 void
4696 reset() { }
4699 * @brief Returns the inverse scale parameter of the distribution.
4701 _RealType
4702 lambda() const
4703 { return _M_param.lambda(); }
4706 * @brief Returns the parameter set of the distribution.
4708 param_type
4709 param() const
4710 { return _M_param; }
4713 * @brief Sets the parameter set of the distribution.
4714 * @param __param The new parameter set of the distribution.
4716 void
4717 param(const param_type& __param)
4718 { _M_param = __param; }
4721 * @brief Returns the greatest lower bound value of the distribution.
4723 result_type
4724 min() const
4725 { return result_type(0); }
4728 * @brief Returns the least upper bound value of the distribution.
4730 result_type
4731 max() const
4732 { return std::numeric_limits<result_type>::max(); }
4735 * @brief Generating functions.
4737 template<typename _UniformRandomNumberGenerator>
4738 result_type
4739 operator()(_UniformRandomNumberGenerator& __urng)
4740 { return this->operator()(__urng, _M_param); }
4742 template<typename _UniformRandomNumberGenerator>
4743 result_type
4744 operator()(_UniformRandomNumberGenerator& __urng,
4745 const param_type& __p)
4747 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4748 __aurng(__urng);
4749 return -std::log(result_type(1) - __aurng()) / __p.lambda();
4752 template<typename _ForwardIterator,
4753 typename _UniformRandomNumberGenerator>
4754 void
4755 __generate(_ForwardIterator __f, _ForwardIterator __t,
4756 _UniformRandomNumberGenerator& __urng)
4757 { this->__generate(__f, __t, __urng, _M_param); }
4759 template<typename _ForwardIterator,
4760 typename _UniformRandomNumberGenerator>
4761 void
4762 __generate(_ForwardIterator __f, _ForwardIterator __t,
4763 _UniformRandomNumberGenerator& __urng,
4764 const param_type& __p)
4765 { this->__generate_impl(__f, __t, __urng, __p); }
4767 template<typename _UniformRandomNumberGenerator>
4768 void
4769 __generate(result_type* __f, result_type* __t,
4770 _UniformRandomNumberGenerator& __urng,
4771 const param_type& __p)
4772 { this->__generate_impl(__f, __t, __urng, __p); }
4775 * @brief Return true if two exponential distributions have the same
4776 * parameters.
4778 friend bool
4779 operator==(const exponential_distribution& __d1,
4780 const exponential_distribution& __d2)
4781 { return __d1._M_param == __d2._M_param; }
4783 private:
4784 template<typename _ForwardIterator,
4785 typename _UniformRandomNumberGenerator>
4786 void
4787 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4788 _UniformRandomNumberGenerator& __urng,
4789 const param_type& __p);
4791 param_type _M_param;
4795 * @brief Return true if two exponential distributions have different
4796 * parameters.
4798 template<typename _RealType>
4799 inline bool
4800 operator!=(const std::exponential_distribution<_RealType>& __d1,
4801 const std::exponential_distribution<_RealType>& __d2)
4802 { return !(__d1 == __d2); }
4805 * @brief Inserts a %exponential_distribution random number distribution
4806 * @p __x into the output stream @p __os.
4808 * @param __os An output stream.
4809 * @param __x A %exponential_distribution random number distribution.
4811 * @returns The output stream with the state of @p __x inserted or in
4812 * an error state.
4814 template<typename _RealType, typename _CharT, typename _Traits>
4815 std::basic_ostream<_CharT, _Traits>&
4816 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4817 const std::exponential_distribution<_RealType>& __x);
4820 * @brief Extracts a %exponential_distribution random number distribution
4821 * @p __x from the input stream @p __is.
4823 * @param __is An input stream.
4824 * @param __x A %exponential_distribution random number
4825 * generator engine.
4827 * @returns The input stream with @p __x extracted or in an error state.
4829 template<typename _RealType, typename _CharT, typename _Traits>
4830 std::basic_istream<_CharT, _Traits>&
4831 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4832 std::exponential_distribution<_RealType>& __x);
4836 * @brief A weibull_distribution random number distribution.
4838 * The formula for the normal probability density function is:
4839 * @f[
4840 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4841 * \exp{(-(\frac{x}{\beta})^\alpha)}
4842 * @f]
4844 template<typename _RealType = double>
4845 class weibull_distribution
4847 static_assert(std::is_floating_point<_RealType>::value,
4848 "template argument not a floating point type");
4850 public:
4851 /** The type of the range of the distribution. */
4852 typedef _RealType result_type;
4853 /** Parameter type. */
4854 struct param_type
4856 typedef weibull_distribution<_RealType> distribution_type;
4858 explicit
4859 param_type(_RealType __a = _RealType(1),
4860 _RealType __b = _RealType(1))
4861 : _M_a(__a), _M_b(__b)
4864 _RealType
4865 a() const
4866 { return _M_a; }
4868 _RealType
4869 b() const
4870 { return _M_b; }
4872 friend bool
4873 operator==(const param_type& __p1, const param_type& __p2)
4874 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4876 private:
4877 _RealType _M_a;
4878 _RealType _M_b;
4881 explicit
4882 weibull_distribution(_RealType __a = _RealType(1),
4883 _RealType __b = _RealType(1))
4884 : _M_param(__a, __b)
4887 explicit
4888 weibull_distribution(const param_type& __p)
4889 : _M_param(__p)
4893 * @brief Resets the distribution state.
4895 void
4896 reset()
4900 * @brief Return the @f$a@f$ parameter of the distribution.
4902 _RealType
4903 a() const
4904 { return _M_param.a(); }
4907 * @brief Return the @f$b@f$ parameter of the distribution.
4909 _RealType
4910 b() const
4911 { return _M_param.b(); }
4914 * @brief Returns the parameter set of the distribution.
4916 param_type
4917 param() const
4918 { return _M_param; }
4921 * @brief Sets the parameter set of the distribution.
4922 * @param __param The new parameter set of the distribution.
4924 void
4925 param(const param_type& __param)
4926 { _M_param = __param; }
4929 * @brief Returns the greatest lower bound value of the distribution.
4931 result_type
4932 min() const
4933 { return result_type(0); }
4936 * @brief Returns the least upper bound value of the distribution.
4938 result_type
4939 max() const
4940 { return std::numeric_limits<result_type>::max(); }
4943 * @brief Generating functions.
4945 template<typename _UniformRandomNumberGenerator>
4946 result_type
4947 operator()(_UniformRandomNumberGenerator& __urng)
4948 { return this->operator()(__urng, _M_param); }
4950 template<typename _UniformRandomNumberGenerator>
4951 result_type
4952 operator()(_UniformRandomNumberGenerator& __urng,
4953 const param_type& __p);
4955 template<typename _ForwardIterator,
4956 typename _UniformRandomNumberGenerator>
4957 void
4958 __generate(_ForwardIterator __f, _ForwardIterator __t,
4959 _UniformRandomNumberGenerator& __urng)
4960 { this->__generate(__f, __t, __urng, _M_param); }
4962 template<typename _ForwardIterator,
4963 typename _UniformRandomNumberGenerator>
4964 void
4965 __generate(_ForwardIterator __f, _ForwardIterator __t,
4966 _UniformRandomNumberGenerator& __urng,
4967 const param_type& __p)
4968 { this->__generate_impl(__f, __t, __urng, __p); }
4970 template<typename _UniformRandomNumberGenerator>
4971 void
4972 __generate(result_type* __f, result_type* __t,
4973 _UniformRandomNumberGenerator& __urng,
4974 const param_type& __p)
4975 { this->__generate_impl(__f, __t, __urng, __p); }
4978 * @brief Return true if two Weibull distributions have the same
4979 * parameters.
4981 friend bool
4982 operator==(const weibull_distribution& __d1,
4983 const weibull_distribution& __d2)
4984 { return __d1._M_param == __d2._M_param; }
4986 private:
4987 template<typename _ForwardIterator,
4988 typename _UniformRandomNumberGenerator>
4989 void
4990 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4991 _UniformRandomNumberGenerator& __urng,
4992 const param_type& __p);
4994 param_type _M_param;
4998 * @brief Return true if two Weibull distributions have different
4999 * parameters.
5001 template<typename _RealType>
5002 inline bool
5003 operator!=(const std::weibull_distribution<_RealType>& __d1,
5004 const std::weibull_distribution<_RealType>& __d2)
5005 { return !(__d1 == __d2); }
5008 * @brief Inserts a %weibull_distribution random number distribution
5009 * @p __x into the output stream @p __os.
5011 * @param __os An output stream.
5012 * @param __x A %weibull_distribution random number distribution.
5014 * @returns The output stream with the state of @p __x inserted or in
5015 * an error state.
5017 template<typename _RealType, typename _CharT, typename _Traits>
5018 std::basic_ostream<_CharT, _Traits>&
5019 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5020 const std::weibull_distribution<_RealType>& __x);
5023 * @brief Extracts a %weibull_distribution random number distribution
5024 * @p __x from the input stream @p __is.
5026 * @param __is An input stream.
5027 * @param __x A %weibull_distribution random number
5028 * generator engine.
5030 * @returns The input stream with @p __x extracted or in an error state.
5032 template<typename _RealType, typename _CharT, typename _Traits>
5033 std::basic_istream<_CharT, _Traits>&
5034 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5035 std::weibull_distribution<_RealType>& __x);
5039 * @brief A extreme_value_distribution random number distribution.
5041 * The formula for the normal probability mass function is
5042 * @f[
5043 * p(x|a,b) = \frac{1}{b}
5044 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
5045 * @f]
5047 template<typename _RealType = double>
5048 class extreme_value_distribution
5050 static_assert(std::is_floating_point<_RealType>::value,
5051 "template argument not a floating point type");
5053 public:
5054 /** The type of the range of the distribution. */
5055 typedef _RealType result_type;
5056 /** Parameter type. */
5057 struct param_type
5059 typedef extreme_value_distribution<_RealType> distribution_type;
5061 explicit
5062 param_type(_RealType __a = _RealType(0),
5063 _RealType __b = _RealType(1))
5064 : _M_a(__a), _M_b(__b)
5067 _RealType
5068 a() const
5069 { return _M_a; }
5071 _RealType
5072 b() const
5073 { return _M_b; }
5075 friend bool
5076 operator==(const param_type& __p1, const param_type& __p2)
5077 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5079 private:
5080 _RealType _M_a;
5081 _RealType _M_b;
5084 explicit
5085 extreme_value_distribution(_RealType __a = _RealType(0),
5086 _RealType __b = _RealType(1))
5087 : _M_param(__a, __b)
5090 explicit
5091 extreme_value_distribution(const param_type& __p)
5092 : _M_param(__p)
5096 * @brief Resets the distribution state.
5098 void
5099 reset()
5103 * @brief Return the @f$a@f$ parameter of the distribution.
5105 _RealType
5106 a() const
5107 { return _M_param.a(); }
5110 * @brief Return the @f$b@f$ parameter of the distribution.
5112 _RealType
5113 b() const
5114 { return _M_param.b(); }
5117 * @brief Returns the parameter set of the distribution.
5119 param_type
5120 param() const
5121 { return _M_param; }
5124 * @brief Sets the parameter set of the distribution.
5125 * @param __param The new parameter set of the distribution.
5127 void
5128 param(const param_type& __param)
5129 { _M_param = __param; }
5132 * @brief Returns the greatest lower bound value of the distribution.
5134 result_type
5135 min() const
5136 { return std::numeric_limits<result_type>::lowest(); }
5139 * @brief Returns the least upper bound value of the distribution.
5141 result_type
5142 max() const
5143 { return std::numeric_limits<result_type>::max(); }
5146 * @brief Generating functions.
5148 template<typename _UniformRandomNumberGenerator>
5149 result_type
5150 operator()(_UniformRandomNumberGenerator& __urng)
5151 { return this->operator()(__urng, _M_param); }
5153 template<typename _UniformRandomNumberGenerator>
5154 result_type
5155 operator()(_UniformRandomNumberGenerator& __urng,
5156 const param_type& __p);
5158 template<typename _ForwardIterator,
5159 typename _UniformRandomNumberGenerator>
5160 void
5161 __generate(_ForwardIterator __f, _ForwardIterator __t,
5162 _UniformRandomNumberGenerator& __urng)
5163 { this->__generate(__f, __t, __urng, _M_param); }
5165 template<typename _ForwardIterator,
5166 typename _UniformRandomNumberGenerator>
5167 void
5168 __generate(_ForwardIterator __f, _ForwardIterator __t,
5169 _UniformRandomNumberGenerator& __urng,
5170 const param_type& __p)
5171 { this->__generate_impl(__f, __t, __urng, __p); }
5173 template<typename _UniformRandomNumberGenerator>
5174 void
5175 __generate(result_type* __f, result_type* __t,
5176 _UniformRandomNumberGenerator& __urng,
5177 const param_type& __p)
5178 { this->__generate_impl(__f, __t, __urng, __p); }
5181 * @brief Return true if two extreme value distributions have the same
5182 * parameters.
5184 friend bool
5185 operator==(const extreme_value_distribution& __d1,
5186 const extreme_value_distribution& __d2)
5187 { return __d1._M_param == __d2._M_param; }
5189 private:
5190 template<typename _ForwardIterator,
5191 typename _UniformRandomNumberGenerator>
5192 void
5193 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5194 _UniformRandomNumberGenerator& __urng,
5195 const param_type& __p);
5197 param_type _M_param;
5201 * @brief Return true if two extreme value distributions have different
5202 * parameters.
5204 template<typename _RealType>
5205 inline bool
5206 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
5207 const std::extreme_value_distribution<_RealType>& __d2)
5208 { return !(__d1 == __d2); }
5211 * @brief Inserts a %extreme_value_distribution random number distribution
5212 * @p __x into the output stream @p __os.
5214 * @param __os An output stream.
5215 * @param __x A %extreme_value_distribution random number distribution.
5217 * @returns The output stream with the state of @p __x inserted or in
5218 * an error state.
5220 template<typename _RealType, typename _CharT, typename _Traits>
5221 std::basic_ostream<_CharT, _Traits>&
5222 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5223 const std::extreme_value_distribution<_RealType>& __x);
5226 * @brief Extracts a %extreme_value_distribution random number
5227 * distribution @p __x from the input stream @p __is.
5229 * @param __is An input stream.
5230 * @param __x A %extreme_value_distribution random number
5231 * generator engine.
5233 * @returns The input stream with @p __x extracted or in an error state.
5235 template<typename _RealType, typename _CharT, typename _Traits>
5236 std::basic_istream<_CharT, _Traits>&
5237 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5238 std::extreme_value_distribution<_RealType>& __x);
5242 * @brief A discrete_distribution random number distribution.
5244 * The formula for the discrete probability mass function is
5247 template<typename _IntType = int>
5248 class discrete_distribution
5250 static_assert(std::is_integral<_IntType>::value,
5251 "template argument not an integral type");
5253 public:
5254 /** The type of the range of the distribution. */
5255 typedef _IntType result_type;
5256 /** Parameter type. */
5257 struct param_type
5259 typedef discrete_distribution<_IntType> distribution_type;
5260 friend class discrete_distribution<_IntType>;
5262 param_type()
5263 : _M_prob(), _M_cp()
5266 template<typename _InputIterator>
5267 param_type(_InputIterator __wbegin,
5268 _InputIterator __wend)
5269 : _M_prob(__wbegin, __wend), _M_cp()
5270 { _M_initialize(); }
5272 param_type(initializer_list<double> __wil)
5273 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
5274 { _M_initialize(); }
5276 template<typename _Func>
5277 param_type(size_t __nw, double __xmin, double __xmax,
5278 _Func __fw);
5280 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5281 param_type(const param_type&) = default;
5282 param_type& operator=(const param_type&) = default;
5284 std::vector<double>
5285 probabilities() const
5286 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
5288 friend bool
5289 operator==(const param_type& __p1, const param_type& __p2)
5290 { return __p1._M_prob == __p2._M_prob; }
5292 private:
5293 void
5294 _M_initialize();
5296 std::vector<double> _M_prob;
5297 std::vector<double> _M_cp;
5300 discrete_distribution()
5301 : _M_param()
5304 template<typename _InputIterator>
5305 discrete_distribution(_InputIterator __wbegin,
5306 _InputIterator __wend)
5307 : _M_param(__wbegin, __wend)
5310 discrete_distribution(initializer_list<double> __wl)
5311 : _M_param(__wl)
5314 template<typename _Func>
5315 discrete_distribution(size_t __nw, double __xmin, double __xmax,
5316 _Func __fw)
5317 : _M_param(__nw, __xmin, __xmax, __fw)
5320 explicit
5321 discrete_distribution(const param_type& __p)
5322 : _M_param(__p)
5326 * @brief Resets the distribution state.
5328 void
5329 reset()
5333 * @brief Returns the probabilities of the distribution.
5335 std::vector<double>
5336 probabilities() const
5338 return _M_param._M_prob.empty()
5339 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
5343 * @brief Returns the parameter set of the distribution.
5345 param_type
5346 param() const
5347 { return _M_param; }
5350 * @brief Sets the parameter set of the distribution.
5351 * @param __param The new parameter set of the distribution.
5353 void
5354 param(const param_type& __param)
5355 { _M_param = __param; }
5358 * @brief Returns the greatest lower bound value of the distribution.
5360 result_type
5361 min() const
5362 { return result_type(0); }
5365 * @brief Returns the least upper bound value of the distribution.
5367 result_type
5368 max() const
5370 return _M_param._M_prob.empty()
5371 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
5375 * @brief Generating functions.
5377 template<typename _UniformRandomNumberGenerator>
5378 result_type
5379 operator()(_UniformRandomNumberGenerator& __urng)
5380 { return this->operator()(__urng, _M_param); }
5382 template<typename _UniformRandomNumberGenerator>
5383 result_type
5384 operator()(_UniformRandomNumberGenerator& __urng,
5385 const param_type& __p);
5387 template<typename _ForwardIterator,
5388 typename _UniformRandomNumberGenerator>
5389 void
5390 __generate(_ForwardIterator __f, _ForwardIterator __t,
5391 _UniformRandomNumberGenerator& __urng)
5392 { this->__generate(__f, __t, __urng, _M_param); }
5394 template<typename _ForwardIterator,
5395 typename _UniformRandomNumberGenerator>
5396 void
5397 __generate(_ForwardIterator __f, _ForwardIterator __t,
5398 _UniformRandomNumberGenerator& __urng,
5399 const param_type& __p)
5400 { this->__generate_impl(__f, __t, __urng, __p); }
5402 template<typename _UniformRandomNumberGenerator>
5403 void
5404 __generate(result_type* __f, result_type* __t,
5405 _UniformRandomNumberGenerator& __urng,
5406 const param_type& __p)
5407 { this->__generate_impl(__f, __t, __urng, __p); }
5410 * @brief Return true if two discrete distributions have the same
5411 * parameters.
5413 friend bool
5414 operator==(const discrete_distribution& __d1,
5415 const discrete_distribution& __d2)
5416 { return __d1._M_param == __d2._M_param; }
5419 * @brief Inserts a %discrete_distribution random number distribution
5420 * @p __x into the output stream @p __os.
5422 * @param __os An output stream.
5423 * @param __x A %discrete_distribution random number distribution.
5425 * @returns The output stream with the state of @p __x inserted or in
5426 * an error state.
5428 template<typename _IntType1, typename _CharT, typename _Traits>
5429 friend std::basic_ostream<_CharT, _Traits>&
5430 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5431 const std::discrete_distribution<_IntType1>& __x);
5434 * @brief Extracts a %discrete_distribution random number distribution
5435 * @p __x from the input stream @p __is.
5437 * @param __is An input stream.
5438 * @param __x A %discrete_distribution random number
5439 * generator engine.
5441 * @returns The input stream with @p __x extracted or in an error
5442 * state.
5444 template<typename _IntType1, typename _CharT, typename _Traits>
5445 friend std::basic_istream<_CharT, _Traits>&
5446 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5447 std::discrete_distribution<_IntType1>& __x);
5449 private:
5450 template<typename _ForwardIterator,
5451 typename _UniformRandomNumberGenerator>
5452 void
5453 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5454 _UniformRandomNumberGenerator& __urng,
5455 const param_type& __p);
5457 param_type _M_param;
5461 * @brief Return true if two discrete distributions have different
5462 * parameters.
5464 template<typename _IntType>
5465 inline bool
5466 operator!=(const std::discrete_distribution<_IntType>& __d1,
5467 const std::discrete_distribution<_IntType>& __d2)
5468 { return !(__d1 == __d2); }
5472 * @brief A piecewise_constant_distribution random number distribution.
5474 * The formula for the piecewise constant probability mass function is
5477 template<typename _RealType = double>
5478 class piecewise_constant_distribution
5480 static_assert(std::is_floating_point<_RealType>::value,
5481 "template argument not a floating point type");
5483 public:
5484 /** The type of the range of the distribution. */
5485 typedef _RealType result_type;
5486 /** Parameter type. */
5487 struct param_type
5489 typedef piecewise_constant_distribution<_RealType> distribution_type;
5490 friend class piecewise_constant_distribution<_RealType>;
5492 param_type()
5493 : _M_int(), _M_den(), _M_cp()
5496 template<typename _InputIteratorB, typename _InputIteratorW>
5497 param_type(_InputIteratorB __bfirst,
5498 _InputIteratorB __bend,
5499 _InputIteratorW __wbegin);
5501 template<typename _Func>
5502 param_type(initializer_list<_RealType> __bi, _Func __fw);
5504 template<typename _Func>
5505 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5506 _Func __fw);
5508 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5509 param_type(const param_type&) = default;
5510 param_type& operator=(const param_type&) = default;
5512 std::vector<_RealType>
5513 intervals() const
5515 if (_M_int.empty())
5517 std::vector<_RealType> __tmp(2);
5518 __tmp[1] = _RealType(1);
5519 return __tmp;
5521 else
5522 return _M_int;
5525 std::vector<double>
5526 densities() const
5527 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
5529 friend bool
5530 operator==(const param_type& __p1, const param_type& __p2)
5531 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
5533 private:
5534 void
5535 _M_initialize();
5537 std::vector<_RealType> _M_int;
5538 std::vector<double> _M_den;
5539 std::vector<double> _M_cp;
5542 explicit
5543 piecewise_constant_distribution()
5544 : _M_param()
5547 template<typename _InputIteratorB, typename _InputIteratorW>
5548 piecewise_constant_distribution(_InputIteratorB __bfirst,
5549 _InputIteratorB __bend,
5550 _InputIteratorW __wbegin)
5551 : _M_param(__bfirst, __bend, __wbegin)
5554 template<typename _Func>
5555 piecewise_constant_distribution(initializer_list<_RealType> __bl,
5556 _Func __fw)
5557 : _M_param(__bl, __fw)
5560 template<typename _Func>
5561 piecewise_constant_distribution(size_t __nw,
5562 _RealType __xmin, _RealType __xmax,
5563 _Func __fw)
5564 : _M_param(__nw, __xmin, __xmax, __fw)
5567 explicit
5568 piecewise_constant_distribution(const param_type& __p)
5569 : _M_param(__p)
5573 * @brief Resets the distribution state.
5575 void
5576 reset()
5580 * @brief Returns a vector of the intervals.
5582 std::vector<_RealType>
5583 intervals() const
5585 if (_M_param._M_int.empty())
5587 std::vector<_RealType> __tmp(2);
5588 __tmp[1] = _RealType(1);
5589 return __tmp;
5591 else
5592 return _M_param._M_int;
5596 * @brief Returns a vector of the probability densities.
5598 std::vector<double>
5599 densities() const
5601 return _M_param._M_den.empty()
5602 ? std::vector<double>(1, 1.0) : _M_param._M_den;
5606 * @brief Returns the parameter set of the distribution.
5608 param_type
5609 param() const
5610 { return _M_param; }
5613 * @brief Sets the parameter set of the distribution.
5614 * @param __param The new parameter set of the distribution.
5616 void
5617 param(const param_type& __param)
5618 { _M_param = __param; }
5621 * @brief Returns the greatest lower bound value of the distribution.
5623 result_type
5624 min() const
5626 return _M_param._M_int.empty()
5627 ? result_type(0) : _M_param._M_int.front();
5631 * @brief Returns the least upper bound value of the distribution.
5633 result_type
5634 max() const
5636 return _M_param._M_int.empty()
5637 ? result_type(1) : _M_param._M_int.back();
5641 * @brief Generating functions.
5643 template<typename _UniformRandomNumberGenerator>
5644 result_type
5645 operator()(_UniformRandomNumberGenerator& __urng)
5646 { return this->operator()(__urng, _M_param); }
5648 template<typename _UniformRandomNumberGenerator>
5649 result_type
5650 operator()(_UniformRandomNumberGenerator& __urng,
5651 const param_type& __p);
5653 template<typename _ForwardIterator,
5654 typename _UniformRandomNumberGenerator>
5655 void
5656 __generate(_ForwardIterator __f, _ForwardIterator __t,
5657 _UniformRandomNumberGenerator& __urng)
5658 { this->__generate(__f, __t, __urng, _M_param); }
5660 template<typename _ForwardIterator,
5661 typename _UniformRandomNumberGenerator>
5662 void
5663 __generate(_ForwardIterator __f, _ForwardIterator __t,
5664 _UniformRandomNumberGenerator& __urng,
5665 const param_type& __p)
5666 { this->__generate_impl(__f, __t, __urng, __p); }
5668 template<typename _UniformRandomNumberGenerator>
5669 void
5670 __generate(result_type* __f, result_type* __t,
5671 _UniformRandomNumberGenerator& __urng,
5672 const param_type& __p)
5673 { this->__generate_impl(__f, __t, __urng, __p); }
5676 * @brief Return true if two piecewise constant distributions have the
5677 * same parameters.
5679 friend bool
5680 operator==(const piecewise_constant_distribution& __d1,
5681 const piecewise_constant_distribution& __d2)
5682 { return __d1._M_param == __d2._M_param; }
5685 * @brief Inserts a %piecewise_constant_distribution random
5686 * number distribution @p __x into the output stream @p __os.
5688 * @param __os An output stream.
5689 * @param __x A %piecewise_constant_distribution random number
5690 * distribution.
5692 * @returns The output stream with the state of @p __x inserted or in
5693 * an error state.
5695 template<typename _RealType1, typename _CharT, typename _Traits>
5696 friend std::basic_ostream<_CharT, _Traits>&
5697 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5698 const std::piecewise_constant_distribution<_RealType1>& __x);
5701 * @brief Extracts a %piecewise_constant_distribution random
5702 * number distribution @p __x from the input stream @p __is.
5704 * @param __is An input stream.
5705 * @param __x A %piecewise_constant_distribution random number
5706 * generator engine.
5708 * @returns The input stream with @p __x extracted or in an error
5709 * state.
5711 template<typename _RealType1, typename _CharT, typename _Traits>
5712 friend std::basic_istream<_CharT, _Traits>&
5713 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5714 std::piecewise_constant_distribution<_RealType1>& __x);
5716 private:
5717 template<typename _ForwardIterator,
5718 typename _UniformRandomNumberGenerator>
5719 void
5720 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5721 _UniformRandomNumberGenerator& __urng,
5722 const param_type& __p);
5724 param_type _M_param;
5728 * @brief Return true if two piecewise constant distributions have
5729 * different parameters.
5731 template<typename _RealType>
5732 inline bool
5733 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5734 const std::piecewise_constant_distribution<_RealType>& __d2)
5735 { return !(__d1 == __d2); }
5739 * @brief A piecewise_linear_distribution random number distribution.
5741 * The formula for the piecewise linear probability mass function is
5744 template<typename _RealType = double>
5745 class piecewise_linear_distribution
5747 static_assert(std::is_floating_point<_RealType>::value,
5748 "template argument not a floating point type");
5750 public:
5751 /** The type of the range of the distribution. */
5752 typedef _RealType result_type;
5753 /** Parameter type. */
5754 struct param_type
5756 typedef piecewise_linear_distribution<_RealType> distribution_type;
5757 friend class piecewise_linear_distribution<_RealType>;
5759 param_type()
5760 : _M_int(), _M_den(), _M_cp(), _M_m()
5763 template<typename _InputIteratorB, typename _InputIteratorW>
5764 param_type(_InputIteratorB __bfirst,
5765 _InputIteratorB __bend,
5766 _InputIteratorW __wbegin);
5768 template<typename _Func>
5769 param_type(initializer_list<_RealType> __bl, _Func __fw);
5771 template<typename _Func>
5772 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5773 _Func __fw);
5775 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5776 param_type(const param_type&) = default;
5777 param_type& operator=(const param_type&) = default;
5779 std::vector<_RealType>
5780 intervals() const
5782 if (_M_int.empty())
5784 std::vector<_RealType> __tmp(2);
5785 __tmp[1] = _RealType(1);
5786 return __tmp;
5788 else
5789 return _M_int;
5792 std::vector<double>
5793 densities() const
5794 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5796 friend bool
5797 operator==(const param_type& __p1, const param_type& __p2)
5798 { return (__p1._M_int == __p2._M_int
5799 && __p1._M_den == __p2._M_den); }
5801 private:
5802 void
5803 _M_initialize();
5805 std::vector<_RealType> _M_int;
5806 std::vector<double> _M_den;
5807 std::vector<double> _M_cp;
5808 std::vector<double> _M_m;
5811 explicit
5812 piecewise_linear_distribution()
5813 : _M_param()
5816 template<typename _InputIteratorB, typename _InputIteratorW>
5817 piecewise_linear_distribution(_InputIteratorB __bfirst,
5818 _InputIteratorB __bend,
5819 _InputIteratorW __wbegin)
5820 : _M_param(__bfirst, __bend, __wbegin)
5823 template<typename _Func>
5824 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5825 _Func __fw)
5826 : _M_param(__bl, __fw)
5829 template<typename _Func>
5830 piecewise_linear_distribution(size_t __nw,
5831 _RealType __xmin, _RealType __xmax,
5832 _Func __fw)
5833 : _M_param(__nw, __xmin, __xmax, __fw)
5836 explicit
5837 piecewise_linear_distribution(const param_type& __p)
5838 : _M_param(__p)
5842 * Resets the distribution state.
5844 void
5845 reset()
5849 * @brief Return the intervals of the distribution.
5851 std::vector<_RealType>
5852 intervals() const
5854 if (_M_param._M_int.empty())
5856 std::vector<_RealType> __tmp(2);
5857 __tmp[1] = _RealType(1);
5858 return __tmp;
5860 else
5861 return _M_param._M_int;
5865 * @brief Return a vector of the probability densities of the
5866 * distribution.
5868 std::vector<double>
5869 densities() const
5871 return _M_param._M_den.empty()
5872 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5876 * @brief Returns the parameter set of the distribution.
5878 param_type
5879 param() const
5880 { return _M_param; }
5883 * @brief Sets the parameter set of the distribution.
5884 * @param __param The new parameter set of the distribution.
5886 void
5887 param(const param_type& __param)
5888 { _M_param = __param; }
5891 * @brief Returns the greatest lower bound value of the distribution.
5893 result_type
5894 min() const
5896 return _M_param._M_int.empty()
5897 ? result_type(0) : _M_param._M_int.front();
5901 * @brief Returns the least upper bound value of the distribution.
5903 result_type
5904 max() const
5906 return _M_param._M_int.empty()
5907 ? result_type(1) : _M_param._M_int.back();
5911 * @brief Generating functions.
5913 template<typename _UniformRandomNumberGenerator>
5914 result_type
5915 operator()(_UniformRandomNumberGenerator& __urng)
5916 { return this->operator()(__urng, _M_param); }
5918 template<typename _UniformRandomNumberGenerator>
5919 result_type
5920 operator()(_UniformRandomNumberGenerator& __urng,
5921 const param_type& __p);
5923 template<typename _ForwardIterator,
5924 typename _UniformRandomNumberGenerator>
5925 void
5926 __generate(_ForwardIterator __f, _ForwardIterator __t,
5927 _UniformRandomNumberGenerator& __urng)
5928 { this->__generate(__f, __t, __urng, _M_param); }
5930 template<typename _ForwardIterator,
5931 typename _UniformRandomNumberGenerator>
5932 void
5933 __generate(_ForwardIterator __f, _ForwardIterator __t,
5934 _UniformRandomNumberGenerator& __urng,
5935 const param_type& __p)
5936 { this->__generate_impl(__f, __t, __urng, __p); }
5938 template<typename _UniformRandomNumberGenerator>
5939 void
5940 __generate(result_type* __f, result_type* __t,
5941 _UniformRandomNumberGenerator& __urng,
5942 const param_type& __p)
5943 { this->__generate_impl(__f, __t, __urng, __p); }
5946 * @brief Return true if two piecewise linear distributions have the
5947 * same parameters.
5949 friend bool
5950 operator==(const piecewise_linear_distribution& __d1,
5951 const piecewise_linear_distribution& __d2)
5952 { return __d1._M_param == __d2._M_param; }
5955 * @brief Inserts a %piecewise_linear_distribution random number
5956 * distribution @p __x into the output stream @p __os.
5958 * @param __os An output stream.
5959 * @param __x A %piecewise_linear_distribution random number
5960 * distribution.
5962 * @returns The output stream with the state of @p __x inserted or in
5963 * an error state.
5965 template<typename _RealType1, typename _CharT, typename _Traits>
5966 friend std::basic_ostream<_CharT, _Traits>&
5967 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5968 const std::piecewise_linear_distribution<_RealType1>& __x);
5971 * @brief Extracts a %piecewise_linear_distribution random number
5972 * distribution @p __x from the input stream @p __is.
5974 * @param __is An input stream.
5975 * @param __x A %piecewise_linear_distribution random number
5976 * generator engine.
5978 * @returns The input stream with @p __x extracted or in an error
5979 * state.
5981 template<typename _RealType1, typename _CharT, typename _Traits>
5982 friend std::basic_istream<_CharT, _Traits>&
5983 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5984 std::piecewise_linear_distribution<_RealType1>& __x);
5986 private:
5987 template<typename _ForwardIterator,
5988 typename _UniformRandomNumberGenerator>
5989 void
5990 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5991 _UniformRandomNumberGenerator& __urng,
5992 const param_type& __p);
5994 param_type _M_param;
5998 * @brief Return true if two piecewise linear distributions have
5999 * different parameters.
6001 template<typename _RealType>
6002 inline bool
6003 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
6004 const std::piecewise_linear_distribution<_RealType>& __d2)
6005 { return !(__d1 == __d2); }
6008 /* @} */ // group random_distributions_poisson
6010 /* @} */ // group random_distributions
6013 * @addtogroup random_utilities Random Number Utilities
6014 * @ingroup random
6015 * @{
6019 * @brief The seed_seq class generates sequences of seeds for random
6020 * number generators.
6022 class seed_seq
6025 public:
6026 /** The type of the seed vales. */
6027 typedef uint_least32_t result_type;
6029 /** Default constructor. */
6030 seed_seq()
6031 : _M_v()
6034 template<typename _IntType>
6035 seed_seq(std::initializer_list<_IntType> il);
6037 template<typename _InputIterator>
6038 seed_seq(_InputIterator __begin, _InputIterator __end);
6040 // generating functions
6041 template<typename _RandomAccessIterator>
6042 void
6043 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
6045 // property functions
6046 size_t size() const
6047 { return _M_v.size(); }
6049 template<typename OutputIterator>
6050 void
6051 param(OutputIterator __dest) const
6052 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
6054 private:
6056 std::vector<result_type> _M_v;
6059 /* @} */ // group random_utilities
6061 /* @} */ // group random
6063 _GLIBCXX_END_NAMESPACE_VERSION
6064 } // namespace std
6066 #endif