Daily bump.
[official-gcc.git] / libstdc++-v3 / include / bits / random.h
blobb76cfbb558e1d3bbd520dfcf2ccc65f43064fd0b
1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009-2018 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>
35 #include <bits/uniform_int_dist.h>
37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 // [26.4] Random number generation
43 /**
44 * @defgroup random Random Number Generation
45 * @ingroup numerics
47 * A facility for generating random numbers on selected distributions.
48 * @{
51 /**
52 * @brief A function template for converting the output of a (integral)
53 * uniform random number generator to a floatng point result in the range
54 * [0-1).
56 template<typename _RealType, size_t __bits,
57 typename _UniformRandomNumberGenerator>
58 _RealType
59 generate_canonical(_UniformRandomNumberGenerator& __g);
62 * Implementation-space details.
64 namespace __detail
66 template<typename _UIntType, size_t __w,
67 bool = __w < static_cast<size_t>
68 (std::numeric_limits<_UIntType>::digits)>
69 struct _Shift
70 { static const _UIntType __value = 0; };
72 template<typename _UIntType, size_t __w>
73 struct _Shift<_UIntType, __w, true>
74 { static const _UIntType __value = _UIntType(1) << __w; };
76 template<int __s,
77 int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
78 + (__s <= __CHAR_BIT__ * sizeof (long))
79 + (__s <= __CHAR_BIT__ * sizeof (long long))
80 /* assume long long no bigger than __int128 */
81 + (__s <= 128))>
82 struct _Select_uint_least_t
84 static_assert(__which < 0, /* needs to be dependent */
85 "sorry, would be too much trouble for a slow result");
88 template<int __s>
89 struct _Select_uint_least_t<__s, 4>
90 { typedef unsigned int type; };
92 template<int __s>
93 struct _Select_uint_least_t<__s, 3>
94 { typedef unsigned long type; };
96 template<int __s>
97 struct _Select_uint_least_t<__s, 2>
98 { typedef unsigned long long type; };
100 #ifdef _GLIBCXX_USE_INT128
101 template<int __s>
102 struct _Select_uint_least_t<__s, 1>
103 { typedef unsigned __int128 type; };
104 #endif
106 // Assume a != 0, a < m, c < m, x < m.
107 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
108 bool __big_enough = (!(__m & (__m - 1))
109 || (_Tp(-1) - __c) / __a >= __m - 1),
110 bool __schrage_ok = __m % __a < __m / __a>
111 struct _Mod
113 typedef typename _Select_uint_least_t<std::__lg(__a)
114 + std::__lg(__m) + 2>::type _Tp2;
115 static _Tp
116 __calc(_Tp __x)
117 { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); }
120 // Schrage.
121 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
122 struct _Mod<_Tp, __m, __a, __c, false, true>
124 static _Tp
125 __calc(_Tp __x);
128 // Special cases:
129 // - for m == 2^n or m == 0, unsigned integer overflow is safe.
130 // - a * (m - 1) + c fits in _Tp, there is no overflow.
131 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
132 struct _Mod<_Tp, __m, __a, __c, true, __s>
134 static _Tp
135 __calc(_Tp __x)
137 _Tp __res = __a * __x + __c;
138 if (__m)
139 __res %= __m;
140 return __res;
144 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
145 inline _Tp
146 __mod(_Tp __x)
147 { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
150 * An adaptor class for converting the output of any Generator into
151 * the input for a specific Distribution.
153 template<typename _Engine, typename _DInputType>
154 struct _Adaptor
156 static_assert(std::is_floating_point<_DInputType>::value,
157 "template argument must be a floating point type");
159 public:
160 _Adaptor(_Engine& __g)
161 : _M_g(__g) { }
163 _DInputType
164 min() const
165 { return _DInputType(0); }
167 _DInputType
168 max() const
169 { return _DInputType(1); }
172 * Converts a value generated by the adapted random number generator
173 * into a value in the input domain for the dependent random number
174 * distribution.
176 _DInputType
177 operator()()
179 return std::generate_canonical<_DInputType,
180 std::numeric_limits<_DInputType>::digits,
181 _Engine>(_M_g);
184 private:
185 _Engine& _M_g;
188 template<typename _Sseq>
189 using __seed_seq_generate_t = decltype(
190 std::declval<_Sseq&>().generate(std::declval<uint_least32_t*>(),
191 std::declval<uint_least32_t*>()));
193 // Detect whether _Sseq is a valid seed sequence for
194 // a random number engine _Engine with result type _Res.
195 template<typename _Sseq, typename _Engine, typename _Res,
196 typename _GenerateCheck = __seed_seq_generate_t<_Sseq>>
197 using __is_seed_seq = __and_<
198 __not_<is_same<__remove_cvref_t<_Sseq>, _Engine>>,
199 is_unsigned<typename _Sseq::result_type>,
200 __not_<is_convertible<_Sseq, _Res>>
203 } // namespace __detail
206 * @addtogroup random_generators Random Number Generators
207 * @ingroup random
209 * These classes define objects which provide random or pseudorandom
210 * numbers, either from a discrete or a continuous interval. The
211 * random number generator supplied as a part of this library are
212 * all uniform random number generators which provide a sequence of
213 * random number uniformly distributed over their range.
215 * A number generator is a function object with an operator() that
216 * takes zero arguments and returns a number.
218 * A compliant random number generator must satisfy the following
219 * requirements. <table border=1 cellpadding=10 cellspacing=0>
220 * <caption align=top>Random Number Generator Requirements</caption>
221 * <tr><td>To be documented.</td></tr> </table>
223 * @{
227 * @brief A model of a linear congruential random number generator.
229 * A random number generator that produces pseudorandom numbers via
230 * linear function:
231 * @f[
232 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
233 * @f]
235 * The template parameter @p _UIntType must be an unsigned integral type
236 * large enough to store values up to (__m-1). If the template parameter
237 * @p __m is 0, the modulus @p __m used is
238 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
239 * parameters @p __a and @p __c must be less than @p __m.
241 * The size of the state is @f$1@f$.
243 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
244 class linear_congruential_engine
246 static_assert(std::is_unsigned<_UIntType>::value,
247 "result_type must be an unsigned integral type");
248 static_assert(__m == 0u || (__a < __m && __c < __m),
249 "template argument substituting __m out of bounds");
251 template<typename _Sseq>
252 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
253 _Sseq, linear_congruential_engine, _UIntType>::value>::type;
255 public:
256 /** The type of the generated random value. */
257 typedef _UIntType result_type;
259 /** The multiplier. */
260 static constexpr result_type multiplier = __a;
261 /** An increment. */
262 static constexpr result_type increment = __c;
263 /** The modulus. */
264 static constexpr result_type modulus = __m;
265 static constexpr result_type default_seed = 1u;
268 * @brief Constructs a %linear_congruential_engine random number
269 * generator engine with seed @p __s. The default seed value
270 * is 1.
272 * @param __s The initial seed value.
274 explicit
275 linear_congruential_engine(result_type __s = default_seed)
276 { seed(__s); }
279 * @brief Constructs a %linear_congruential_engine random number
280 * generator engine seeded from the seed sequence @p __q.
282 * @param __q the seed sequence.
284 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
285 explicit
286 linear_congruential_engine(_Sseq& __q)
287 { seed(__q); }
290 * @brief Reseeds the %linear_congruential_engine random number generator
291 * engine sequence to the seed @p __s.
293 * @param __s The new seed.
295 void
296 seed(result_type __s = default_seed);
299 * @brief Reseeds the %linear_congruential_engine random number generator
300 * engine
301 * sequence using values from the seed sequence @p __q.
303 * @param __q the seed sequence.
305 template<typename _Sseq>
306 _If_seed_seq<_Sseq>
307 seed(_Sseq& __q);
310 * @brief Gets the smallest possible value in the output range.
312 * The minimum depends on the @p __c parameter: if it is zero, the
313 * minimum generated must be > 0, otherwise 0 is allowed.
315 static constexpr result_type
316 min()
317 { return __c == 0u ? 1u : 0u; }
320 * @brief Gets the largest possible value in the output range.
322 static constexpr result_type
323 max()
324 { return __m - 1u; }
327 * @brief Discard a sequence of random numbers.
329 void
330 discard(unsigned long long __z)
332 for (; __z != 0ULL; --__z)
333 (*this)();
337 * @brief Gets the next random number in the sequence.
339 result_type
340 operator()()
342 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
343 return _M_x;
347 * @brief Compares two linear congruential random number generator
348 * objects of the same type for equality.
350 * @param __lhs A linear congruential random number generator object.
351 * @param __rhs Another linear congruential random number generator
352 * object.
354 * @returns true if the infinite sequences of generated values
355 * would be equal, false otherwise.
357 friend bool
358 operator==(const linear_congruential_engine& __lhs,
359 const linear_congruential_engine& __rhs)
360 { return __lhs._M_x == __rhs._M_x; }
363 * @brief Writes the textual representation of the state x(i) of x to
364 * @p __os.
366 * @param __os The output stream.
367 * @param __lcr A % linear_congruential_engine random number generator.
368 * @returns __os.
370 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
371 _UIntType1 __m1, typename _CharT, typename _Traits>
372 friend std::basic_ostream<_CharT, _Traits>&
373 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
374 const std::linear_congruential_engine<_UIntType1,
375 __a1, __c1, __m1>& __lcr);
378 * @brief Sets the state of the engine by reading its textual
379 * representation from @p __is.
381 * The textual representation must have been previously written using
382 * an output stream whose imbued locale and whose type's template
383 * specialization arguments _CharT and _Traits were the same as those
384 * of @p __is.
386 * @param __is The input stream.
387 * @param __lcr A % linear_congruential_engine random number generator.
388 * @returns __is.
390 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
391 _UIntType1 __m1, typename _CharT, typename _Traits>
392 friend std::basic_istream<_CharT, _Traits>&
393 operator>>(std::basic_istream<_CharT, _Traits>& __is,
394 std::linear_congruential_engine<_UIntType1, __a1,
395 __c1, __m1>& __lcr);
397 private:
398 _UIntType _M_x;
402 * @brief Compares two linear congruential random number generator
403 * objects of the same type for inequality.
405 * @param __lhs A linear congruential random number generator object.
406 * @param __rhs Another linear congruential random number generator
407 * object.
409 * @returns true if the infinite sequences of generated values
410 * would be different, false otherwise.
412 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
413 inline bool
414 operator!=(const std::linear_congruential_engine<_UIntType, __a,
415 __c, __m>& __lhs,
416 const std::linear_congruential_engine<_UIntType, __a,
417 __c, __m>& __rhs)
418 { return !(__lhs == __rhs); }
422 * A generalized feedback shift register discrete random number generator.
424 * This algorithm avoids multiplication and division and is designed to be
425 * friendly to a pipelined architecture. If the parameters are chosen
426 * correctly, this generator will produce numbers with a very long period and
427 * fairly good apparent entropy, although still not cryptographically strong.
429 * The best way to use this generator is with the predefined mt19937 class.
431 * This algorithm was originally invented by Makoto Matsumoto and
432 * Takuji Nishimura.
434 * @tparam __w Word size, the number of bits in each element of
435 * the state vector.
436 * @tparam __n The degree of recursion.
437 * @tparam __m The period parameter.
438 * @tparam __r The separation point bit index.
439 * @tparam __a The last row of the twist matrix.
440 * @tparam __u The first right-shift tempering matrix parameter.
441 * @tparam __d The first right-shift tempering matrix mask.
442 * @tparam __s The first left-shift tempering matrix parameter.
443 * @tparam __b The first left-shift tempering matrix mask.
444 * @tparam __t The second left-shift tempering matrix parameter.
445 * @tparam __c The second left-shift tempering matrix mask.
446 * @tparam __l The second right-shift tempering matrix parameter.
447 * @tparam __f Initialization multiplier.
449 template<typename _UIntType, size_t __w,
450 size_t __n, size_t __m, size_t __r,
451 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
452 _UIntType __b, size_t __t,
453 _UIntType __c, size_t __l, _UIntType __f>
454 class mersenne_twister_engine
456 static_assert(std::is_unsigned<_UIntType>::value,
457 "result_type must be an unsigned integral type");
458 static_assert(1u <= __m && __m <= __n,
459 "template argument substituting __m out of bounds");
460 static_assert(__r <= __w, "template argument substituting "
461 "__r out of bound");
462 static_assert(__u <= __w, "template argument substituting "
463 "__u out of bound");
464 static_assert(__s <= __w, "template argument substituting "
465 "__s out of bound");
466 static_assert(__t <= __w, "template argument substituting "
467 "__t out of bound");
468 static_assert(__l <= __w, "template argument substituting "
469 "__l out of bound");
470 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
471 "template argument substituting __w out of bound");
472 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
473 "template argument substituting __a out of bound");
474 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
475 "template argument substituting __b out of bound");
476 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
477 "template argument substituting __c out of bound");
478 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
479 "template argument substituting __d out of bound");
480 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
481 "template argument substituting __f out of bound");
483 template<typename _Sseq>
484 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
485 _Sseq, mersenne_twister_engine, _UIntType>::value>::type;
487 public:
488 /** The type of the generated random value. */
489 typedef _UIntType result_type;
491 // parameter values
492 static constexpr size_t word_size = __w;
493 static constexpr size_t state_size = __n;
494 static constexpr size_t shift_size = __m;
495 static constexpr size_t mask_bits = __r;
496 static constexpr result_type xor_mask = __a;
497 static constexpr size_t tempering_u = __u;
498 static constexpr result_type tempering_d = __d;
499 static constexpr size_t tempering_s = __s;
500 static constexpr result_type tempering_b = __b;
501 static constexpr size_t tempering_t = __t;
502 static constexpr result_type tempering_c = __c;
503 static constexpr size_t tempering_l = __l;
504 static constexpr result_type initialization_multiplier = __f;
505 static constexpr result_type default_seed = 5489u;
507 // constructors and member function
508 explicit
509 mersenne_twister_engine(result_type __sd = default_seed)
510 { seed(__sd); }
513 * @brief Constructs a %mersenne_twister_engine random number generator
514 * engine seeded from the seed sequence @p __q.
516 * @param __q the seed sequence.
518 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
519 explicit
520 mersenne_twister_engine(_Sseq& __q)
521 { seed(__q); }
523 void
524 seed(result_type __sd = default_seed);
526 template<typename _Sseq>
527 _If_seed_seq<_Sseq>
528 seed(_Sseq& __q);
531 * @brief Gets the smallest possible value in the output range.
533 static constexpr result_type
534 min()
535 { return 0; }
538 * @brief Gets the largest possible value in the output range.
540 static constexpr result_type
541 max()
542 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
545 * @brief Discard a sequence of random numbers.
547 void
548 discard(unsigned long long __z);
550 result_type
551 operator()();
554 * @brief Compares two % mersenne_twister_engine random number generator
555 * objects of the same type for equality.
557 * @param __lhs A % mersenne_twister_engine random number generator
558 * object.
559 * @param __rhs Another % mersenne_twister_engine random number
560 * generator object.
562 * @returns true if the infinite sequences of generated values
563 * would be equal, false otherwise.
565 friend bool
566 operator==(const mersenne_twister_engine& __lhs,
567 const mersenne_twister_engine& __rhs)
568 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
569 && __lhs._M_p == __rhs._M_p); }
572 * @brief Inserts the current state of a % mersenne_twister_engine
573 * random number generator engine @p __x into the output stream
574 * @p __os.
576 * @param __os An output stream.
577 * @param __x A % mersenne_twister_engine random number generator
578 * engine.
580 * @returns The output stream with the state of @p __x inserted or in
581 * an error state.
583 template<typename _UIntType1,
584 size_t __w1, size_t __n1,
585 size_t __m1, size_t __r1,
586 _UIntType1 __a1, size_t __u1,
587 _UIntType1 __d1, size_t __s1,
588 _UIntType1 __b1, size_t __t1,
589 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
590 typename _CharT, typename _Traits>
591 friend std::basic_ostream<_CharT, _Traits>&
592 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
593 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
594 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
595 __l1, __f1>& __x);
598 * @brief Extracts the current state of a % mersenne_twister_engine
599 * random number generator engine @p __x from the input stream
600 * @p __is.
602 * @param __is An input stream.
603 * @param __x A % mersenne_twister_engine random number generator
604 * engine.
606 * @returns The input stream with the state of @p __x extracted or in
607 * an error state.
609 template<typename _UIntType1,
610 size_t __w1, size_t __n1,
611 size_t __m1, size_t __r1,
612 _UIntType1 __a1, size_t __u1,
613 _UIntType1 __d1, size_t __s1,
614 _UIntType1 __b1, size_t __t1,
615 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
616 typename _CharT, typename _Traits>
617 friend std::basic_istream<_CharT, _Traits>&
618 operator>>(std::basic_istream<_CharT, _Traits>& __is,
619 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
620 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
621 __l1, __f1>& __x);
623 private:
624 void _M_gen_rand();
626 _UIntType _M_x[state_size];
627 size_t _M_p;
631 * @brief Compares two % mersenne_twister_engine random number generator
632 * objects of the same type for inequality.
634 * @param __lhs A % mersenne_twister_engine random number generator
635 * object.
636 * @param __rhs Another % mersenne_twister_engine random number
637 * generator object.
639 * @returns true if the infinite sequences of generated values
640 * would be different, false otherwise.
642 template<typename _UIntType, size_t __w,
643 size_t __n, size_t __m, size_t __r,
644 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
645 _UIntType __b, size_t __t,
646 _UIntType __c, size_t __l, _UIntType __f>
647 inline bool
648 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
649 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
650 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
651 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
652 { return !(__lhs == __rhs); }
656 * @brief The Marsaglia-Zaman generator.
658 * This is a model of a Generalized Fibonacci discrete random number
659 * generator, sometimes referred to as the SWC generator.
661 * A discrete random number generator that produces pseudorandom
662 * numbers using:
663 * @f[
664 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
665 * @f]
667 * The size of the state is @f$r@f$
668 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
670 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
671 class subtract_with_carry_engine
673 static_assert(std::is_unsigned<_UIntType>::value,
674 "result_type must be an unsigned integral type");
675 static_assert(0u < __s && __s < __r,
676 "0 < s < r");
677 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
678 "template argument substituting __w out of bounds");
680 template<typename _Sseq>
681 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
682 _Sseq, subtract_with_carry_engine, _UIntType>::value>::type;
684 public:
685 /** The type of the generated random value. */
686 typedef _UIntType result_type;
688 // parameter values
689 static constexpr size_t word_size = __w;
690 static constexpr size_t short_lag = __s;
691 static constexpr size_t long_lag = __r;
692 static constexpr result_type default_seed = 19780503u;
695 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
696 * random number generator.
698 explicit
699 subtract_with_carry_engine(result_type __sd = default_seed)
700 { seed(__sd); }
703 * @brief Constructs a %subtract_with_carry_engine random number engine
704 * seeded from the seed sequence @p __q.
706 * @param __q the seed sequence.
708 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
709 explicit
710 subtract_with_carry_engine(_Sseq& __q)
711 { seed(__q); }
714 * @brief Seeds the initial state @f$x_0@f$ of the random number
715 * generator.
717 * N1688[4.19] modifies this as follows. If @p __value == 0,
718 * sets value to 19780503. In any case, with a linear
719 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
720 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
721 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
722 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
723 * set carry to 1, otherwise sets carry to 0.
725 void
726 seed(result_type __sd = default_seed);
729 * @brief Seeds the initial state @f$x_0@f$ of the
730 * % subtract_with_carry_engine random number generator.
732 template<typename _Sseq>
733 _If_seed_seq<_Sseq>
734 seed(_Sseq& __q);
737 * @brief Gets the inclusive minimum value of the range of random
738 * integers returned by this generator.
740 static constexpr result_type
741 min()
742 { return 0; }
745 * @brief Gets the inclusive maximum value of the range of random
746 * integers returned by this generator.
748 static constexpr result_type
749 max()
750 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
753 * @brief Discard a sequence of random numbers.
755 void
756 discard(unsigned long long __z)
758 for (; __z != 0ULL; --__z)
759 (*this)();
763 * @brief Gets the next random number in the sequence.
765 result_type
766 operator()();
769 * @brief Compares two % subtract_with_carry_engine random number
770 * generator objects of the same type for equality.
772 * @param __lhs A % subtract_with_carry_engine random number generator
773 * object.
774 * @param __rhs Another % subtract_with_carry_engine random number
775 * generator object.
777 * @returns true if the infinite sequences of generated values
778 * would be equal, false otherwise.
780 friend bool
781 operator==(const subtract_with_carry_engine& __lhs,
782 const subtract_with_carry_engine& __rhs)
783 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
784 && __lhs._M_carry == __rhs._M_carry
785 && __lhs._M_p == __rhs._M_p); }
788 * @brief Inserts the current state of a % subtract_with_carry_engine
789 * random number generator engine @p __x into the output stream
790 * @p __os.
792 * @param __os An output stream.
793 * @param __x A % subtract_with_carry_engine random number generator
794 * engine.
796 * @returns The output stream with the state of @p __x inserted or in
797 * an error state.
799 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
800 typename _CharT, typename _Traits>
801 friend std::basic_ostream<_CharT, _Traits>&
802 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
803 const std::subtract_with_carry_engine<_UIntType1, __w1,
804 __s1, __r1>& __x);
807 * @brief Extracts the current state of a % subtract_with_carry_engine
808 * random number generator engine @p __x from the input stream
809 * @p __is.
811 * @param __is An input stream.
812 * @param __x A % subtract_with_carry_engine random number generator
813 * engine.
815 * @returns The input stream with the state of @p __x extracted or in
816 * an error state.
818 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
819 typename _CharT, typename _Traits>
820 friend std::basic_istream<_CharT, _Traits>&
821 operator>>(std::basic_istream<_CharT, _Traits>& __is,
822 std::subtract_with_carry_engine<_UIntType1, __w1,
823 __s1, __r1>& __x);
825 private:
826 /// The state of the generator. This is a ring buffer.
827 _UIntType _M_x[long_lag];
828 _UIntType _M_carry; ///< The carry
829 size_t _M_p; ///< Current index of x(i - r).
833 * @brief Compares two % subtract_with_carry_engine random number
834 * generator objects of the same type for inequality.
836 * @param __lhs A % subtract_with_carry_engine random number generator
837 * object.
838 * @param __rhs Another % subtract_with_carry_engine random number
839 * generator object.
841 * @returns true if the infinite sequences of generated values
842 * would be different, false otherwise.
844 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
845 inline bool
846 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
847 __s, __r>& __lhs,
848 const std::subtract_with_carry_engine<_UIntType, __w,
849 __s, __r>& __rhs)
850 { return !(__lhs == __rhs); }
854 * Produces random numbers from some base engine by discarding blocks of
855 * data.
857 * 0 <= @p __r <= @p __p
859 template<typename _RandomNumberEngine, size_t __p, size_t __r>
860 class discard_block_engine
862 static_assert(1 <= __r && __r <= __p,
863 "template argument substituting __r out of bounds");
865 public:
866 /** The type of the generated random value. */
867 typedef typename _RandomNumberEngine::result_type result_type;
869 template<typename _Sseq>
870 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
871 _Sseq, discard_block_engine, result_type>::value>::type;
873 // parameter values
874 static constexpr size_t block_size = __p;
875 static constexpr size_t used_block = __r;
878 * @brief Constructs a default %discard_block_engine engine.
880 * The underlying engine is default constructed as well.
882 discard_block_engine()
883 : _M_b(), _M_n(0) { }
886 * @brief Copy constructs a %discard_block_engine engine.
888 * Copies an existing base class random number generator.
889 * @param __rng An existing (base class) engine object.
891 explicit
892 discard_block_engine(const _RandomNumberEngine& __rng)
893 : _M_b(__rng), _M_n(0) { }
896 * @brief Move constructs a %discard_block_engine engine.
898 * Copies an existing base class random number generator.
899 * @param __rng An existing (base class) engine object.
901 explicit
902 discard_block_engine(_RandomNumberEngine&& __rng)
903 : _M_b(std::move(__rng)), _M_n(0) { }
906 * @brief Seed constructs a %discard_block_engine engine.
908 * Constructs the underlying generator engine seeded with @p __s.
909 * @param __s A seed value for the base class engine.
911 explicit
912 discard_block_engine(result_type __s)
913 : _M_b(__s), _M_n(0) { }
916 * @brief Generator construct a %discard_block_engine engine.
918 * @param __q A seed sequence.
920 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
921 explicit
922 discard_block_engine(_Sseq& __q)
923 : _M_b(__q), _M_n(0)
927 * @brief Reseeds the %discard_block_engine object with the default
928 * seed for the underlying base class generator engine.
930 void
931 seed()
933 _M_b.seed();
934 _M_n = 0;
938 * @brief Reseeds the %discard_block_engine object with the default
939 * seed for the underlying base class generator engine.
941 void
942 seed(result_type __s)
944 _M_b.seed(__s);
945 _M_n = 0;
949 * @brief Reseeds the %discard_block_engine object with the given seed
950 * sequence.
951 * @param __q A seed generator function.
953 template<typename _Sseq>
954 _If_seed_seq<_Sseq>
955 seed(_Sseq& __q)
957 _M_b.seed(__q);
958 _M_n = 0;
962 * @brief Gets a const reference to the underlying generator engine
963 * object.
965 const _RandomNumberEngine&
966 base() const noexcept
967 { return _M_b; }
970 * @brief Gets the minimum value in the generated random number range.
972 static constexpr result_type
973 min()
974 { return _RandomNumberEngine::min(); }
977 * @brief Gets the maximum value in the generated random number range.
979 static constexpr result_type
980 max()
981 { return _RandomNumberEngine::max(); }
984 * @brief Discard a sequence of random numbers.
986 void
987 discard(unsigned long long __z)
989 for (; __z != 0ULL; --__z)
990 (*this)();
994 * @brief Gets the next value in the generated random number sequence.
996 result_type
997 operator()();
1000 * @brief Compares two %discard_block_engine random number generator
1001 * objects of the same type for equality.
1003 * @param __lhs A %discard_block_engine random number generator object.
1004 * @param __rhs Another %discard_block_engine random number generator
1005 * object.
1007 * @returns true if the infinite sequences of generated values
1008 * would be equal, false otherwise.
1010 friend bool
1011 operator==(const discard_block_engine& __lhs,
1012 const discard_block_engine& __rhs)
1013 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
1016 * @brief Inserts the current state of a %discard_block_engine random
1017 * number generator engine @p __x into the output stream
1018 * @p __os.
1020 * @param __os An output stream.
1021 * @param __x A %discard_block_engine random number generator engine.
1023 * @returns The output stream with the state of @p __x inserted or in
1024 * an error state.
1026 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1027 typename _CharT, typename _Traits>
1028 friend std::basic_ostream<_CharT, _Traits>&
1029 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1030 const std::discard_block_engine<_RandomNumberEngine1,
1031 __p1, __r1>& __x);
1034 * @brief Extracts the current state of a % subtract_with_carry_engine
1035 * random number generator engine @p __x from the input stream
1036 * @p __is.
1038 * @param __is An input stream.
1039 * @param __x A %discard_block_engine random number generator engine.
1041 * @returns The input stream with the state of @p __x extracted or in
1042 * an error state.
1044 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
1045 typename _CharT, typename _Traits>
1046 friend std::basic_istream<_CharT, _Traits>&
1047 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1048 std::discard_block_engine<_RandomNumberEngine1,
1049 __p1, __r1>& __x);
1051 private:
1052 _RandomNumberEngine _M_b;
1053 size_t _M_n;
1057 * @brief Compares two %discard_block_engine random number generator
1058 * objects of the same type for inequality.
1060 * @param __lhs A %discard_block_engine random number generator object.
1061 * @param __rhs Another %discard_block_engine random number generator
1062 * object.
1064 * @returns true if the infinite sequences of generated values
1065 * would be different, false otherwise.
1067 template<typename _RandomNumberEngine, size_t __p, size_t __r>
1068 inline bool
1069 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
1070 __r>& __lhs,
1071 const std::discard_block_engine<_RandomNumberEngine, __p,
1072 __r>& __rhs)
1073 { return !(__lhs == __rhs); }
1077 * Produces random numbers by combining random numbers from some base
1078 * engine to produce random numbers with a specifies number of bits @p __w.
1080 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1081 class independent_bits_engine
1083 static_assert(std::is_unsigned<_UIntType>::value,
1084 "result_type must be an unsigned integral type");
1085 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1086 "template argument substituting __w out of bounds");
1088 template<typename _Sseq>
1089 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
1090 _Sseq, independent_bits_engine, _UIntType>::value>::type;
1092 public:
1093 /** The type of the generated random value. */
1094 typedef _UIntType result_type;
1097 * @brief Constructs a default %independent_bits_engine engine.
1099 * The underlying engine is default constructed as well.
1101 independent_bits_engine()
1102 : _M_b() { }
1105 * @brief Copy constructs a %independent_bits_engine engine.
1107 * Copies an existing base class random number generator.
1108 * @param __rng An existing (base class) engine object.
1110 explicit
1111 independent_bits_engine(const _RandomNumberEngine& __rng)
1112 : _M_b(__rng) { }
1115 * @brief Move constructs a %independent_bits_engine engine.
1117 * Copies an existing base class random number generator.
1118 * @param __rng An existing (base class) engine object.
1120 explicit
1121 independent_bits_engine(_RandomNumberEngine&& __rng)
1122 : _M_b(std::move(__rng)) { }
1125 * @brief Seed constructs a %independent_bits_engine engine.
1127 * Constructs the underlying generator engine seeded with @p __s.
1128 * @param __s A seed value for the base class engine.
1130 explicit
1131 independent_bits_engine(result_type __s)
1132 : _M_b(__s) { }
1135 * @brief Generator construct a %independent_bits_engine engine.
1137 * @param __q A seed sequence.
1139 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1140 explicit
1141 independent_bits_engine(_Sseq& __q)
1142 : _M_b(__q)
1146 * @brief Reseeds the %independent_bits_engine object with the default
1147 * seed for the underlying base class generator engine.
1149 void
1150 seed()
1151 { _M_b.seed(); }
1154 * @brief Reseeds the %independent_bits_engine object with the default
1155 * seed for the underlying base class generator engine.
1157 void
1158 seed(result_type __s)
1159 { _M_b.seed(__s); }
1162 * @brief Reseeds the %independent_bits_engine object with the given
1163 * seed sequence.
1164 * @param __q A seed generator function.
1166 template<typename _Sseq>
1167 _If_seed_seq<_Sseq>
1168 seed(_Sseq& __q)
1169 { _M_b.seed(__q); }
1172 * @brief Gets a const reference to the underlying generator engine
1173 * object.
1175 const _RandomNumberEngine&
1176 base() const noexcept
1177 { return _M_b; }
1180 * @brief Gets the minimum value in the generated random number range.
1182 static constexpr result_type
1183 min()
1184 { return 0U; }
1187 * @brief Gets the maximum value in the generated random number range.
1189 static constexpr result_type
1190 max()
1191 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1194 * @brief Discard a sequence of random numbers.
1196 void
1197 discard(unsigned long long __z)
1199 for (; __z != 0ULL; --__z)
1200 (*this)();
1204 * @brief Gets the next value in the generated random number sequence.
1206 result_type
1207 operator()();
1210 * @brief Compares two %independent_bits_engine random number generator
1211 * objects of the same type for equality.
1213 * @param __lhs A %independent_bits_engine random number generator
1214 * object.
1215 * @param __rhs Another %independent_bits_engine random number generator
1216 * object.
1218 * @returns true if the infinite sequences of generated values
1219 * would be equal, false otherwise.
1221 friend bool
1222 operator==(const independent_bits_engine& __lhs,
1223 const independent_bits_engine& __rhs)
1224 { return __lhs._M_b == __rhs._M_b; }
1227 * @brief Extracts the current state of a % subtract_with_carry_engine
1228 * random number generator engine @p __x from the input stream
1229 * @p __is.
1231 * @param __is An input stream.
1232 * @param __x A %independent_bits_engine random number generator
1233 * engine.
1235 * @returns The input stream with the state of @p __x extracted or in
1236 * an error state.
1238 template<typename _CharT, typename _Traits>
1239 friend std::basic_istream<_CharT, _Traits>&
1240 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1241 std::independent_bits_engine<_RandomNumberEngine,
1242 __w, _UIntType>& __x)
1244 __is >> __x._M_b;
1245 return __is;
1248 private:
1249 _RandomNumberEngine _M_b;
1253 * @brief Compares two %independent_bits_engine random number generator
1254 * objects of the same type for inequality.
1256 * @param __lhs A %independent_bits_engine random number generator
1257 * object.
1258 * @param __rhs Another %independent_bits_engine random number generator
1259 * object.
1261 * @returns true if the infinite sequences of generated values
1262 * would be different, false otherwise.
1264 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1265 inline bool
1266 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1267 _UIntType>& __lhs,
1268 const std::independent_bits_engine<_RandomNumberEngine, __w,
1269 _UIntType>& __rhs)
1270 { return !(__lhs == __rhs); }
1273 * @brief Inserts the current state of a %independent_bits_engine random
1274 * number generator engine @p __x into the output stream @p __os.
1276 * @param __os An output stream.
1277 * @param __x A %independent_bits_engine random number generator engine.
1279 * @returns The output stream with the state of @p __x inserted or in
1280 * an error state.
1282 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1283 typename _CharT, typename _Traits>
1284 std::basic_ostream<_CharT, _Traits>&
1285 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1286 const std::independent_bits_engine<_RandomNumberEngine,
1287 __w, _UIntType>& __x)
1289 __os << __x.base();
1290 return __os;
1295 * @brief Produces random numbers by combining random numbers from some
1296 * base engine to produce random numbers with a specifies number of bits
1297 * @p __k.
1299 template<typename _RandomNumberEngine, size_t __k>
1300 class shuffle_order_engine
1302 static_assert(1u <= __k, "template argument substituting "
1303 "__k out of bound");
1305 public:
1306 /** The type of the generated random value. */
1307 typedef typename _RandomNumberEngine::result_type result_type;
1309 template<typename _Sseq>
1310 using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
1311 _Sseq, shuffle_order_engine, result_type>::value>::type;
1313 static constexpr size_t table_size = __k;
1316 * @brief Constructs a default %shuffle_order_engine engine.
1318 * The underlying engine is default constructed as well.
1320 shuffle_order_engine()
1321 : _M_b()
1322 { _M_initialize(); }
1325 * @brief Copy constructs a %shuffle_order_engine engine.
1327 * Copies an existing base class random number generator.
1328 * @param __rng An existing (base class) engine object.
1330 explicit
1331 shuffle_order_engine(const _RandomNumberEngine& __rng)
1332 : _M_b(__rng)
1333 { _M_initialize(); }
1336 * @brief Move constructs a %shuffle_order_engine engine.
1338 * Copies an existing base class random number generator.
1339 * @param __rng An existing (base class) engine object.
1341 explicit
1342 shuffle_order_engine(_RandomNumberEngine&& __rng)
1343 : _M_b(std::move(__rng))
1344 { _M_initialize(); }
1347 * @brief Seed constructs a %shuffle_order_engine engine.
1349 * Constructs the underlying generator engine seeded with @p __s.
1350 * @param __s A seed value for the base class engine.
1352 explicit
1353 shuffle_order_engine(result_type __s)
1354 : _M_b(__s)
1355 { _M_initialize(); }
1358 * @brief Generator construct a %shuffle_order_engine engine.
1360 * @param __q A seed sequence.
1362 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
1363 explicit
1364 shuffle_order_engine(_Sseq& __q)
1365 : _M_b(__q)
1366 { _M_initialize(); }
1369 * @brief Reseeds the %shuffle_order_engine object with the default seed
1370 for the underlying base class generator engine.
1372 void
1373 seed()
1375 _M_b.seed();
1376 _M_initialize();
1380 * @brief Reseeds the %shuffle_order_engine object with the default seed
1381 * for the underlying base class generator engine.
1383 void
1384 seed(result_type __s)
1386 _M_b.seed(__s);
1387 _M_initialize();
1391 * @brief Reseeds the %shuffle_order_engine object with the given seed
1392 * sequence.
1393 * @param __q A seed generator function.
1395 template<typename _Sseq>
1396 _If_seed_seq<_Sseq>
1397 seed(_Sseq& __q)
1399 _M_b.seed(__q);
1400 _M_initialize();
1404 * Gets a const reference to the underlying generator engine object.
1406 const _RandomNumberEngine&
1407 base() const noexcept
1408 { return _M_b; }
1411 * Gets the minimum value in the generated random number range.
1413 static constexpr result_type
1414 min()
1415 { return _RandomNumberEngine::min(); }
1418 * Gets the maximum value in the generated random number range.
1420 static constexpr result_type
1421 max()
1422 { return _RandomNumberEngine::max(); }
1425 * Discard a sequence of random numbers.
1427 void
1428 discard(unsigned long long __z)
1430 for (; __z != 0ULL; --__z)
1431 (*this)();
1435 * Gets the next value in the generated random number sequence.
1437 result_type
1438 operator()();
1441 * Compares two %shuffle_order_engine random number generator objects
1442 * of the same type for equality.
1444 * @param __lhs A %shuffle_order_engine random number generator object.
1445 * @param __rhs Another %shuffle_order_engine random number generator
1446 * object.
1448 * @returns true if the infinite sequences of generated values
1449 * would be equal, false otherwise.
1451 friend bool
1452 operator==(const shuffle_order_engine& __lhs,
1453 const shuffle_order_engine& __rhs)
1454 { return (__lhs._M_b == __rhs._M_b
1455 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1456 && __lhs._M_y == __rhs._M_y); }
1459 * @brief Inserts the current state of a %shuffle_order_engine random
1460 * number generator engine @p __x into the output stream
1461 @p __os.
1463 * @param __os An output stream.
1464 * @param __x A %shuffle_order_engine random number generator engine.
1466 * @returns The output stream with the state of @p __x inserted or in
1467 * an error state.
1469 template<typename _RandomNumberEngine1, size_t __k1,
1470 typename _CharT, typename _Traits>
1471 friend std::basic_ostream<_CharT, _Traits>&
1472 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1473 const std::shuffle_order_engine<_RandomNumberEngine1,
1474 __k1>& __x);
1477 * @brief Extracts the current state of a % subtract_with_carry_engine
1478 * random number generator engine @p __x from the input stream
1479 * @p __is.
1481 * @param __is An input stream.
1482 * @param __x A %shuffle_order_engine random number generator engine.
1484 * @returns The input stream with the state of @p __x extracted or in
1485 * an error state.
1487 template<typename _RandomNumberEngine1, size_t __k1,
1488 typename _CharT, typename _Traits>
1489 friend std::basic_istream<_CharT, _Traits>&
1490 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1491 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
1493 private:
1494 void _M_initialize()
1496 for (size_t __i = 0; __i < __k; ++__i)
1497 _M_v[__i] = _M_b();
1498 _M_y = _M_b();
1501 _RandomNumberEngine _M_b;
1502 result_type _M_v[__k];
1503 result_type _M_y;
1507 * Compares two %shuffle_order_engine random number generator objects
1508 * of the same type for inequality.
1510 * @param __lhs A %shuffle_order_engine random number generator object.
1511 * @param __rhs Another %shuffle_order_engine random number generator
1512 * object.
1514 * @returns true if the infinite sequences of generated values
1515 * would be different, false otherwise.
1517 template<typename _RandomNumberEngine, size_t __k>
1518 inline bool
1519 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1520 __k>& __lhs,
1521 const std::shuffle_order_engine<_RandomNumberEngine,
1522 __k>& __rhs)
1523 { return !(__lhs == __rhs); }
1527 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1529 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1530 minstd_rand0;
1533 * An alternative LCR (Lehmer Generator function).
1535 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1536 minstd_rand;
1539 * The classic Mersenne Twister.
1541 * Reference:
1542 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1543 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1544 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1546 typedef mersenne_twister_engine<
1547 uint_fast32_t,
1548 32, 624, 397, 31,
1549 0x9908b0dfUL, 11,
1550 0xffffffffUL, 7,
1551 0x9d2c5680UL, 15,
1552 0xefc60000UL, 18, 1812433253UL> mt19937;
1555 * An alternative Mersenne Twister.
1557 typedef mersenne_twister_engine<
1558 uint_fast64_t,
1559 64, 312, 156, 31,
1560 0xb5026f5aa96619e9ULL, 29,
1561 0x5555555555555555ULL, 17,
1562 0x71d67fffeda60000ULL, 37,
1563 0xfff7eee000000000ULL, 43,
1564 6364136223846793005ULL> mt19937_64;
1566 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1567 ranlux24_base;
1569 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1570 ranlux48_base;
1572 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1574 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1576 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1578 typedef minstd_rand0 default_random_engine;
1581 * A standard interface to a platform-specific non-deterministic
1582 * random number generator (if any are available).
1584 class random_device
1586 public:
1587 /** The type of the generated random value. */
1588 typedef unsigned int result_type;
1590 // constructors, destructors and member functions
1592 #ifdef _GLIBCXX_USE_RANDOM_TR1
1594 explicit
1595 random_device(const std::string& __token = "default")
1597 _M_init(__token);
1600 ~random_device()
1601 { _M_fini(); }
1603 #else
1605 explicit
1606 random_device(const std::string& __token = "mt19937")
1607 { _M_init_pretr1(__token); }
1609 public:
1611 #endif
1613 static constexpr result_type
1614 min()
1615 { return std::numeric_limits<result_type>::min(); }
1617 static constexpr result_type
1618 max()
1619 { return std::numeric_limits<result_type>::max(); }
1621 double
1622 entropy() const noexcept
1624 #ifdef _GLIBCXX_USE_RANDOM_TR1
1625 return this->_M_getentropy();
1626 #else
1627 return 0.0;
1628 #endif
1631 result_type
1632 operator()()
1634 #ifdef _GLIBCXX_USE_RANDOM_TR1
1635 return this->_M_getval();
1636 #else
1637 return this->_M_getval_pretr1();
1638 #endif
1641 // No copy functions.
1642 random_device(const random_device&) = delete;
1643 void operator=(const random_device&) = delete;
1645 private:
1647 void _M_init(const std::string& __token);
1648 void _M_init_pretr1(const std::string& __token);
1649 void _M_fini();
1651 result_type _M_getval();
1652 result_type _M_getval_pretr1();
1653 double _M_getentropy() const noexcept;
1655 union
1657 void* _M_file;
1658 mt19937 _M_mt;
1662 /* @} */ // group random_generators
1665 * @addtogroup random_distributions Random Number Distributions
1666 * @ingroup random
1667 * @{
1671 * @addtogroup random_distributions_uniform Uniform Distributions
1672 * @ingroup random_distributions
1673 * @{
1676 // std::uniform_int_distribution is defined in <bits/uniform_int_dist.h>
1679 * @brief Return true if two uniform integer distributions have
1680 * different parameters.
1682 template<typename _IntType>
1683 inline bool
1684 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1685 const std::uniform_int_distribution<_IntType>& __d2)
1686 { return !(__d1 == __d2); }
1689 * @brief Inserts a %uniform_int_distribution random number
1690 * distribution @p __x into the output stream @p os.
1692 * @param __os An output stream.
1693 * @param __x A %uniform_int_distribution random number distribution.
1695 * @returns The output stream with the state of @p __x inserted or in
1696 * an error state.
1698 template<typename _IntType, typename _CharT, typename _Traits>
1699 std::basic_ostream<_CharT, _Traits>&
1700 operator<<(std::basic_ostream<_CharT, _Traits>&,
1701 const std::uniform_int_distribution<_IntType>&);
1704 * @brief Extracts a %uniform_int_distribution random number distribution
1705 * @p __x from the input stream @p __is.
1707 * @param __is An input stream.
1708 * @param __x A %uniform_int_distribution random number generator engine.
1710 * @returns The input stream with @p __x extracted or in an error state.
1712 template<typename _IntType, typename _CharT, typename _Traits>
1713 std::basic_istream<_CharT, _Traits>&
1714 operator>>(std::basic_istream<_CharT, _Traits>&,
1715 std::uniform_int_distribution<_IntType>&);
1719 * @brief Uniform continuous distribution for random numbers.
1721 * A continuous random distribution on the range [min, max) with equal
1722 * probability throughout the range. The URNG should be real-valued and
1723 * deliver number in the range [0, 1).
1725 template<typename _RealType = double>
1726 class uniform_real_distribution
1728 static_assert(std::is_floating_point<_RealType>::value,
1729 "result_type must be a floating point type");
1731 public:
1732 /** The type of the range of the distribution. */
1733 typedef _RealType result_type;
1735 /** Parameter type. */
1736 struct param_type
1738 typedef uniform_real_distribution<_RealType> distribution_type;
1740 explicit
1741 param_type(_RealType __a = _RealType(0),
1742 _RealType __b = _RealType(1))
1743 : _M_a(__a), _M_b(__b)
1745 __glibcxx_assert(_M_a <= _M_b);
1748 result_type
1749 a() const
1750 { return _M_a; }
1752 result_type
1753 b() const
1754 { return _M_b; }
1756 friend bool
1757 operator==(const param_type& __p1, const param_type& __p2)
1758 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1760 friend bool
1761 operator!=(const param_type& __p1, const param_type& __p2)
1762 { return !(__p1 == __p2); }
1764 private:
1765 _RealType _M_a;
1766 _RealType _M_b;
1769 public:
1771 * @brief Constructs a uniform_real_distribution object.
1773 * @param __a [IN] The lower bound of the distribution.
1774 * @param __b [IN] The upper bound of the distribution.
1776 explicit
1777 uniform_real_distribution(_RealType __a = _RealType(0),
1778 _RealType __b = _RealType(1))
1779 : _M_param(__a, __b)
1782 explicit
1783 uniform_real_distribution(const param_type& __p)
1784 : _M_param(__p)
1788 * @brief Resets the distribution state.
1790 * Does nothing for the uniform real distribution.
1792 void
1793 reset() { }
1795 result_type
1796 a() const
1797 { return _M_param.a(); }
1799 result_type
1800 b() const
1801 { return _M_param.b(); }
1804 * @brief Returns the parameter set of the distribution.
1806 param_type
1807 param() const
1808 { return _M_param; }
1811 * @brief Sets the parameter set of the distribution.
1812 * @param __param The new parameter set of the distribution.
1814 void
1815 param(const param_type& __param)
1816 { _M_param = __param; }
1819 * @brief Returns the inclusive lower bound of the distribution range.
1821 result_type
1822 min() const
1823 { return this->a(); }
1826 * @brief Returns the inclusive upper bound of the distribution range.
1828 result_type
1829 max() const
1830 { return this->b(); }
1833 * @brief Generating functions.
1835 template<typename _UniformRandomNumberGenerator>
1836 result_type
1837 operator()(_UniformRandomNumberGenerator& __urng)
1838 { return this->operator()(__urng, _M_param); }
1840 template<typename _UniformRandomNumberGenerator>
1841 result_type
1842 operator()(_UniformRandomNumberGenerator& __urng,
1843 const param_type& __p)
1845 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1846 __aurng(__urng);
1847 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1850 template<typename _ForwardIterator,
1851 typename _UniformRandomNumberGenerator>
1852 void
1853 __generate(_ForwardIterator __f, _ForwardIterator __t,
1854 _UniformRandomNumberGenerator& __urng)
1855 { this->__generate(__f, __t, __urng, _M_param); }
1857 template<typename _ForwardIterator,
1858 typename _UniformRandomNumberGenerator>
1859 void
1860 __generate(_ForwardIterator __f, _ForwardIterator __t,
1861 _UniformRandomNumberGenerator& __urng,
1862 const param_type& __p)
1863 { this->__generate_impl(__f, __t, __urng, __p); }
1865 template<typename _UniformRandomNumberGenerator>
1866 void
1867 __generate(result_type* __f, result_type* __t,
1868 _UniformRandomNumberGenerator& __urng,
1869 const param_type& __p)
1870 { this->__generate_impl(__f, __t, __urng, __p); }
1873 * @brief Return true if two uniform real distributions have
1874 * the same parameters.
1876 friend bool
1877 operator==(const uniform_real_distribution& __d1,
1878 const uniform_real_distribution& __d2)
1879 { return __d1._M_param == __d2._M_param; }
1881 private:
1882 template<typename _ForwardIterator,
1883 typename _UniformRandomNumberGenerator>
1884 void
1885 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1886 _UniformRandomNumberGenerator& __urng,
1887 const param_type& __p);
1889 param_type _M_param;
1893 * @brief Return true if two uniform real distributions have
1894 * different parameters.
1896 template<typename _IntType>
1897 inline bool
1898 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1899 const std::uniform_real_distribution<_IntType>& __d2)
1900 { return !(__d1 == __d2); }
1903 * @brief Inserts a %uniform_real_distribution random number
1904 * distribution @p __x into the output stream @p __os.
1906 * @param __os An output stream.
1907 * @param __x A %uniform_real_distribution random number distribution.
1909 * @returns The output stream with the state of @p __x inserted or in
1910 * an error state.
1912 template<typename _RealType, typename _CharT, typename _Traits>
1913 std::basic_ostream<_CharT, _Traits>&
1914 operator<<(std::basic_ostream<_CharT, _Traits>&,
1915 const std::uniform_real_distribution<_RealType>&);
1918 * @brief Extracts a %uniform_real_distribution random number distribution
1919 * @p __x from the input stream @p __is.
1921 * @param __is An input stream.
1922 * @param __x A %uniform_real_distribution random number generator engine.
1924 * @returns The input stream with @p __x extracted or in an error state.
1926 template<typename _RealType, typename _CharT, typename _Traits>
1927 std::basic_istream<_CharT, _Traits>&
1928 operator>>(std::basic_istream<_CharT, _Traits>&,
1929 std::uniform_real_distribution<_RealType>&);
1931 /* @} */ // group random_distributions_uniform
1934 * @addtogroup random_distributions_normal Normal Distributions
1935 * @ingroup random_distributions
1936 * @{
1940 * @brief A normal continuous distribution for random numbers.
1942 * The formula for the normal probability density function is
1943 * @f[
1944 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1945 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1946 * @f]
1948 template<typename _RealType = double>
1949 class normal_distribution
1951 static_assert(std::is_floating_point<_RealType>::value,
1952 "result_type must be a floating point type");
1954 public:
1955 /** The type of the range of the distribution. */
1956 typedef _RealType result_type;
1958 /** Parameter type. */
1959 struct param_type
1961 typedef normal_distribution<_RealType> distribution_type;
1963 explicit
1964 param_type(_RealType __mean = _RealType(0),
1965 _RealType __stddev = _RealType(1))
1966 : _M_mean(__mean), _M_stddev(__stddev)
1968 __glibcxx_assert(_M_stddev > _RealType(0));
1971 _RealType
1972 mean() const
1973 { return _M_mean; }
1975 _RealType
1976 stddev() const
1977 { return _M_stddev; }
1979 friend bool
1980 operator==(const param_type& __p1, const param_type& __p2)
1981 { return (__p1._M_mean == __p2._M_mean
1982 && __p1._M_stddev == __p2._M_stddev); }
1984 friend bool
1985 operator!=(const param_type& __p1, const param_type& __p2)
1986 { return !(__p1 == __p2); }
1988 private:
1989 _RealType _M_mean;
1990 _RealType _M_stddev;
1993 public:
1995 * Constructs a normal distribution with parameters @f$mean@f$ and
1996 * standard deviation.
1998 explicit
1999 normal_distribution(result_type __mean = result_type(0),
2000 result_type __stddev = result_type(1))
2001 : _M_param(__mean, __stddev), _M_saved_available(false)
2004 explicit
2005 normal_distribution(const param_type& __p)
2006 : _M_param(__p), _M_saved_available(false)
2010 * @brief Resets the distribution state.
2012 void
2013 reset()
2014 { _M_saved_available = false; }
2017 * @brief Returns the mean of the distribution.
2019 _RealType
2020 mean() const
2021 { return _M_param.mean(); }
2024 * @brief Returns the standard deviation of the distribution.
2026 _RealType
2027 stddev() const
2028 { return _M_param.stddev(); }
2031 * @brief Returns the parameter set of the distribution.
2033 param_type
2034 param() const
2035 { return _M_param; }
2038 * @brief Sets the parameter set of the distribution.
2039 * @param __param The new parameter set of the distribution.
2041 void
2042 param(const param_type& __param)
2043 { _M_param = __param; }
2046 * @brief Returns the greatest lower bound value of the distribution.
2048 result_type
2049 min() const
2050 { return std::numeric_limits<result_type>::lowest(); }
2053 * @brief Returns the least upper bound value of the distribution.
2055 result_type
2056 max() const
2057 { return std::numeric_limits<result_type>::max(); }
2060 * @brief Generating functions.
2062 template<typename _UniformRandomNumberGenerator>
2063 result_type
2064 operator()(_UniformRandomNumberGenerator& __urng)
2065 { return this->operator()(__urng, _M_param); }
2067 template<typename _UniformRandomNumberGenerator>
2068 result_type
2069 operator()(_UniformRandomNumberGenerator& __urng,
2070 const param_type& __p);
2072 template<typename _ForwardIterator,
2073 typename _UniformRandomNumberGenerator>
2074 void
2075 __generate(_ForwardIterator __f, _ForwardIterator __t,
2076 _UniformRandomNumberGenerator& __urng)
2077 { this->__generate(__f, __t, __urng, _M_param); }
2079 template<typename _ForwardIterator,
2080 typename _UniformRandomNumberGenerator>
2081 void
2082 __generate(_ForwardIterator __f, _ForwardIterator __t,
2083 _UniformRandomNumberGenerator& __urng,
2084 const param_type& __p)
2085 { this->__generate_impl(__f, __t, __urng, __p); }
2087 template<typename _UniformRandomNumberGenerator>
2088 void
2089 __generate(result_type* __f, result_type* __t,
2090 _UniformRandomNumberGenerator& __urng,
2091 const param_type& __p)
2092 { this->__generate_impl(__f, __t, __urng, __p); }
2095 * @brief Return true if two normal distributions have
2096 * the same parameters and the sequences that would
2097 * be generated are equal.
2099 template<typename _RealType1>
2100 friend bool
2101 operator==(const std::normal_distribution<_RealType1>& __d1,
2102 const std::normal_distribution<_RealType1>& __d2);
2105 * @brief Inserts a %normal_distribution random number distribution
2106 * @p __x into the output stream @p __os.
2108 * @param __os An output stream.
2109 * @param __x A %normal_distribution random number distribution.
2111 * @returns The output stream with the state of @p __x inserted or in
2112 * an error state.
2114 template<typename _RealType1, typename _CharT, typename _Traits>
2115 friend std::basic_ostream<_CharT, _Traits>&
2116 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2117 const std::normal_distribution<_RealType1>& __x);
2120 * @brief Extracts a %normal_distribution random number distribution
2121 * @p __x from the input stream @p __is.
2123 * @param __is An input stream.
2124 * @param __x A %normal_distribution random number generator engine.
2126 * @returns The input stream with @p __x extracted or in an error
2127 * state.
2129 template<typename _RealType1, typename _CharT, typename _Traits>
2130 friend std::basic_istream<_CharT, _Traits>&
2131 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2132 std::normal_distribution<_RealType1>& __x);
2134 private:
2135 template<typename _ForwardIterator,
2136 typename _UniformRandomNumberGenerator>
2137 void
2138 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2139 _UniformRandomNumberGenerator& __urng,
2140 const param_type& __p);
2142 param_type _M_param;
2143 result_type _M_saved;
2144 bool _M_saved_available;
2148 * @brief Return true if two normal distributions are different.
2150 template<typename _RealType>
2151 inline bool
2152 operator!=(const std::normal_distribution<_RealType>& __d1,
2153 const std::normal_distribution<_RealType>& __d2)
2154 { return !(__d1 == __d2); }
2158 * @brief A lognormal_distribution random number distribution.
2160 * The formula for the normal probability mass function is
2161 * @f[
2162 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2163 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2164 * @f]
2166 template<typename _RealType = double>
2167 class lognormal_distribution
2169 static_assert(std::is_floating_point<_RealType>::value,
2170 "result_type must be a floating point type");
2172 public:
2173 /** The type of the range of the distribution. */
2174 typedef _RealType result_type;
2176 /** Parameter type. */
2177 struct param_type
2179 typedef lognormal_distribution<_RealType> distribution_type;
2181 explicit
2182 param_type(_RealType __m = _RealType(0),
2183 _RealType __s = _RealType(1))
2184 : _M_m(__m), _M_s(__s)
2187 _RealType
2188 m() const
2189 { return _M_m; }
2191 _RealType
2192 s() const
2193 { return _M_s; }
2195 friend bool
2196 operator==(const param_type& __p1, const param_type& __p2)
2197 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2199 friend bool
2200 operator!=(const param_type& __p1, const param_type& __p2)
2201 { return !(__p1 == __p2); }
2203 private:
2204 _RealType _M_m;
2205 _RealType _M_s;
2208 explicit
2209 lognormal_distribution(_RealType __m = _RealType(0),
2210 _RealType __s = _RealType(1))
2211 : _M_param(__m, __s), _M_nd()
2214 explicit
2215 lognormal_distribution(const param_type& __p)
2216 : _M_param(__p), _M_nd()
2220 * Resets the distribution state.
2222 void
2223 reset()
2224 { _M_nd.reset(); }
2229 _RealType
2230 m() const
2231 { return _M_param.m(); }
2233 _RealType
2234 s() const
2235 { return _M_param.s(); }
2238 * @brief Returns the parameter set of the distribution.
2240 param_type
2241 param() const
2242 { return _M_param; }
2245 * @brief Sets the parameter set of the distribution.
2246 * @param __param The new parameter set of the distribution.
2248 void
2249 param(const param_type& __param)
2250 { _M_param = __param; }
2253 * @brief Returns the greatest lower bound value of the distribution.
2255 result_type
2256 min() const
2257 { return result_type(0); }
2260 * @brief Returns the least upper bound value of the distribution.
2262 result_type
2263 max() const
2264 { return std::numeric_limits<result_type>::max(); }
2267 * @brief Generating functions.
2269 template<typename _UniformRandomNumberGenerator>
2270 result_type
2271 operator()(_UniformRandomNumberGenerator& __urng)
2272 { return this->operator()(__urng, _M_param); }
2274 template<typename _UniformRandomNumberGenerator>
2275 result_type
2276 operator()(_UniformRandomNumberGenerator& __urng,
2277 const param_type& __p)
2278 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2280 template<typename _ForwardIterator,
2281 typename _UniformRandomNumberGenerator>
2282 void
2283 __generate(_ForwardIterator __f, _ForwardIterator __t,
2284 _UniformRandomNumberGenerator& __urng)
2285 { this->__generate(__f, __t, __urng, _M_param); }
2287 template<typename _ForwardIterator,
2288 typename _UniformRandomNumberGenerator>
2289 void
2290 __generate(_ForwardIterator __f, _ForwardIterator __t,
2291 _UniformRandomNumberGenerator& __urng,
2292 const param_type& __p)
2293 { this->__generate_impl(__f, __t, __urng, __p); }
2295 template<typename _UniformRandomNumberGenerator>
2296 void
2297 __generate(result_type* __f, result_type* __t,
2298 _UniformRandomNumberGenerator& __urng,
2299 const param_type& __p)
2300 { this->__generate_impl(__f, __t, __urng, __p); }
2303 * @brief Return true if two lognormal distributions have
2304 * the same parameters and the sequences that would
2305 * be generated are equal.
2307 friend bool
2308 operator==(const lognormal_distribution& __d1,
2309 const lognormal_distribution& __d2)
2310 { return (__d1._M_param == __d2._M_param
2311 && __d1._M_nd == __d2._M_nd); }
2314 * @brief Inserts a %lognormal_distribution random number distribution
2315 * @p __x into the output stream @p __os.
2317 * @param __os An output stream.
2318 * @param __x A %lognormal_distribution random number distribution.
2320 * @returns The output stream with the state of @p __x inserted or in
2321 * an error state.
2323 template<typename _RealType1, typename _CharT, typename _Traits>
2324 friend std::basic_ostream<_CharT, _Traits>&
2325 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2326 const std::lognormal_distribution<_RealType1>& __x);
2329 * @brief Extracts a %lognormal_distribution random number distribution
2330 * @p __x from the input stream @p __is.
2332 * @param __is An input stream.
2333 * @param __x A %lognormal_distribution random number
2334 * generator engine.
2336 * @returns The input stream with @p __x extracted or in an error state.
2338 template<typename _RealType1, typename _CharT, typename _Traits>
2339 friend std::basic_istream<_CharT, _Traits>&
2340 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2341 std::lognormal_distribution<_RealType1>& __x);
2343 private:
2344 template<typename _ForwardIterator,
2345 typename _UniformRandomNumberGenerator>
2346 void
2347 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2348 _UniformRandomNumberGenerator& __urng,
2349 const param_type& __p);
2351 param_type _M_param;
2353 std::normal_distribution<result_type> _M_nd;
2357 * @brief Return true if two lognormal distributions are different.
2359 template<typename _RealType>
2360 inline bool
2361 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2362 const std::lognormal_distribution<_RealType>& __d2)
2363 { return !(__d1 == __d2); }
2367 * @brief A gamma continuous distribution for random numbers.
2369 * The formula for the gamma probability density function is:
2370 * @f[
2371 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2372 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2373 * @f]
2375 template<typename _RealType = double>
2376 class gamma_distribution
2378 static_assert(std::is_floating_point<_RealType>::value,
2379 "result_type must be a floating point type");
2381 public:
2382 /** The type of the range of the distribution. */
2383 typedef _RealType result_type;
2385 /** Parameter type. */
2386 struct param_type
2388 typedef gamma_distribution<_RealType> distribution_type;
2389 friend class gamma_distribution<_RealType>;
2391 explicit
2392 param_type(_RealType __alpha_val = _RealType(1),
2393 _RealType __beta_val = _RealType(1))
2394 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2396 __glibcxx_assert(_M_alpha > _RealType(0));
2397 _M_initialize();
2400 _RealType
2401 alpha() const
2402 { return _M_alpha; }
2404 _RealType
2405 beta() const
2406 { return _M_beta; }
2408 friend bool
2409 operator==(const param_type& __p1, const param_type& __p2)
2410 { return (__p1._M_alpha == __p2._M_alpha
2411 && __p1._M_beta == __p2._M_beta); }
2413 friend bool
2414 operator!=(const param_type& __p1, const param_type& __p2)
2415 { return !(__p1 == __p2); }
2417 private:
2418 void
2419 _M_initialize();
2421 _RealType _M_alpha;
2422 _RealType _M_beta;
2424 _RealType _M_malpha, _M_a2;
2427 public:
2429 * @brief Constructs a gamma distribution with parameters
2430 * @f$\alpha@f$ and @f$\beta@f$.
2432 explicit
2433 gamma_distribution(_RealType __alpha_val = _RealType(1),
2434 _RealType __beta_val = _RealType(1))
2435 : _M_param(__alpha_val, __beta_val), _M_nd()
2438 explicit
2439 gamma_distribution(const param_type& __p)
2440 : _M_param(__p), _M_nd()
2444 * @brief Resets the distribution state.
2446 void
2447 reset()
2448 { _M_nd.reset(); }
2451 * @brief Returns the @f$\alpha@f$ of the distribution.
2453 _RealType
2454 alpha() const
2455 { return _M_param.alpha(); }
2458 * @brief Returns the @f$\beta@f$ of the distribution.
2460 _RealType
2461 beta() const
2462 { return _M_param.beta(); }
2465 * @brief Returns the parameter set of the distribution.
2467 param_type
2468 param() const
2469 { return _M_param; }
2472 * @brief Sets the parameter set of the distribution.
2473 * @param __param The new parameter set of the distribution.
2475 void
2476 param(const param_type& __param)
2477 { _M_param = __param; }
2480 * @brief Returns the greatest lower bound value of the distribution.
2482 result_type
2483 min() const
2484 { return result_type(0); }
2487 * @brief Returns the least upper bound value of the distribution.
2489 result_type
2490 max() const
2491 { return std::numeric_limits<result_type>::max(); }
2494 * @brief Generating functions.
2496 template<typename _UniformRandomNumberGenerator>
2497 result_type
2498 operator()(_UniformRandomNumberGenerator& __urng)
2499 { return this->operator()(__urng, _M_param); }
2501 template<typename _UniformRandomNumberGenerator>
2502 result_type
2503 operator()(_UniformRandomNumberGenerator& __urng,
2504 const param_type& __p);
2506 template<typename _ForwardIterator,
2507 typename _UniformRandomNumberGenerator>
2508 void
2509 __generate(_ForwardIterator __f, _ForwardIterator __t,
2510 _UniformRandomNumberGenerator& __urng)
2511 { this->__generate(__f, __t, __urng, _M_param); }
2513 template<typename _ForwardIterator,
2514 typename _UniformRandomNumberGenerator>
2515 void
2516 __generate(_ForwardIterator __f, _ForwardIterator __t,
2517 _UniformRandomNumberGenerator& __urng,
2518 const param_type& __p)
2519 { this->__generate_impl(__f, __t, __urng, __p); }
2521 template<typename _UniformRandomNumberGenerator>
2522 void
2523 __generate(result_type* __f, result_type* __t,
2524 _UniformRandomNumberGenerator& __urng,
2525 const param_type& __p)
2526 { this->__generate_impl(__f, __t, __urng, __p); }
2529 * @brief Return true if two gamma distributions have the same
2530 * parameters and the sequences that would be generated
2531 * are equal.
2533 friend bool
2534 operator==(const gamma_distribution& __d1,
2535 const gamma_distribution& __d2)
2536 { return (__d1._M_param == __d2._M_param
2537 && __d1._M_nd == __d2._M_nd); }
2540 * @brief Inserts a %gamma_distribution random number distribution
2541 * @p __x into the output stream @p __os.
2543 * @param __os An output stream.
2544 * @param __x A %gamma_distribution random number distribution.
2546 * @returns The output stream with the state of @p __x inserted or in
2547 * an error state.
2549 template<typename _RealType1, typename _CharT, typename _Traits>
2550 friend std::basic_ostream<_CharT, _Traits>&
2551 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2552 const std::gamma_distribution<_RealType1>& __x);
2555 * @brief Extracts a %gamma_distribution random number distribution
2556 * @p __x from the input stream @p __is.
2558 * @param __is An input stream.
2559 * @param __x A %gamma_distribution random number generator engine.
2561 * @returns The input stream with @p __x extracted or in an error state.
2563 template<typename _RealType1, typename _CharT, typename _Traits>
2564 friend std::basic_istream<_CharT, _Traits>&
2565 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2566 std::gamma_distribution<_RealType1>& __x);
2568 private:
2569 template<typename _ForwardIterator,
2570 typename _UniformRandomNumberGenerator>
2571 void
2572 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2573 _UniformRandomNumberGenerator& __urng,
2574 const param_type& __p);
2576 param_type _M_param;
2578 std::normal_distribution<result_type> _M_nd;
2582 * @brief Return true if two gamma distributions are different.
2584 template<typename _RealType>
2585 inline bool
2586 operator!=(const std::gamma_distribution<_RealType>& __d1,
2587 const std::gamma_distribution<_RealType>& __d2)
2588 { return !(__d1 == __d2); }
2592 * @brief A chi_squared_distribution random number distribution.
2594 * The formula for the normal probability mass function is
2595 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2597 template<typename _RealType = double>
2598 class chi_squared_distribution
2600 static_assert(std::is_floating_point<_RealType>::value,
2601 "result_type must be a floating point type");
2603 public:
2604 /** The type of the range of the distribution. */
2605 typedef _RealType result_type;
2607 /** Parameter type. */
2608 struct param_type
2610 typedef chi_squared_distribution<_RealType> distribution_type;
2612 explicit
2613 param_type(_RealType __n = _RealType(1))
2614 : _M_n(__n)
2617 _RealType
2618 n() const
2619 { return _M_n; }
2621 friend bool
2622 operator==(const param_type& __p1, const param_type& __p2)
2623 { return __p1._M_n == __p2._M_n; }
2625 friend bool
2626 operator!=(const param_type& __p1, const param_type& __p2)
2627 { return !(__p1 == __p2); }
2629 private:
2630 _RealType _M_n;
2633 explicit
2634 chi_squared_distribution(_RealType __n = _RealType(1))
2635 : _M_param(__n), _M_gd(__n / 2)
2638 explicit
2639 chi_squared_distribution(const param_type& __p)
2640 : _M_param(__p), _M_gd(__p.n() / 2)
2644 * @brief Resets the distribution state.
2646 void
2647 reset()
2648 { _M_gd.reset(); }
2653 _RealType
2654 n() const
2655 { return _M_param.n(); }
2658 * @brief Returns the parameter set of the distribution.
2660 param_type
2661 param() const
2662 { return _M_param; }
2665 * @brief Sets the parameter set of the distribution.
2666 * @param __param The new parameter set of the distribution.
2668 void
2669 param(const param_type& __param)
2671 _M_param = __param;
2672 typedef typename std::gamma_distribution<result_type>::param_type
2673 param_type;
2674 _M_gd.param(param_type{__param.n() / 2});
2678 * @brief Returns the greatest lower bound value of the distribution.
2680 result_type
2681 min() const
2682 { return result_type(0); }
2685 * @brief Returns the least upper bound value of the distribution.
2687 result_type
2688 max() const
2689 { return std::numeric_limits<result_type>::max(); }
2692 * @brief Generating functions.
2694 template<typename _UniformRandomNumberGenerator>
2695 result_type
2696 operator()(_UniformRandomNumberGenerator& __urng)
2697 { return 2 * _M_gd(__urng); }
2699 template<typename _UniformRandomNumberGenerator>
2700 result_type
2701 operator()(_UniformRandomNumberGenerator& __urng,
2702 const param_type& __p)
2704 typedef typename std::gamma_distribution<result_type>::param_type
2705 param_type;
2706 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2709 template<typename _ForwardIterator,
2710 typename _UniformRandomNumberGenerator>
2711 void
2712 __generate(_ForwardIterator __f, _ForwardIterator __t,
2713 _UniformRandomNumberGenerator& __urng)
2714 { this->__generate_impl(__f, __t, __urng); }
2716 template<typename _ForwardIterator,
2717 typename _UniformRandomNumberGenerator>
2718 void
2719 __generate(_ForwardIterator __f, _ForwardIterator __t,
2720 _UniformRandomNumberGenerator& __urng,
2721 const param_type& __p)
2722 { typename std::gamma_distribution<result_type>::param_type
2723 __p2(__p.n() / 2);
2724 this->__generate_impl(__f, __t, __urng, __p2); }
2726 template<typename _UniformRandomNumberGenerator>
2727 void
2728 __generate(result_type* __f, result_type* __t,
2729 _UniformRandomNumberGenerator& __urng)
2730 { this->__generate_impl(__f, __t, __urng); }
2732 template<typename _UniformRandomNumberGenerator>
2733 void
2734 __generate(result_type* __f, result_type* __t,
2735 _UniformRandomNumberGenerator& __urng,
2736 const param_type& __p)
2737 { typename std::gamma_distribution<result_type>::param_type
2738 __p2(__p.n() / 2);
2739 this->__generate_impl(__f, __t, __urng, __p2); }
2742 * @brief Return true if two Chi-squared distributions have
2743 * the same parameters and the sequences that would be
2744 * generated are equal.
2746 friend bool
2747 operator==(const chi_squared_distribution& __d1,
2748 const chi_squared_distribution& __d2)
2749 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
2752 * @brief Inserts a %chi_squared_distribution random number distribution
2753 * @p __x into the output stream @p __os.
2755 * @param __os An output stream.
2756 * @param __x A %chi_squared_distribution random number distribution.
2758 * @returns The output stream with the state of @p __x inserted or in
2759 * an error state.
2761 template<typename _RealType1, typename _CharT, typename _Traits>
2762 friend std::basic_ostream<_CharT, _Traits>&
2763 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2764 const std::chi_squared_distribution<_RealType1>& __x);
2767 * @brief Extracts a %chi_squared_distribution random number distribution
2768 * @p __x from the input stream @p __is.
2770 * @param __is An input stream.
2771 * @param __x A %chi_squared_distribution random number
2772 * generator engine.
2774 * @returns The input stream with @p __x extracted or in an error state.
2776 template<typename _RealType1, typename _CharT, typename _Traits>
2777 friend std::basic_istream<_CharT, _Traits>&
2778 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2779 std::chi_squared_distribution<_RealType1>& __x);
2781 private:
2782 template<typename _ForwardIterator,
2783 typename _UniformRandomNumberGenerator>
2784 void
2785 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2786 _UniformRandomNumberGenerator& __urng);
2788 template<typename _ForwardIterator,
2789 typename _UniformRandomNumberGenerator>
2790 void
2791 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2792 _UniformRandomNumberGenerator& __urng,
2793 const typename
2794 std::gamma_distribution<result_type>::param_type& __p);
2796 param_type _M_param;
2798 std::gamma_distribution<result_type> _M_gd;
2802 * @brief Return true if two Chi-squared distributions are different.
2804 template<typename _RealType>
2805 inline bool
2806 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2807 const std::chi_squared_distribution<_RealType>& __d2)
2808 { return !(__d1 == __d2); }
2812 * @brief A cauchy_distribution random number distribution.
2814 * The formula for the normal probability mass function is
2815 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2817 template<typename _RealType = double>
2818 class cauchy_distribution
2820 static_assert(std::is_floating_point<_RealType>::value,
2821 "result_type must be a floating point type");
2823 public:
2824 /** The type of the range of the distribution. */
2825 typedef _RealType result_type;
2827 /** Parameter type. */
2828 struct param_type
2830 typedef cauchy_distribution<_RealType> distribution_type;
2832 explicit
2833 param_type(_RealType __a = _RealType(0),
2834 _RealType __b = _RealType(1))
2835 : _M_a(__a), _M_b(__b)
2838 _RealType
2839 a() const
2840 { return _M_a; }
2842 _RealType
2843 b() const
2844 { return _M_b; }
2846 friend bool
2847 operator==(const param_type& __p1, const param_type& __p2)
2848 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2850 friend bool
2851 operator!=(const param_type& __p1, const param_type& __p2)
2852 { return !(__p1 == __p2); }
2854 private:
2855 _RealType _M_a;
2856 _RealType _M_b;
2859 explicit
2860 cauchy_distribution(_RealType __a = _RealType(0),
2861 _RealType __b = _RealType(1))
2862 : _M_param(__a, __b)
2865 explicit
2866 cauchy_distribution(const param_type& __p)
2867 : _M_param(__p)
2871 * @brief Resets the distribution state.
2873 void
2874 reset()
2880 _RealType
2881 a() const
2882 { return _M_param.a(); }
2884 _RealType
2885 b() const
2886 { return _M_param.b(); }
2889 * @brief Returns the parameter set of the distribution.
2891 param_type
2892 param() const
2893 { return _M_param; }
2896 * @brief Sets the parameter set of the distribution.
2897 * @param __param The new parameter set of the distribution.
2899 void
2900 param(const param_type& __param)
2901 { _M_param = __param; }
2904 * @brief Returns the greatest lower bound value of the distribution.
2906 result_type
2907 min() const
2908 { return std::numeric_limits<result_type>::lowest(); }
2911 * @brief Returns the least upper bound value of the distribution.
2913 result_type
2914 max() const
2915 { return std::numeric_limits<result_type>::max(); }
2918 * @brief Generating functions.
2920 template<typename _UniformRandomNumberGenerator>
2921 result_type
2922 operator()(_UniformRandomNumberGenerator& __urng)
2923 { return this->operator()(__urng, _M_param); }
2925 template<typename _UniformRandomNumberGenerator>
2926 result_type
2927 operator()(_UniformRandomNumberGenerator& __urng,
2928 const param_type& __p);
2930 template<typename _ForwardIterator,
2931 typename _UniformRandomNumberGenerator>
2932 void
2933 __generate(_ForwardIterator __f, _ForwardIterator __t,
2934 _UniformRandomNumberGenerator& __urng)
2935 { this->__generate(__f, __t, __urng, _M_param); }
2937 template<typename _ForwardIterator,
2938 typename _UniformRandomNumberGenerator>
2939 void
2940 __generate(_ForwardIterator __f, _ForwardIterator __t,
2941 _UniformRandomNumberGenerator& __urng,
2942 const param_type& __p)
2943 { this->__generate_impl(__f, __t, __urng, __p); }
2945 template<typename _UniformRandomNumberGenerator>
2946 void
2947 __generate(result_type* __f, result_type* __t,
2948 _UniformRandomNumberGenerator& __urng,
2949 const param_type& __p)
2950 { this->__generate_impl(__f, __t, __urng, __p); }
2953 * @brief Return true if two Cauchy distributions have
2954 * the same parameters.
2956 friend bool
2957 operator==(const cauchy_distribution& __d1,
2958 const cauchy_distribution& __d2)
2959 { return __d1._M_param == __d2._M_param; }
2961 private:
2962 template<typename _ForwardIterator,
2963 typename _UniformRandomNumberGenerator>
2964 void
2965 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2966 _UniformRandomNumberGenerator& __urng,
2967 const param_type& __p);
2969 param_type _M_param;
2973 * @brief Return true if two Cauchy distributions have
2974 * different parameters.
2976 template<typename _RealType>
2977 inline bool
2978 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2979 const std::cauchy_distribution<_RealType>& __d2)
2980 { return !(__d1 == __d2); }
2983 * @brief Inserts a %cauchy_distribution random number distribution
2984 * @p __x into the output stream @p __os.
2986 * @param __os An output stream.
2987 * @param __x A %cauchy_distribution random number distribution.
2989 * @returns The output stream with the state of @p __x inserted or in
2990 * an error state.
2992 template<typename _RealType, typename _CharT, typename _Traits>
2993 std::basic_ostream<_CharT, _Traits>&
2994 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2995 const std::cauchy_distribution<_RealType>& __x);
2998 * @brief Extracts a %cauchy_distribution random number distribution
2999 * @p __x from the input stream @p __is.
3001 * @param __is An input stream.
3002 * @param __x A %cauchy_distribution random number
3003 * generator engine.
3005 * @returns The input stream with @p __x extracted or in an error state.
3007 template<typename _RealType, typename _CharT, typename _Traits>
3008 std::basic_istream<_CharT, _Traits>&
3009 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3010 std::cauchy_distribution<_RealType>& __x);
3014 * @brief A fisher_f_distribution random number distribution.
3016 * The formula for the normal probability mass function is
3017 * @f[
3018 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
3019 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
3020 * (1 + \frac{mx}{n})^{-(m+n)/2}
3021 * @f]
3023 template<typename _RealType = double>
3024 class fisher_f_distribution
3026 static_assert(std::is_floating_point<_RealType>::value,
3027 "result_type must be a floating point type");
3029 public:
3030 /** The type of the range of the distribution. */
3031 typedef _RealType result_type;
3033 /** Parameter type. */
3034 struct param_type
3036 typedef fisher_f_distribution<_RealType> distribution_type;
3038 explicit
3039 param_type(_RealType __m = _RealType(1),
3040 _RealType __n = _RealType(1))
3041 : _M_m(__m), _M_n(__n)
3044 _RealType
3045 m() const
3046 { return _M_m; }
3048 _RealType
3049 n() const
3050 { return _M_n; }
3052 friend bool
3053 operator==(const param_type& __p1, const param_type& __p2)
3054 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
3056 friend bool
3057 operator!=(const param_type& __p1, const param_type& __p2)
3058 { return !(__p1 == __p2); }
3060 private:
3061 _RealType _M_m;
3062 _RealType _M_n;
3065 explicit
3066 fisher_f_distribution(_RealType __m = _RealType(1),
3067 _RealType __n = _RealType(1))
3068 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
3071 explicit
3072 fisher_f_distribution(const param_type& __p)
3073 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
3077 * @brief Resets the distribution state.
3079 void
3080 reset()
3082 _M_gd_x.reset();
3083 _M_gd_y.reset();
3089 _RealType
3090 m() const
3091 { return _M_param.m(); }
3093 _RealType
3094 n() const
3095 { return _M_param.n(); }
3098 * @brief Returns the parameter set of the distribution.
3100 param_type
3101 param() const
3102 { return _M_param; }
3105 * @brief Sets the parameter set of the distribution.
3106 * @param __param The new parameter set of the distribution.
3108 void
3109 param(const param_type& __param)
3110 { _M_param = __param; }
3113 * @brief Returns the greatest lower bound value of the distribution.
3115 result_type
3116 min() const
3117 { return result_type(0); }
3120 * @brief Returns the least upper bound value of the distribution.
3122 result_type
3123 max() const
3124 { return std::numeric_limits<result_type>::max(); }
3127 * @brief Generating functions.
3129 template<typename _UniformRandomNumberGenerator>
3130 result_type
3131 operator()(_UniformRandomNumberGenerator& __urng)
3132 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
3134 template<typename _UniformRandomNumberGenerator>
3135 result_type
3136 operator()(_UniformRandomNumberGenerator& __urng,
3137 const param_type& __p)
3139 typedef typename std::gamma_distribution<result_type>::param_type
3140 param_type;
3141 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
3142 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
3145 template<typename _ForwardIterator,
3146 typename _UniformRandomNumberGenerator>
3147 void
3148 __generate(_ForwardIterator __f, _ForwardIterator __t,
3149 _UniformRandomNumberGenerator& __urng)
3150 { this->__generate_impl(__f, __t, __urng); }
3152 template<typename _ForwardIterator,
3153 typename _UniformRandomNumberGenerator>
3154 void
3155 __generate(_ForwardIterator __f, _ForwardIterator __t,
3156 _UniformRandomNumberGenerator& __urng,
3157 const param_type& __p)
3158 { this->__generate_impl(__f, __t, __urng, __p); }
3160 template<typename _UniformRandomNumberGenerator>
3161 void
3162 __generate(result_type* __f, result_type* __t,
3163 _UniformRandomNumberGenerator& __urng)
3164 { this->__generate_impl(__f, __t, __urng); }
3166 template<typename _UniformRandomNumberGenerator>
3167 void
3168 __generate(result_type* __f, result_type* __t,
3169 _UniformRandomNumberGenerator& __urng,
3170 const param_type& __p)
3171 { this->__generate_impl(__f, __t, __urng, __p); }
3174 * @brief Return true if two Fisher f distributions have
3175 * the same parameters and the sequences that would
3176 * be generated are equal.
3178 friend bool
3179 operator==(const fisher_f_distribution& __d1,
3180 const fisher_f_distribution& __d2)
3181 { return (__d1._M_param == __d2._M_param
3182 && __d1._M_gd_x == __d2._M_gd_x
3183 && __d1._M_gd_y == __d2._M_gd_y); }
3186 * @brief Inserts a %fisher_f_distribution random number distribution
3187 * @p __x into the output stream @p __os.
3189 * @param __os An output stream.
3190 * @param __x A %fisher_f_distribution random number distribution.
3192 * @returns The output stream with the state of @p __x inserted or in
3193 * an error state.
3195 template<typename _RealType1, typename _CharT, typename _Traits>
3196 friend std::basic_ostream<_CharT, _Traits>&
3197 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3198 const std::fisher_f_distribution<_RealType1>& __x);
3201 * @brief Extracts a %fisher_f_distribution random number distribution
3202 * @p __x from the input stream @p __is.
3204 * @param __is An input stream.
3205 * @param __x A %fisher_f_distribution random number
3206 * generator engine.
3208 * @returns The input stream with @p __x extracted or in an error state.
3210 template<typename _RealType1, typename _CharT, typename _Traits>
3211 friend std::basic_istream<_CharT, _Traits>&
3212 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3213 std::fisher_f_distribution<_RealType1>& __x);
3215 private:
3216 template<typename _ForwardIterator,
3217 typename _UniformRandomNumberGenerator>
3218 void
3219 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3220 _UniformRandomNumberGenerator& __urng);
3222 template<typename _ForwardIterator,
3223 typename _UniformRandomNumberGenerator>
3224 void
3225 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3226 _UniformRandomNumberGenerator& __urng,
3227 const param_type& __p);
3229 param_type _M_param;
3231 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3235 * @brief Return true if two Fisher f distributions are different.
3237 template<typename _RealType>
3238 inline bool
3239 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3240 const std::fisher_f_distribution<_RealType>& __d2)
3241 { return !(__d1 == __d2); }
3244 * @brief A student_t_distribution random number distribution.
3246 * The formula for the normal probability mass function is:
3247 * @f[
3248 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3249 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3250 * @f]
3252 template<typename _RealType = double>
3253 class student_t_distribution
3255 static_assert(std::is_floating_point<_RealType>::value,
3256 "result_type must be a floating point type");
3258 public:
3259 /** The type of the range of the distribution. */
3260 typedef _RealType result_type;
3262 /** Parameter type. */
3263 struct param_type
3265 typedef student_t_distribution<_RealType> distribution_type;
3267 explicit
3268 param_type(_RealType __n = _RealType(1))
3269 : _M_n(__n)
3272 _RealType
3273 n() const
3274 { return _M_n; }
3276 friend bool
3277 operator==(const param_type& __p1, const param_type& __p2)
3278 { return __p1._M_n == __p2._M_n; }
3280 friend bool
3281 operator!=(const param_type& __p1, const param_type& __p2)
3282 { return !(__p1 == __p2); }
3284 private:
3285 _RealType _M_n;
3288 explicit
3289 student_t_distribution(_RealType __n = _RealType(1))
3290 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3293 explicit
3294 student_t_distribution(const param_type& __p)
3295 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3299 * @brief Resets the distribution state.
3301 void
3302 reset()
3304 _M_nd.reset();
3305 _M_gd.reset();
3311 _RealType
3312 n() const
3313 { return _M_param.n(); }
3316 * @brief Returns the parameter set of the distribution.
3318 param_type
3319 param() const
3320 { return _M_param; }
3323 * @brief Sets the parameter set of the distribution.
3324 * @param __param The new parameter set of the distribution.
3326 void
3327 param(const param_type& __param)
3328 { _M_param = __param; }
3331 * @brief Returns the greatest lower bound value of the distribution.
3333 result_type
3334 min() const
3335 { return std::numeric_limits<result_type>::lowest(); }
3338 * @brief Returns the least upper bound value of the distribution.
3340 result_type
3341 max() const
3342 { return std::numeric_limits<result_type>::max(); }
3345 * @brief Generating functions.
3347 template<typename _UniformRandomNumberGenerator>
3348 result_type
3349 operator()(_UniformRandomNumberGenerator& __urng)
3350 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3352 template<typename _UniformRandomNumberGenerator>
3353 result_type
3354 operator()(_UniformRandomNumberGenerator& __urng,
3355 const param_type& __p)
3357 typedef typename std::gamma_distribution<result_type>::param_type
3358 param_type;
3360 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3361 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3364 template<typename _ForwardIterator,
3365 typename _UniformRandomNumberGenerator>
3366 void
3367 __generate(_ForwardIterator __f, _ForwardIterator __t,
3368 _UniformRandomNumberGenerator& __urng)
3369 { this->__generate_impl(__f, __t, __urng); }
3371 template<typename _ForwardIterator,
3372 typename _UniformRandomNumberGenerator>
3373 void
3374 __generate(_ForwardIterator __f, _ForwardIterator __t,
3375 _UniformRandomNumberGenerator& __urng,
3376 const param_type& __p)
3377 { this->__generate_impl(__f, __t, __urng, __p); }
3379 template<typename _UniformRandomNumberGenerator>
3380 void
3381 __generate(result_type* __f, result_type* __t,
3382 _UniformRandomNumberGenerator& __urng)
3383 { this->__generate_impl(__f, __t, __urng); }
3385 template<typename _UniformRandomNumberGenerator>
3386 void
3387 __generate(result_type* __f, result_type* __t,
3388 _UniformRandomNumberGenerator& __urng,
3389 const param_type& __p)
3390 { this->__generate_impl(__f, __t, __urng, __p); }
3393 * @brief Return true if two Student t distributions have
3394 * the same parameters and the sequences that would
3395 * be generated are equal.
3397 friend bool
3398 operator==(const student_t_distribution& __d1,
3399 const student_t_distribution& __d2)
3400 { return (__d1._M_param == __d2._M_param
3401 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3404 * @brief Inserts a %student_t_distribution random number distribution
3405 * @p __x into the output stream @p __os.
3407 * @param __os An output stream.
3408 * @param __x A %student_t_distribution random number distribution.
3410 * @returns The output stream with the state of @p __x inserted or in
3411 * an error state.
3413 template<typename _RealType1, typename _CharT, typename _Traits>
3414 friend std::basic_ostream<_CharT, _Traits>&
3415 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3416 const std::student_t_distribution<_RealType1>& __x);
3419 * @brief Extracts a %student_t_distribution random number distribution
3420 * @p __x from the input stream @p __is.
3422 * @param __is An input stream.
3423 * @param __x A %student_t_distribution random number
3424 * generator engine.
3426 * @returns The input stream with @p __x extracted or in an error state.
3428 template<typename _RealType1, typename _CharT, typename _Traits>
3429 friend std::basic_istream<_CharT, _Traits>&
3430 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3431 std::student_t_distribution<_RealType1>& __x);
3433 private:
3434 template<typename _ForwardIterator,
3435 typename _UniformRandomNumberGenerator>
3436 void
3437 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3438 _UniformRandomNumberGenerator& __urng);
3439 template<typename _ForwardIterator,
3440 typename _UniformRandomNumberGenerator>
3441 void
3442 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3443 _UniformRandomNumberGenerator& __urng,
3444 const param_type& __p);
3446 param_type _M_param;
3448 std::normal_distribution<result_type> _M_nd;
3449 std::gamma_distribution<result_type> _M_gd;
3453 * @brief Return true if two Student t distributions are different.
3455 template<typename _RealType>
3456 inline bool
3457 operator!=(const std::student_t_distribution<_RealType>& __d1,
3458 const std::student_t_distribution<_RealType>& __d2)
3459 { return !(__d1 == __d2); }
3462 /* @} */ // group random_distributions_normal
3465 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3466 * @ingroup random_distributions
3467 * @{
3471 * @brief A Bernoulli random number distribution.
3473 * Generates a sequence of true and false values with likelihood @f$p@f$
3474 * that true will come up and @f$(1 - p)@f$ that false will appear.
3476 class bernoulli_distribution
3478 public:
3479 /** The type of the range of the distribution. */
3480 typedef bool result_type;
3482 /** Parameter type. */
3483 struct param_type
3485 typedef bernoulli_distribution distribution_type;
3487 explicit
3488 param_type(double __p = 0.5)
3489 : _M_p(__p)
3491 __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0));
3494 double
3495 p() const
3496 { return _M_p; }
3498 friend bool
3499 operator==(const param_type& __p1, const param_type& __p2)
3500 { return __p1._M_p == __p2._M_p; }
3502 friend bool
3503 operator!=(const param_type& __p1, const param_type& __p2)
3504 { return !(__p1 == __p2); }
3506 private:
3507 double _M_p;
3510 public:
3512 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3514 * @param __p [IN] The likelihood of a true result being returned.
3515 * Must be in the interval @f$[0, 1]@f$.
3517 explicit
3518 bernoulli_distribution(double __p = 0.5)
3519 : _M_param(__p)
3522 explicit
3523 bernoulli_distribution(const param_type& __p)
3524 : _M_param(__p)
3528 * @brief Resets the distribution state.
3530 * Does nothing for a Bernoulli distribution.
3532 void
3533 reset() { }
3536 * @brief Returns the @p p parameter of the distribution.
3538 double
3539 p() const
3540 { return _M_param.p(); }
3543 * @brief Returns the parameter set of the distribution.
3545 param_type
3546 param() const
3547 { return _M_param; }
3550 * @brief Sets the parameter set of the distribution.
3551 * @param __param The new parameter set of the distribution.
3553 void
3554 param(const param_type& __param)
3555 { _M_param = __param; }
3558 * @brief Returns the greatest lower bound value of the distribution.
3560 result_type
3561 min() const
3562 { return std::numeric_limits<result_type>::min(); }
3565 * @brief Returns the least upper bound value of the distribution.
3567 result_type
3568 max() const
3569 { return std::numeric_limits<result_type>::max(); }
3572 * @brief Generating functions.
3574 template<typename _UniformRandomNumberGenerator>
3575 result_type
3576 operator()(_UniformRandomNumberGenerator& __urng)
3577 { return this->operator()(__urng, _M_param); }
3579 template<typename _UniformRandomNumberGenerator>
3580 result_type
3581 operator()(_UniformRandomNumberGenerator& __urng,
3582 const param_type& __p)
3584 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3585 __aurng(__urng);
3586 if ((__aurng() - __aurng.min())
3587 < __p.p() * (__aurng.max() - __aurng.min()))
3588 return true;
3589 return false;
3592 template<typename _ForwardIterator,
3593 typename _UniformRandomNumberGenerator>
3594 void
3595 __generate(_ForwardIterator __f, _ForwardIterator __t,
3596 _UniformRandomNumberGenerator& __urng)
3597 { this->__generate(__f, __t, __urng, _M_param); }
3599 template<typename _ForwardIterator,
3600 typename _UniformRandomNumberGenerator>
3601 void
3602 __generate(_ForwardIterator __f, _ForwardIterator __t,
3603 _UniformRandomNumberGenerator& __urng, const param_type& __p)
3604 { this->__generate_impl(__f, __t, __urng, __p); }
3606 template<typename _UniformRandomNumberGenerator>
3607 void
3608 __generate(result_type* __f, result_type* __t,
3609 _UniformRandomNumberGenerator& __urng,
3610 const param_type& __p)
3611 { this->__generate_impl(__f, __t, __urng, __p); }
3614 * @brief Return true if two Bernoulli distributions have
3615 * the same parameters.
3617 friend bool
3618 operator==(const bernoulli_distribution& __d1,
3619 const bernoulli_distribution& __d2)
3620 { return __d1._M_param == __d2._M_param; }
3622 private:
3623 template<typename _ForwardIterator,
3624 typename _UniformRandomNumberGenerator>
3625 void
3626 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3627 _UniformRandomNumberGenerator& __urng,
3628 const param_type& __p);
3630 param_type _M_param;
3634 * @brief Return true if two Bernoulli distributions have
3635 * different parameters.
3637 inline bool
3638 operator!=(const std::bernoulli_distribution& __d1,
3639 const std::bernoulli_distribution& __d2)
3640 { return !(__d1 == __d2); }
3643 * @brief Inserts a %bernoulli_distribution random number distribution
3644 * @p __x into the output stream @p __os.
3646 * @param __os An output stream.
3647 * @param __x A %bernoulli_distribution random number distribution.
3649 * @returns The output stream with the state of @p __x inserted or in
3650 * an error state.
3652 template<typename _CharT, typename _Traits>
3653 std::basic_ostream<_CharT, _Traits>&
3654 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3655 const std::bernoulli_distribution& __x);
3658 * @brief Extracts a %bernoulli_distribution random number distribution
3659 * @p __x from the input stream @p __is.
3661 * @param __is An input stream.
3662 * @param __x A %bernoulli_distribution random number generator engine.
3664 * @returns The input stream with @p __x extracted or in an error state.
3666 template<typename _CharT, typename _Traits>
3667 std::basic_istream<_CharT, _Traits>&
3668 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3669 std::bernoulli_distribution& __x)
3671 double __p;
3672 __is >> __p;
3673 __x.param(bernoulli_distribution::param_type(__p));
3674 return __is;
3679 * @brief A discrete binomial random number distribution.
3681 * The formula for the binomial probability density function is
3682 * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3683 * and @f$p@f$ are the parameters of the distribution.
3685 template<typename _IntType = int>
3686 class binomial_distribution
3688 static_assert(std::is_integral<_IntType>::value,
3689 "result_type must be an integral type");
3691 public:
3692 /** The type of the range of the distribution. */
3693 typedef _IntType result_type;
3695 /** Parameter type. */
3696 struct param_type
3698 typedef binomial_distribution<_IntType> distribution_type;
3699 friend class binomial_distribution<_IntType>;
3701 explicit
3702 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3703 : _M_t(__t), _M_p(__p)
3705 __glibcxx_assert((_M_t >= _IntType(0))
3706 && (_M_p >= 0.0)
3707 && (_M_p <= 1.0));
3708 _M_initialize();
3711 _IntType
3712 t() const
3713 { return _M_t; }
3715 double
3716 p() const
3717 { return _M_p; }
3719 friend bool
3720 operator==(const param_type& __p1, const param_type& __p2)
3721 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3723 friend bool
3724 operator!=(const param_type& __p1, const param_type& __p2)
3725 { return !(__p1 == __p2); }
3727 private:
3728 void
3729 _M_initialize();
3731 _IntType _M_t;
3732 double _M_p;
3734 double _M_q;
3735 #if _GLIBCXX_USE_C99_MATH_TR1
3736 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3737 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3738 #endif
3739 bool _M_easy;
3742 // constructors and member function
3743 explicit
3744 binomial_distribution(_IntType __t = _IntType(1),
3745 double __p = 0.5)
3746 : _M_param(__t, __p), _M_nd()
3749 explicit
3750 binomial_distribution(const param_type& __p)
3751 : _M_param(__p), _M_nd()
3755 * @brief Resets the distribution state.
3757 void
3758 reset()
3759 { _M_nd.reset(); }
3762 * @brief Returns the distribution @p t parameter.
3764 _IntType
3765 t() const
3766 { return _M_param.t(); }
3769 * @brief Returns the distribution @p p parameter.
3771 double
3772 p() const
3773 { return _M_param.p(); }
3776 * @brief Returns the parameter set of the distribution.
3778 param_type
3779 param() const
3780 { return _M_param; }
3783 * @brief Sets the parameter set of the distribution.
3784 * @param __param The new parameter set of the distribution.
3786 void
3787 param(const param_type& __param)
3788 { _M_param = __param; }
3791 * @brief Returns the greatest lower bound value of the distribution.
3793 result_type
3794 min() const
3795 { return 0; }
3798 * @brief Returns the least upper bound value of the distribution.
3800 result_type
3801 max() const
3802 { return _M_param.t(); }
3805 * @brief Generating functions.
3807 template<typename _UniformRandomNumberGenerator>
3808 result_type
3809 operator()(_UniformRandomNumberGenerator& __urng)
3810 { return this->operator()(__urng, _M_param); }
3812 template<typename _UniformRandomNumberGenerator>
3813 result_type
3814 operator()(_UniformRandomNumberGenerator& __urng,
3815 const param_type& __p);
3817 template<typename _ForwardIterator,
3818 typename _UniformRandomNumberGenerator>
3819 void
3820 __generate(_ForwardIterator __f, _ForwardIterator __t,
3821 _UniformRandomNumberGenerator& __urng)
3822 { this->__generate(__f, __t, __urng, _M_param); }
3824 template<typename _ForwardIterator,
3825 typename _UniformRandomNumberGenerator>
3826 void
3827 __generate(_ForwardIterator __f, _ForwardIterator __t,
3828 _UniformRandomNumberGenerator& __urng,
3829 const param_type& __p)
3830 { this->__generate_impl(__f, __t, __urng, __p); }
3832 template<typename _UniformRandomNumberGenerator>
3833 void
3834 __generate(result_type* __f, result_type* __t,
3835 _UniformRandomNumberGenerator& __urng,
3836 const param_type& __p)
3837 { this->__generate_impl(__f, __t, __urng, __p); }
3840 * @brief Return true if two binomial distributions have
3841 * the same parameters and the sequences that would
3842 * be generated are equal.
3844 friend bool
3845 operator==(const binomial_distribution& __d1,
3846 const binomial_distribution& __d2)
3847 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3848 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
3849 #else
3850 { return __d1._M_param == __d2._M_param; }
3851 #endif
3854 * @brief Inserts a %binomial_distribution random number distribution
3855 * @p __x into the output stream @p __os.
3857 * @param __os An output stream.
3858 * @param __x A %binomial_distribution random number distribution.
3860 * @returns The output stream with the state of @p __x inserted or in
3861 * an error state.
3863 template<typename _IntType1,
3864 typename _CharT, typename _Traits>
3865 friend std::basic_ostream<_CharT, _Traits>&
3866 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3867 const std::binomial_distribution<_IntType1>& __x);
3870 * @brief Extracts a %binomial_distribution random number distribution
3871 * @p __x from the input stream @p __is.
3873 * @param __is An input stream.
3874 * @param __x A %binomial_distribution random number generator engine.
3876 * @returns The input stream with @p __x extracted or in an error
3877 * state.
3879 template<typename _IntType1,
3880 typename _CharT, typename _Traits>
3881 friend std::basic_istream<_CharT, _Traits>&
3882 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3883 std::binomial_distribution<_IntType1>& __x);
3885 private:
3886 template<typename _ForwardIterator,
3887 typename _UniformRandomNumberGenerator>
3888 void
3889 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3890 _UniformRandomNumberGenerator& __urng,
3891 const param_type& __p);
3893 template<typename _UniformRandomNumberGenerator>
3894 result_type
3895 _M_waiting(_UniformRandomNumberGenerator& __urng,
3896 _IntType __t, double __q);
3898 param_type _M_param;
3900 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3901 std::normal_distribution<double> _M_nd;
3905 * @brief Return true if two binomial distributions are different.
3907 template<typename _IntType>
3908 inline bool
3909 operator!=(const std::binomial_distribution<_IntType>& __d1,
3910 const std::binomial_distribution<_IntType>& __d2)
3911 { return !(__d1 == __d2); }
3915 * @brief A discrete geometric random number distribution.
3917 * The formula for the geometric probability density function is
3918 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3919 * distribution.
3921 template<typename _IntType = int>
3922 class geometric_distribution
3924 static_assert(std::is_integral<_IntType>::value,
3925 "result_type must be an integral type");
3927 public:
3928 /** The type of the range of the distribution. */
3929 typedef _IntType result_type;
3931 /** Parameter type. */
3932 struct param_type
3934 typedef geometric_distribution<_IntType> distribution_type;
3935 friend class geometric_distribution<_IntType>;
3937 explicit
3938 param_type(double __p = 0.5)
3939 : _M_p(__p)
3941 __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0));
3942 _M_initialize();
3945 double
3946 p() const
3947 { return _M_p; }
3949 friend bool
3950 operator==(const param_type& __p1, const param_type& __p2)
3951 { return __p1._M_p == __p2._M_p; }
3953 friend bool
3954 operator!=(const param_type& __p1, const param_type& __p2)
3955 { return !(__p1 == __p2); }
3957 private:
3958 void
3959 _M_initialize()
3960 { _M_log_1_p = std::log(1.0 - _M_p); }
3962 double _M_p;
3964 double _M_log_1_p;
3967 // constructors and member function
3968 explicit
3969 geometric_distribution(double __p = 0.5)
3970 : _M_param(__p)
3973 explicit
3974 geometric_distribution(const param_type& __p)
3975 : _M_param(__p)
3979 * @brief Resets the distribution state.
3981 * Does nothing for the geometric distribution.
3983 void
3984 reset() { }
3987 * @brief Returns the distribution parameter @p p.
3989 double
3990 p() const
3991 { return _M_param.p(); }
3994 * @brief Returns the parameter set of the distribution.
3996 param_type
3997 param() const
3998 { return _M_param; }
4001 * @brief Sets the parameter set of the distribution.
4002 * @param __param The new parameter set of the distribution.
4004 void
4005 param(const param_type& __param)
4006 { _M_param = __param; }
4009 * @brief Returns the greatest lower bound value of the distribution.
4011 result_type
4012 min() const
4013 { return 0; }
4016 * @brief Returns the least upper bound value of the distribution.
4018 result_type
4019 max() const
4020 { return std::numeric_limits<result_type>::max(); }
4023 * @brief Generating functions.
4025 template<typename _UniformRandomNumberGenerator>
4026 result_type
4027 operator()(_UniformRandomNumberGenerator& __urng)
4028 { return this->operator()(__urng, _M_param); }
4030 template<typename _UniformRandomNumberGenerator>
4031 result_type
4032 operator()(_UniformRandomNumberGenerator& __urng,
4033 const param_type& __p);
4035 template<typename _ForwardIterator,
4036 typename _UniformRandomNumberGenerator>
4037 void
4038 __generate(_ForwardIterator __f, _ForwardIterator __t,
4039 _UniformRandomNumberGenerator& __urng)
4040 { this->__generate(__f, __t, __urng, _M_param); }
4042 template<typename _ForwardIterator,
4043 typename _UniformRandomNumberGenerator>
4044 void
4045 __generate(_ForwardIterator __f, _ForwardIterator __t,
4046 _UniformRandomNumberGenerator& __urng,
4047 const param_type& __p)
4048 { this->__generate_impl(__f, __t, __urng, __p); }
4050 template<typename _UniformRandomNumberGenerator>
4051 void
4052 __generate(result_type* __f, result_type* __t,
4053 _UniformRandomNumberGenerator& __urng,
4054 const param_type& __p)
4055 { this->__generate_impl(__f, __t, __urng, __p); }
4058 * @brief Return true if two geometric distributions have
4059 * the same parameters.
4061 friend bool
4062 operator==(const geometric_distribution& __d1,
4063 const geometric_distribution& __d2)
4064 { return __d1._M_param == __d2._M_param; }
4066 private:
4067 template<typename _ForwardIterator,
4068 typename _UniformRandomNumberGenerator>
4069 void
4070 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4071 _UniformRandomNumberGenerator& __urng,
4072 const param_type& __p);
4074 param_type _M_param;
4078 * @brief Return true if two geometric distributions have
4079 * different parameters.
4081 template<typename _IntType>
4082 inline bool
4083 operator!=(const std::geometric_distribution<_IntType>& __d1,
4084 const std::geometric_distribution<_IntType>& __d2)
4085 { return !(__d1 == __d2); }
4088 * @brief Inserts a %geometric_distribution random number distribution
4089 * @p __x into the output stream @p __os.
4091 * @param __os An output stream.
4092 * @param __x A %geometric_distribution random number distribution.
4094 * @returns The output stream with the state of @p __x inserted or in
4095 * an error state.
4097 template<typename _IntType,
4098 typename _CharT, typename _Traits>
4099 std::basic_ostream<_CharT, _Traits>&
4100 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4101 const std::geometric_distribution<_IntType>& __x);
4104 * @brief Extracts a %geometric_distribution random number distribution
4105 * @p __x from the input stream @p __is.
4107 * @param __is An input stream.
4108 * @param __x A %geometric_distribution random number generator engine.
4110 * @returns The input stream with @p __x extracted or in an error state.
4112 template<typename _IntType,
4113 typename _CharT, typename _Traits>
4114 std::basic_istream<_CharT, _Traits>&
4115 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4116 std::geometric_distribution<_IntType>& __x);
4120 * @brief A negative_binomial_distribution random number distribution.
4122 * The formula for the negative binomial probability mass function is
4123 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
4124 * and @f$p@f$ are the parameters of the distribution.
4126 template<typename _IntType = int>
4127 class negative_binomial_distribution
4129 static_assert(std::is_integral<_IntType>::value,
4130 "result_type must be an integral type");
4132 public:
4133 /** The type of the range of the distribution. */
4134 typedef _IntType result_type;
4136 /** Parameter type. */
4137 struct param_type
4139 typedef negative_binomial_distribution<_IntType> distribution_type;
4141 explicit
4142 param_type(_IntType __k = 1, double __p = 0.5)
4143 : _M_k(__k), _M_p(__p)
4145 __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
4148 _IntType
4149 k() const
4150 { return _M_k; }
4152 double
4153 p() const
4154 { return _M_p; }
4156 friend bool
4157 operator==(const param_type& __p1, const param_type& __p2)
4158 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
4160 friend bool
4161 operator!=(const param_type& __p1, const param_type& __p2)
4162 { return !(__p1 == __p2); }
4164 private:
4165 _IntType _M_k;
4166 double _M_p;
4169 explicit
4170 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
4171 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
4174 explicit
4175 negative_binomial_distribution(const param_type& __p)
4176 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
4180 * @brief Resets the distribution state.
4182 void
4183 reset()
4184 { _M_gd.reset(); }
4187 * @brief Return the @f$k@f$ parameter of the distribution.
4189 _IntType
4190 k() const
4191 { return _M_param.k(); }
4194 * @brief Return the @f$p@f$ parameter of the distribution.
4196 double
4197 p() const
4198 { return _M_param.p(); }
4201 * @brief Returns the parameter set of the distribution.
4203 param_type
4204 param() const
4205 { return _M_param; }
4208 * @brief Sets the parameter set of the distribution.
4209 * @param __param The new parameter set of the distribution.
4211 void
4212 param(const param_type& __param)
4213 { _M_param = __param; }
4216 * @brief Returns the greatest lower bound value of the distribution.
4218 result_type
4219 min() const
4220 { return result_type(0); }
4223 * @brief Returns the least upper bound value of the distribution.
4225 result_type
4226 max() const
4227 { return std::numeric_limits<result_type>::max(); }
4230 * @brief Generating functions.
4232 template<typename _UniformRandomNumberGenerator>
4233 result_type
4234 operator()(_UniformRandomNumberGenerator& __urng);
4236 template<typename _UniformRandomNumberGenerator>
4237 result_type
4238 operator()(_UniformRandomNumberGenerator& __urng,
4239 const param_type& __p);
4241 template<typename _ForwardIterator,
4242 typename _UniformRandomNumberGenerator>
4243 void
4244 __generate(_ForwardIterator __f, _ForwardIterator __t,
4245 _UniformRandomNumberGenerator& __urng)
4246 { this->__generate_impl(__f, __t, __urng); }
4248 template<typename _ForwardIterator,
4249 typename _UniformRandomNumberGenerator>
4250 void
4251 __generate(_ForwardIterator __f, _ForwardIterator __t,
4252 _UniformRandomNumberGenerator& __urng,
4253 const param_type& __p)
4254 { this->__generate_impl(__f, __t, __urng, __p); }
4256 template<typename _UniformRandomNumberGenerator>
4257 void
4258 __generate(result_type* __f, result_type* __t,
4259 _UniformRandomNumberGenerator& __urng)
4260 { this->__generate_impl(__f, __t, __urng); }
4262 template<typename _UniformRandomNumberGenerator>
4263 void
4264 __generate(result_type* __f, result_type* __t,
4265 _UniformRandomNumberGenerator& __urng,
4266 const param_type& __p)
4267 { this->__generate_impl(__f, __t, __urng, __p); }
4270 * @brief Return true if two negative binomial distributions have
4271 * the same parameters and the sequences that would be
4272 * generated are equal.
4274 friend bool
4275 operator==(const negative_binomial_distribution& __d1,
4276 const negative_binomial_distribution& __d2)
4277 { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
4280 * @brief Inserts a %negative_binomial_distribution random
4281 * number distribution @p __x into the output stream @p __os.
4283 * @param __os An output stream.
4284 * @param __x A %negative_binomial_distribution random number
4285 * distribution.
4287 * @returns The output stream with the state of @p __x inserted or in
4288 * an error state.
4290 template<typename _IntType1, typename _CharT, typename _Traits>
4291 friend std::basic_ostream<_CharT, _Traits>&
4292 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4293 const std::negative_binomial_distribution<_IntType1>& __x);
4296 * @brief Extracts a %negative_binomial_distribution random number
4297 * distribution @p __x from the input stream @p __is.
4299 * @param __is An input stream.
4300 * @param __x A %negative_binomial_distribution random number
4301 * generator engine.
4303 * @returns The input stream with @p __x extracted or in an error state.
4305 template<typename _IntType1, typename _CharT, typename _Traits>
4306 friend std::basic_istream<_CharT, _Traits>&
4307 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4308 std::negative_binomial_distribution<_IntType1>& __x);
4310 private:
4311 template<typename _ForwardIterator,
4312 typename _UniformRandomNumberGenerator>
4313 void
4314 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4315 _UniformRandomNumberGenerator& __urng);
4316 template<typename _ForwardIterator,
4317 typename _UniformRandomNumberGenerator>
4318 void
4319 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4320 _UniformRandomNumberGenerator& __urng,
4321 const param_type& __p);
4323 param_type _M_param;
4325 std::gamma_distribution<double> _M_gd;
4329 * @brief Return true if two negative binomial distributions are different.
4331 template<typename _IntType>
4332 inline bool
4333 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
4334 const std::negative_binomial_distribution<_IntType>& __d2)
4335 { return !(__d1 == __d2); }
4338 /* @} */ // group random_distributions_bernoulli
4341 * @addtogroup random_distributions_poisson Poisson Distributions
4342 * @ingroup random_distributions
4343 * @{
4347 * @brief A discrete Poisson random number distribution.
4349 * The formula for the Poisson probability density function is
4350 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
4351 * parameter of the distribution.
4353 template<typename _IntType = int>
4354 class poisson_distribution
4356 static_assert(std::is_integral<_IntType>::value,
4357 "result_type must be an integral type");
4359 public:
4360 /** The type of the range of the distribution. */
4361 typedef _IntType result_type;
4363 /** Parameter type. */
4364 struct param_type
4366 typedef poisson_distribution<_IntType> distribution_type;
4367 friend class poisson_distribution<_IntType>;
4369 explicit
4370 param_type(double __mean = 1.0)
4371 : _M_mean(__mean)
4373 __glibcxx_assert(_M_mean > 0.0);
4374 _M_initialize();
4377 double
4378 mean() const
4379 { return _M_mean; }
4381 friend bool
4382 operator==(const param_type& __p1, const param_type& __p2)
4383 { return __p1._M_mean == __p2._M_mean; }
4385 friend bool
4386 operator!=(const param_type& __p1, const param_type& __p2)
4387 { return !(__p1 == __p2); }
4389 private:
4390 // Hosts either log(mean) or the threshold of the simple method.
4391 void
4392 _M_initialize();
4394 double _M_mean;
4396 double _M_lm_thr;
4397 #if _GLIBCXX_USE_C99_MATH_TR1
4398 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
4399 #endif
4402 // constructors and member function
4403 explicit
4404 poisson_distribution(double __mean = 1.0)
4405 : _M_param(__mean), _M_nd()
4408 explicit
4409 poisson_distribution(const param_type& __p)
4410 : _M_param(__p), _M_nd()
4414 * @brief Resets the distribution state.
4416 void
4417 reset()
4418 { _M_nd.reset(); }
4421 * @brief Returns the distribution parameter @p mean.
4423 double
4424 mean() const
4425 { return _M_param.mean(); }
4428 * @brief Returns the parameter set of the distribution.
4430 param_type
4431 param() const
4432 { return _M_param; }
4435 * @brief Sets the parameter set of the distribution.
4436 * @param __param The new parameter set of the distribution.
4438 void
4439 param(const param_type& __param)
4440 { _M_param = __param; }
4443 * @brief Returns the greatest lower bound value of the distribution.
4445 result_type
4446 min() const
4447 { return 0; }
4450 * @brief Returns the least upper bound value of the distribution.
4452 result_type
4453 max() const
4454 { return std::numeric_limits<result_type>::max(); }
4457 * @brief Generating functions.
4459 template<typename _UniformRandomNumberGenerator>
4460 result_type
4461 operator()(_UniformRandomNumberGenerator& __urng)
4462 { return this->operator()(__urng, _M_param); }
4464 template<typename _UniformRandomNumberGenerator>
4465 result_type
4466 operator()(_UniformRandomNumberGenerator& __urng,
4467 const param_type& __p);
4469 template<typename _ForwardIterator,
4470 typename _UniformRandomNumberGenerator>
4471 void
4472 __generate(_ForwardIterator __f, _ForwardIterator __t,
4473 _UniformRandomNumberGenerator& __urng)
4474 { this->__generate(__f, __t, __urng, _M_param); }
4476 template<typename _ForwardIterator,
4477 typename _UniformRandomNumberGenerator>
4478 void
4479 __generate(_ForwardIterator __f, _ForwardIterator __t,
4480 _UniformRandomNumberGenerator& __urng,
4481 const param_type& __p)
4482 { this->__generate_impl(__f, __t, __urng, __p); }
4484 template<typename _UniformRandomNumberGenerator>
4485 void
4486 __generate(result_type* __f, result_type* __t,
4487 _UniformRandomNumberGenerator& __urng,
4488 const param_type& __p)
4489 { this->__generate_impl(__f, __t, __urng, __p); }
4492 * @brief Return true if two Poisson distributions have the same
4493 * parameters and the sequences that would be generated
4494 * are equal.
4496 friend bool
4497 operator==(const poisson_distribution& __d1,
4498 const poisson_distribution& __d2)
4499 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4500 { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
4501 #else
4502 { return __d1._M_param == __d2._M_param; }
4503 #endif
4506 * @brief Inserts a %poisson_distribution random number distribution
4507 * @p __x into the output stream @p __os.
4509 * @param __os An output stream.
4510 * @param __x A %poisson_distribution random number distribution.
4512 * @returns The output stream with the state of @p __x inserted or in
4513 * an error state.
4515 template<typename _IntType1, typename _CharT, typename _Traits>
4516 friend std::basic_ostream<_CharT, _Traits>&
4517 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4518 const std::poisson_distribution<_IntType1>& __x);
4521 * @brief Extracts a %poisson_distribution random number distribution
4522 * @p __x from the input stream @p __is.
4524 * @param __is An input stream.
4525 * @param __x A %poisson_distribution random number generator engine.
4527 * @returns The input stream with @p __x extracted or in an error
4528 * state.
4530 template<typename _IntType1, typename _CharT, typename _Traits>
4531 friend std::basic_istream<_CharT, _Traits>&
4532 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4533 std::poisson_distribution<_IntType1>& __x);
4535 private:
4536 template<typename _ForwardIterator,
4537 typename _UniformRandomNumberGenerator>
4538 void
4539 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4540 _UniformRandomNumberGenerator& __urng,
4541 const param_type& __p);
4543 param_type _M_param;
4545 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4546 std::normal_distribution<double> _M_nd;
4550 * @brief Return true if two Poisson distributions are different.
4552 template<typename _IntType>
4553 inline bool
4554 operator!=(const std::poisson_distribution<_IntType>& __d1,
4555 const std::poisson_distribution<_IntType>& __d2)
4556 { return !(__d1 == __d2); }
4560 * @brief An exponential continuous distribution for random numbers.
4562 * The formula for the exponential probability density function is
4563 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4565 * <table border=1 cellpadding=10 cellspacing=0>
4566 * <caption align=top>Distribution Statistics</caption>
4567 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4568 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4569 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4570 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4571 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4572 * </table>
4574 template<typename _RealType = double>
4575 class exponential_distribution
4577 static_assert(std::is_floating_point<_RealType>::value,
4578 "result_type must be a floating point type");
4580 public:
4581 /** The type of the range of the distribution. */
4582 typedef _RealType result_type;
4584 /** Parameter type. */
4585 struct param_type
4587 typedef exponential_distribution<_RealType> distribution_type;
4589 explicit
4590 param_type(_RealType __lambda = _RealType(1))
4591 : _M_lambda(__lambda)
4593 __glibcxx_assert(_M_lambda > _RealType(0));
4596 _RealType
4597 lambda() const
4598 { return _M_lambda; }
4600 friend bool
4601 operator==(const param_type& __p1, const param_type& __p2)
4602 { return __p1._M_lambda == __p2._M_lambda; }
4604 friend bool
4605 operator!=(const param_type& __p1, const param_type& __p2)
4606 { return !(__p1 == __p2); }
4608 private:
4609 _RealType _M_lambda;
4612 public:
4614 * @brief Constructs an exponential distribution with inverse scale
4615 * parameter @f$\lambda@f$.
4617 explicit
4618 exponential_distribution(const result_type& __lambda = result_type(1))
4619 : _M_param(__lambda)
4622 explicit
4623 exponential_distribution(const param_type& __p)
4624 : _M_param(__p)
4628 * @brief Resets the distribution state.
4630 * Has no effect on exponential distributions.
4632 void
4633 reset() { }
4636 * @brief Returns the inverse scale parameter of the distribution.
4638 _RealType
4639 lambda() const
4640 { return _M_param.lambda(); }
4643 * @brief Returns the parameter set of the distribution.
4645 param_type
4646 param() const
4647 { return _M_param; }
4650 * @brief Sets the parameter set of the distribution.
4651 * @param __param The new parameter set of the distribution.
4653 void
4654 param(const param_type& __param)
4655 { _M_param = __param; }
4658 * @brief Returns the greatest lower bound value of the distribution.
4660 result_type
4661 min() const
4662 { return result_type(0); }
4665 * @brief Returns the least upper bound value of the distribution.
4667 result_type
4668 max() const
4669 { return std::numeric_limits<result_type>::max(); }
4672 * @brief Generating functions.
4674 template<typename _UniformRandomNumberGenerator>
4675 result_type
4676 operator()(_UniformRandomNumberGenerator& __urng)
4677 { return this->operator()(__urng, _M_param); }
4679 template<typename _UniformRandomNumberGenerator>
4680 result_type
4681 operator()(_UniformRandomNumberGenerator& __urng,
4682 const param_type& __p)
4684 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4685 __aurng(__urng);
4686 return -std::log(result_type(1) - __aurng()) / __p.lambda();
4689 template<typename _ForwardIterator,
4690 typename _UniformRandomNumberGenerator>
4691 void
4692 __generate(_ForwardIterator __f, _ForwardIterator __t,
4693 _UniformRandomNumberGenerator& __urng)
4694 { this->__generate(__f, __t, __urng, _M_param); }
4696 template<typename _ForwardIterator,
4697 typename _UniformRandomNumberGenerator>
4698 void
4699 __generate(_ForwardIterator __f, _ForwardIterator __t,
4700 _UniformRandomNumberGenerator& __urng,
4701 const param_type& __p)
4702 { this->__generate_impl(__f, __t, __urng, __p); }
4704 template<typename _UniformRandomNumberGenerator>
4705 void
4706 __generate(result_type* __f, result_type* __t,
4707 _UniformRandomNumberGenerator& __urng,
4708 const param_type& __p)
4709 { this->__generate_impl(__f, __t, __urng, __p); }
4712 * @brief Return true if two exponential distributions have the same
4713 * parameters.
4715 friend bool
4716 operator==(const exponential_distribution& __d1,
4717 const exponential_distribution& __d2)
4718 { return __d1._M_param == __d2._M_param; }
4720 private:
4721 template<typename _ForwardIterator,
4722 typename _UniformRandomNumberGenerator>
4723 void
4724 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4725 _UniformRandomNumberGenerator& __urng,
4726 const param_type& __p);
4728 param_type _M_param;
4732 * @brief Return true if two exponential distributions have different
4733 * parameters.
4735 template<typename _RealType>
4736 inline bool
4737 operator!=(const std::exponential_distribution<_RealType>& __d1,
4738 const std::exponential_distribution<_RealType>& __d2)
4739 { return !(__d1 == __d2); }
4742 * @brief Inserts a %exponential_distribution random number distribution
4743 * @p __x into the output stream @p __os.
4745 * @param __os An output stream.
4746 * @param __x A %exponential_distribution random number distribution.
4748 * @returns The output stream with the state of @p __x inserted or in
4749 * an error state.
4751 template<typename _RealType, typename _CharT, typename _Traits>
4752 std::basic_ostream<_CharT, _Traits>&
4753 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4754 const std::exponential_distribution<_RealType>& __x);
4757 * @brief Extracts a %exponential_distribution random number distribution
4758 * @p __x from the input stream @p __is.
4760 * @param __is An input stream.
4761 * @param __x A %exponential_distribution random number
4762 * generator engine.
4764 * @returns The input stream with @p __x extracted or in an error state.
4766 template<typename _RealType, typename _CharT, typename _Traits>
4767 std::basic_istream<_CharT, _Traits>&
4768 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4769 std::exponential_distribution<_RealType>& __x);
4773 * @brief A weibull_distribution random number distribution.
4775 * The formula for the normal probability density function is:
4776 * @f[
4777 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4778 * \exp{(-(\frac{x}{\beta})^\alpha)}
4779 * @f]
4781 template<typename _RealType = double>
4782 class weibull_distribution
4784 static_assert(std::is_floating_point<_RealType>::value,
4785 "result_type must be a floating point type");
4787 public:
4788 /** The type of the range of the distribution. */
4789 typedef _RealType result_type;
4791 /** Parameter type. */
4792 struct param_type
4794 typedef weibull_distribution<_RealType> distribution_type;
4796 explicit
4797 param_type(_RealType __a = _RealType(1),
4798 _RealType __b = _RealType(1))
4799 : _M_a(__a), _M_b(__b)
4802 _RealType
4803 a() const
4804 { return _M_a; }
4806 _RealType
4807 b() const
4808 { return _M_b; }
4810 friend bool
4811 operator==(const param_type& __p1, const param_type& __p2)
4812 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4814 friend bool
4815 operator!=(const param_type& __p1, const param_type& __p2)
4816 { return !(__p1 == __p2); }
4818 private:
4819 _RealType _M_a;
4820 _RealType _M_b;
4823 explicit
4824 weibull_distribution(_RealType __a = _RealType(1),
4825 _RealType __b = _RealType(1))
4826 : _M_param(__a, __b)
4829 explicit
4830 weibull_distribution(const param_type& __p)
4831 : _M_param(__p)
4835 * @brief Resets the distribution state.
4837 void
4838 reset()
4842 * @brief Return the @f$a@f$ parameter of the distribution.
4844 _RealType
4845 a() const
4846 { return _M_param.a(); }
4849 * @brief Return the @f$b@f$ parameter of the distribution.
4851 _RealType
4852 b() const
4853 { return _M_param.b(); }
4856 * @brief Returns the parameter set of the distribution.
4858 param_type
4859 param() const
4860 { return _M_param; }
4863 * @brief Sets the parameter set of the distribution.
4864 * @param __param The new parameter set of the distribution.
4866 void
4867 param(const param_type& __param)
4868 { _M_param = __param; }
4871 * @brief Returns the greatest lower bound value of the distribution.
4873 result_type
4874 min() const
4875 { return result_type(0); }
4878 * @brief Returns the least upper bound value of the distribution.
4880 result_type
4881 max() const
4882 { return std::numeric_limits<result_type>::max(); }
4885 * @brief Generating functions.
4887 template<typename _UniformRandomNumberGenerator>
4888 result_type
4889 operator()(_UniformRandomNumberGenerator& __urng)
4890 { return this->operator()(__urng, _M_param); }
4892 template<typename _UniformRandomNumberGenerator>
4893 result_type
4894 operator()(_UniformRandomNumberGenerator& __urng,
4895 const param_type& __p);
4897 template<typename _ForwardIterator,
4898 typename _UniformRandomNumberGenerator>
4899 void
4900 __generate(_ForwardIterator __f, _ForwardIterator __t,
4901 _UniformRandomNumberGenerator& __urng)
4902 { this->__generate(__f, __t, __urng, _M_param); }
4904 template<typename _ForwardIterator,
4905 typename _UniformRandomNumberGenerator>
4906 void
4907 __generate(_ForwardIterator __f, _ForwardIterator __t,
4908 _UniformRandomNumberGenerator& __urng,
4909 const param_type& __p)
4910 { this->__generate_impl(__f, __t, __urng, __p); }
4912 template<typename _UniformRandomNumberGenerator>
4913 void
4914 __generate(result_type* __f, result_type* __t,
4915 _UniformRandomNumberGenerator& __urng,
4916 const param_type& __p)
4917 { this->__generate_impl(__f, __t, __urng, __p); }
4920 * @brief Return true if two Weibull distributions have the same
4921 * parameters.
4923 friend bool
4924 operator==(const weibull_distribution& __d1,
4925 const weibull_distribution& __d2)
4926 { return __d1._M_param == __d2._M_param; }
4928 private:
4929 template<typename _ForwardIterator,
4930 typename _UniformRandomNumberGenerator>
4931 void
4932 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
4933 _UniformRandomNumberGenerator& __urng,
4934 const param_type& __p);
4936 param_type _M_param;
4940 * @brief Return true if two Weibull distributions have different
4941 * parameters.
4943 template<typename _RealType>
4944 inline bool
4945 operator!=(const std::weibull_distribution<_RealType>& __d1,
4946 const std::weibull_distribution<_RealType>& __d2)
4947 { return !(__d1 == __d2); }
4950 * @brief Inserts a %weibull_distribution random number distribution
4951 * @p __x into the output stream @p __os.
4953 * @param __os An output stream.
4954 * @param __x A %weibull_distribution random number distribution.
4956 * @returns The output stream with the state of @p __x inserted or in
4957 * an error state.
4959 template<typename _RealType, typename _CharT, typename _Traits>
4960 std::basic_ostream<_CharT, _Traits>&
4961 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4962 const std::weibull_distribution<_RealType>& __x);
4965 * @brief Extracts a %weibull_distribution random number distribution
4966 * @p __x from the input stream @p __is.
4968 * @param __is An input stream.
4969 * @param __x A %weibull_distribution random number
4970 * generator engine.
4972 * @returns The input stream with @p __x extracted or in an error state.
4974 template<typename _RealType, typename _CharT, typename _Traits>
4975 std::basic_istream<_CharT, _Traits>&
4976 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4977 std::weibull_distribution<_RealType>& __x);
4981 * @brief A extreme_value_distribution random number distribution.
4983 * The formula for the normal probability mass function is
4984 * @f[
4985 * p(x|a,b) = \frac{1}{b}
4986 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4987 * @f]
4989 template<typename _RealType = double>
4990 class extreme_value_distribution
4992 static_assert(std::is_floating_point<_RealType>::value,
4993 "result_type must be a floating point type");
4995 public:
4996 /** The type of the range of the distribution. */
4997 typedef _RealType result_type;
4999 /** Parameter type. */
5000 struct param_type
5002 typedef extreme_value_distribution<_RealType> distribution_type;
5004 explicit
5005 param_type(_RealType __a = _RealType(0),
5006 _RealType __b = _RealType(1))
5007 : _M_a(__a), _M_b(__b)
5010 _RealType
5011 a() const
5012 { return _M_a; }
5014 _RealType
5015 b() const
5016 { return _M_b; }
5018 friend bool
5019 operator==(const param_type& __p1, const param_type& __p2)
5020 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
5022 friend bool
5023 operator!=(const param_type& __p1, const param_type& __p2)
5024 { return !(__p1 == __p2); }
5026 private:
5027 _RealType _M_a;
5028 _RealType _M_b;
5031 explicit
5032 extreme_value_distribution(_RealType __a = _RealType(0),
5033 _RealType __b = _RealType(1))
5034 : _M_param(__a, __b)
5037 explicit
5038 extreme_value_distribution(const param_type& __p)
5039 : _M_param(__p)
5043 * @brief Resets the distribution state.
5045 void
5046 reset()
5050 * @brief Return the @f$a@f$ parameter of the distribution.
5052 _RealType
5053 a() const
5054 { return _M_param.a(); }
5057 * @brief Return the @f$b@f$ parameter of the distribution.
5059 _RealType
5060 b() const
5061 { return _M_param.b(); }
5064 * @brief Returns the parameter set of the distribution.
5066 param_type
5067 param() const
5068 { return _M_param; }
5071 * @brief Sets the parameter set of the distribution.
5072 * @param __param The new parameter set of the distribution.
5074 void
5075 param(const param_type& __param)
5076 { _M_param = __param; }
5079 * @brief Returns the greatest lower bound value of the distribution.
5081 result_type
5082 min() const
5083 { return std::numeric_limits<result_type>::lowest(); }
5086 * @brief Returns the least upper bound value of the distribution.
5088 result_type
5089 max() const
5090 { return std::numeric_limits<result_type>::max(); }
5093 * @brief Generating functions.
5095 template<typename _UniformRandomNumberGenerator>
5096 result_type
5097 operator()(_UniformRandomNumberGenerator& __urng)
5098 { return this->operator()(__urng, _M_param); }
5100 template<typename _UniformRandomNumberGenerator>
5101 result_type
5102 operator()(_UniformRandomNumberGenerator& __urng,
5103 const param_type& __p);
5105 template<typename _ForwardIterator,
5106 typename _UniformRandomNumberGenerator>
5107 void
5108 __generate(_ForwardIterator __f, _ForwardIterator __t,
5109 _UniformRandomNumberGenerator& __urng)
5110 { this->__generate(__f, __t, __urng, _M_param); }
5112 template<typename _ForwardIterator,
5113 typename _UniformRandomNumberGenerator>
5114 void
5115 __generate(_ForwardIterator __f, _ForwardIterator __t,
5116 _UniformRandomNumberGenerator& __urng,
5117 const param_type& __p)
5118 { this->__generate_impl(__f, __t, __urng, __p); }
5120 template<typename _UniformRandomNumberGenerator>
5121 void
5122 __generate(result_type* __f, result_type* __t,
5123 _UniformRandomNumberGenerator& __urng,
5124 const param_type& __p)
5125 { this->__generate_impl(__f, __t, __urng, __p); }
5128 * @brief Return true if two extreme value distributions have the same
5129 * parameters.
5131 friend bool
5132 operator==(const extreme_value_distribution& __d1,
5133 const extreme_value_distribution& __d2)
5134 { return __d1._M_param == __d2._M_param; }
5136 private:
5137 template<typename _ForwardIterator,
5138 typename _UniformRandomNumberGenerator>
5139 void
5140 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5141 _UniformRandomNumberGenerator& __urng,
5142 const param_type& __p);
5144 param_type _M_param;
5148 * @brief Return true if two extreme value distributions have different
5149 * parameters.
5151 template<typename _RealType>
5152 inline bool
5153 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
5154 const std::extreme_value_distribution<_RealType>& __d2)
5155 { return !(__d1 == __d2); }
5158 * @brief Inserts a %extreme_value_distribution random number distribution
5159 * @p __x into the output stream @p __os.
5161 * @param __os An output stream.
5162 * @param __x A %extreme_value_distribution random number distribution.
5164 * @returns The output stream with the state of @p __x inserted or in
5165 * an error state.
5167 template<typename _RealType, typename _CharT, typename _Traits>
5168 std::basic_ostream<_CharT, _Traits>&
5169 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5170 const std::extreme_value_distribution<_RealType>& __x);
5173 * @brief Extracts a %extreme_value_distribution random number
5174 * distribution @p __x from the input stream @p __is.
5176 * @param __is An input stream.
5177 * @param __x A %extreme_value_distribution random number
5178 * generator engine.
5180 * @returns The input stream with @p __x extracted or in an error state.
5182 template<typename _RealType, typename _CharT, typename _Traits>
5183 std::basic_istream<_CharT, _Traits>&
5184 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5185 std::extreme_value_distribution<_RealType>& __x);
5189 * @brief A discrete_distribution random number distribution.
5191 * The formula for the discrete probability mass function is
5194 template<typename _IntType = int>
5195 class discrete_distribution
5197 static_assert(std::is_integral<_IntType>::value,
5198 "result_type must be an integral type");
5200 public:
5201 /** The type of the range of the distribution. */
5202 typedef _IntType result_type;
5204 /** Parameter type. */
5205 struct param_type
5207 typedef discrete_distribution<_IntType> distribution_type;
5208 friend class discrete_distribution<_IntType>;
5210 param_type()
5211 : _M_prob(), _M_cp()
5214 template<typename _InputIterator>
5215 param_type(_InputIterator __wbegin,
5216 _InputIterator __wend)
5217 : _M_prob(__wbegin, __wend), _M_cp()
5218 { _M_initialize(); }
5220 param_type(initializer_list<double> __wil)
5221 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
5222 { _M_initialize(); }
5224 template<typename _Func>
5225 param_type(size_t __nw, double __xmin, double __xmax,
5226 _Func __fw);
5228 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5229 param_type(const param_type&) = default;
5230 param_type& operator=(const param_type&) = default;
5232 std::vector<double>
5233 probabilities() const
5234 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
5236 friend bool
5237 operator==(const param_type& __p1, const param_type& __p2)
5238 { return __p1._M_prob == __p2._M_prob; }
5240 friend bool
5241 operator!=(const param_type& __p1, const param_type& __p2)
5242 { return !(__p1 == __p2); }
5244 private:
5245 void
5246 _M_initialize();
5248 std::vector<double> _M_prob;
5249 std::vector<double> _M_cp;
5252 discrete_distribution()
5253 : _M_param()
5256 template<typename _InputIterator>
5257 discrete_distribution(_InputIterator __wbegin,
5258 _InputIterator __wend)
5259 : _M_param(__wbegin, __wend)
5262 discrete_distribution(initializer_list<double> __wl)
5263 : _M_param(__wl)
5266 template<typename _Func>
5267 discrete_distribution(size_t __nw, double __xmin, double __xmax,
5268 _Func __fw)
5269 : _M_param(__nw, __xmin, __xmax, __fw)
5272 explicit
5273 discrete_distribution(const param_type& __p)
5274 : _M_param(__p)
5278 * @brief Resets the distribution state.
5280 void
5281 reset()
5285 * @brief Returns the probabilities of the distribution.
5287 std::vector<double>
5288 probabilities() const
5290 return _M_param._M_prob.empty()
5291 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
5295 * @brief Returns the parameter set of the distribution.
5297 param_type
5298 param() const
5299 { return _M_param; }
5302 * @brief Sets the parameter set of the distribution.
5303 * @param __param The new parameter set of the distribution.
5305 void
5306 param(const param_type& __param)
5307 { _M_param = __param; }
5310 * @brief Returns the greatest lower bound value of the distribution.
5312 result_type
5313 min() const
5314 { return result_type(0); }
5317 * @brief Returns the least upper bound value of the distribution.
5319 result_type
5320 max() const
5322 return _M_param._M_prob.empty()
5323 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
5327 * @brief Generating functions.
5329 template<typename _UniformRandomNumberGenerator>
5330 result_type
5331 operator()(_UniformRandomNumberGenerator& __urng)
5332 { return this->operator()(__urng, _M_param); }
5334 template<typename _UniformRandomNumberGenerator>
5335 result_type
5336 operator()(_UniformRandomNumberGenerator& __urng,
5337 const param_type& __p);
5339 template<typename _ForwardIterator,
5340 typename _UniformRandomNumberGenerator>
5341 void
5342 __generate(_ForwardIterator __f, _ForwardIterator __t,
5343 _UniformRandomNumberGenerator& __urng)
5344 { this->__generate(__f, __t, __urng, _M_param); }
5346 template<typename _ForwardIterator,
5347 typename _UniformRandomNumberGenerator>
5348 void
5349 __generate(_ForwardIterator __f, _ForwardIterator __t,
5350 _UniformRandomNumberGenerator& __urng,
5351 const param_type& __p)
5352 { this->__generate_impl(__f, __t, __urng, __p); }
5354 template<typename _UniformRandomNumberGenerator>
5355 void
5356 __generate(result_type* __f, result_type* __t,
5357 _UniformRandomNumberGenerator& __urng,
5358 const param_type& __p)
5359 { this->__generate_impl(__f, __t, __urng, __p); }
5362 * @brief Return true if two discrete distributions have the same
5363 * parameters.
5365 friend bool
5366 operator==(const discrete_distribution& __d1,
5367 const discrete_distribution& __d2)
5368 { return __d1._M_param == __d2._M_param; }
5371 * @brief Inserts a %discrete_distribution random number distribution
5372 * @p __x into the output stream @p __os.
5374 * @param __os An output stream.
5375 * @param __x A %discrete_distribution random number distribution.
5377 * @returns The output stream with the state of @p __x inserted or in
5378 * an error state.
5380 template<typename _IntType1, typename _CharT, typename _Traits>
5381 friend std::basic_ostream<_CharT, _Traits>&
5382 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5383 const std::discrete_distribution<_IntType1>& __x);
5386 * @brief Extracts a %discrete_distribution random number distribution
5387 * @p __x from the input stream @p __is.
5389 * @param __is An input stream.
5390 * @param __x A %discrete_distribution random number
5391 * generator engine.
5393 * @returns The input stream with @p __x extracted or in an error
5394 * state.
5396 template<typename _IntType1, typename _CharT, typename _Traits>
5397 friend std::basic_istream<_CharT, _Traits>&
5398 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5399 std::discrete_distribution<_IntType1>& __x);
5401 private:
5402 template<typename _ForwardIterator,
5403 typename _UniformRandomNumberGenerator>
5404 void
5405 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5406 _UniformRandomNumberGenerator& __urng,
5407 const param_type& __p);
5409 param_type _M_param;
5413 * @brief Return true if two discrete distributions have different
5414 * parameters.
5416 template<typename _IntType>
5417 inline bool
5418 operator!=(const std::discrete_distribution<_IntType>& __d1,
5419 const std::discrete_distribution<_IntType>& __d2)
5420 { return !(__d1 == __d2); }
5424 * @brief A piecewise_constant_distribution random number distribution.
5426 * The formula for the piecewise constant probability mass function is
5429 template<typename _RealType = double>
5430 class piecewise_constant_distribution
5432 static_assert(std::is_floating_point<_RealType>::value,
5433 "result_type must be a floating point type");
5435 public:
5436 /** The type of the range of the distribution. */
5437 typedef _RealType result_type;
5439 /** Parameter type. */
5440 struct param_type
5442 typedef piecewise_constant_distribution<_RealType> distribution_type;
5443 friend class piecewise_constant_distribution<_RealType>;
5445 param_type()
5446 : _M_int(), _M_den(), _M_cp()
5449 template<typename _InputIteratorB, typename _InputIteratorW>
5450 param_type(_InputIteratorB __bfirst,
5451 _InputIteratorB __bend,
5452 _InputIteratorW __wbegin);
5454 template<typename _Func>
5455 param_type(initializer_list<_RealType> __bi, _Func __fw);
5457 template<typename _Func>
5458 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5459 _Func __fw);
5461 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5462 param_type(const param_type&) = default;
5463 param_type& operator=(const param_type&) = default;
5465 std::vector<_RealType>
5466 intervals() const
5468 if (_M_int.empty())
5470 std::vector<_RealType> __tmp(2);
5471 __tmp[1] = _RealType(1);
5472 return __tmp;
5474 else
5475 return _M_int;
5478 std::vector<double>
5479 densities() const
5480 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
5482 friend bool
5483 operator==(const param_type& __p1, const param_type& __p2)
5484 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
5486 friend bool
5487 operator!=(const param_type& __p1, const param_type& __p2)
5488 { return !(__p1 == __p2); }
5490 private:
5491 void
5492 _M_initialize();
5494 std::vector<_RealType> _M_int;
5495 std::vector<double> _M_den;
5496 std::vector<double> _M_cp;
5499 explicit
5500 piecewise_constant_distribution()
5501 : _M_param()
5504 template<typename _InputIteratorB, typename _InputIteratorW>
5505 piecewise_constant_distribution(_InputIteratorB __bfirst,
5506 _InputIteratorB __bend,
5507 _InputIteratorW __wbegin)
5508 : _M_param(__bfirst, __bend, __wbegin)
5511 template<typename _Func>
5512 piecewise_constant_distribution(initializer_list<_RealType> __bl,
5513 _Func __fw)
5514 : _M_param(__bl, __fw)
5517 template<typename _Func>
5518 piecewise_constant_distribution(size_t __nw,
5519 _RealType __xmin, _RealType __xmax,
5520 _Func __fw)
5521 : _M_param(__nw, __xmin, __xmax, __fw)
5524 explicit
5525 piecewise_constant_distribution(const param_type& __p)
5526 : _M_param(__p)
5530 * @brief Resets the distribution state.
5532 void
5533 reset()
5537 * @brief Returns a vector of the intervals.
5539 std::vector<_RealType>
5540 intervals() const
5542 if (_M_param._M_int.empty())
5544 std::vector<_RealType> __tmp(2);
5545 __tmp[1] = _RealType(1);
5546 return __tmp;
5548 else
5549 return _M_param._M_int;
5553 * @brief Returns a vector of the probability densities.
5555 std::vector<double>
5556 densities() const
5558 return _M_param._M_den.empty()
5559 ? std::vector<double>(1, 1.0) : _M_param._M_den;
5563 * @brief Returns the parameter set of the distribution.
5565 param_type
5566 param() const
5567 { return _M_param; }
5570 * @brief Sets the parameter set of the distribution.
5571 * @param __param The new parameter set of the distribution.
5573 void
5574 param(const param_type& __param)
5575 { _M_param = __param; }
5578 * @brief Returns the greatest lower bound value of the distribution.
5580 result_type
5581 min() const
5583 return _M_param._M_int.empty()
5584 ? result_type(0) : _M_param._M_int.front();
5588 * @brief Returns the least upper bound value of the distribution.
5590 result_type
5591 max() const
5593 return _M_param._M_int.empty()
5594 ? result_type(1) : _M_param._M_int.back();
5598 * @brief Generating functions.
5600 template<typename _UniformRandomNumberGenerator>
5601 result_type
5602 operator()(_UniformRandomNumberGenerator& __urng)
5603 { return this->operator()(__urng, _M_param); }
5605 template<typename _UniformRandomNumberGenerator>
5606 result_type
5607 operator()(_UniformRandomNumberGenerator& __urng,
5608 const param_type& __p);
5610 template<typename _ForwardIterator,
5611 typename _UniformRandomNumberGenerator>
5612 void
5613 __generate(_ForwardIterator __f, _ForwardIterator __t,
5614 _UniformRandomNumberGenerator& __urng)
5615 { this->__generate(__f, __t, __urng, _M_param); }
5617 template<typename _ForwardIterator,
5618 typename _UniformRandomNumberGenerator>
5619 void
5620 __generate(_ForwardIterator __f, _ForwardIterator __t,
5621 _UniformRandomNumberGenerator& __urng,
5622 const param_type& __p)
5623 { this->__generate_impl(__f, __t, __urng, __p); }
5625 template<typename _UniformRandomNumberGenerator>
5626 void
5627 __generate(result_type* __f, result_type* __t,
5628 _UniformRandomNumberGenerator& __urng,
5629 const param_type& __p)
5630 { this->__generate_impl(__f, __t, __urng, __p); }
5633 * @brief Return true if two piecewise constant distributions have the
5634 * same parameters.
5636 friend bool
5637 operator==(const piecewise_constant_distribution& __d1,
5638 const piecewise_constant_distribution& __d2)
5639 { return __d1._M_param == __d2._M_param; }
5642 * @brief Inserts a %piecewise_constant_distribution random
5643 * number distribution @p __x into the output stream @p __os.
5645 * @param __os An output stream.
5646 * @param __x A %piecewise_constant_distribution random number
5647 * distribution.
5649 * @returns The output stream with the state of @p __x inserted or in
5650 * an error state.
5652 template<typename _RealType1, typename _CharT, typename _Traits>
5653 friend std::basic_ostream<_CharT, _Traits>&
5654 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5655 const std::piecewise_constant_distribution<_RealType1>& __x);
5658 * @brief Extracts a %piecewise_constant_distribution random
5659 * number distribution @p __x from the input stream @p __is.
5661 * @param __is An input stream.
5662 * @param __x A %piecewise_constant_distribution random number
5663 * generator engine.
5665 * @returns The input stream with @p __x extracted or in an error
5666 * state.
5668 template<typename _RealType1, typename _CharT, typename _Traits>
5669 friend std::basic_istream<_CharT, _Traits>&
5670 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5671 std::piecewise_constant_distribution<_RealType1>& __x);
5673 private:
5674 template<typename _ForwardIterator,
5675 typename _UniformRandomNumberGenerator>
5676 void
5677 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5678 _UniformRandomNumberGenerator& __urng,
5679 const param_type& __p);
5681 param_type _M_param;
5685 * @brief Return true if two piecewise constant distributions have
5686 * different parameters.
5688 template<typename _RealType>
5689 inline bool
5690 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5691 const std::piecewise_constant_distribution<_RealType>& __d2)
5692 { return !(__d1 == __d2); }
5696 * @brief A piecewise_linear_distribution random number distribution.
5698 * The formula for the piecewise linear probability mass function is
5701 template<typename _RealType = double>
5702 class piecewise_linear_distribution
5704 static_assert(std::is_floating_point<_RealType>::value,
5705 "result_type must be a floating point type");
5707 public:
5708 /** The type of the range of the distribution. */
5709 typedef _RealType result_type;
5711 /** Parameter type. */
5712 struct param_type
5714 typedef piecewise_linear_distribution<_RealType> distribution_type;
5715 friend class piecewise_linear_distribution<_RealType>;
5717 param_type()
5718 : _M_int(), _M_den(), _M_cp(), _M_m()
5721 template<typename _InputIteratorB, typename _InputIteratorW>
5722 param_type(_InputIteratorB __bfirst,
5723 _InputIteratorB __bend,
5724 _InputIteratorW __wbegin);
5726 template<typename _Func>
5727 param_type(initializer_list<_RealType> __bl, _Func __fw);
5729 template<typename _Func>
5730 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5731 _Func __fw);
5733 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5734 param_type(const param_type&) = default;
5735 param_type& operator=(const param_type&) = default;
5737 std::vector<_RealType>
5738 intervals() const
5740 if (_M_int.empty())
5742 std::vector<_RealType> __tmp(2);
5743 __tmp[1] = _RealType(1);
5744 return __tmp;
5746 else
5747 return _M_int;
5750 std::vector<double>
5751 densities() const
5752 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5754 friend bool
5755 operator==(const param_type& __p1, const param_type& __p2)
5756 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
5758 friend bool
5759 operator!=(const param_type& __p1, const param_type& __p2)
5760 { return !(__p1 == __p2); }
5762 private:
5763 void
5764 _M_initialize();
5766 std::vector<_RealType> _M_int;
5767 std::vector<double> _M_den;
5768 std::vector<double> _M_cp;
5769 std::vector<double> _M_m;
5772 explicit
5773 piecewise_linear_distribution()
5774 : _M_param()
5777 template<typename _InputIteratorB, typename _InputIteratorW>
5778 piecewise_linear_distribution(_InputIteratorB __bfirst,
5779 _InputIteratorB __bend,
5780 _InputIteratorW __wbegin)
5781 : _M_param(__bfirst, __bend, __wbegin)
5784 template<typename _Func>
5785 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5786 _Func __fw)
5787 : _M_param(__bl, __fw)
5790 template<typename _Func>
5791 piecewise_linear_distribution(size_t __nw,
5792 _RealType __xmin, _RealType __xmax,
5793 _Func __fw)
5794 : _M_param(__nw, __xmin, __xmax, __fw)
5797 explicit
5798 piecewise_linear_distribution(const param_type& __p)
5799 : _M_param(__p)
5803 * Resets the distribution state.
5805 void
5806 reset()
5810 * @brief Return the intervals of the distribution.
5812 std::vector<_RealType>
5813 intervals() const
5815 if (_M_param._M_int.empty())
5817 std::vector<_RealType> __tmp(2);
5818 __tmp[1] = _RealType(1);
5819 return __tmp;
5821 else
5822 return _M_param._M_int;
5826 * @brief Return a vector of the probability densities of the
5827 * distribution.
5829 std::vector<double>
5830 densities() const
5832 return _M_param._M_den.empty()
5833 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5837 * @brief Returns the parameter set of the distribution.
5839 param_type
5840 param() const
5841 { return _M_param; }
5844 * @brief Sets the parameter set of the distribution.
5845 * @param __param The new parameter set of the distribution.
5847 void
5848 param(const param_type& __param)
5849 { _M_param = __param; }
5852 * @brief Returns the greatest lower bound value of the distribution.
5854 result_type
5855 min() const
5857 return _M_param._M_int.empty()
5858 ? result_type(0) : _M_param._M_int.front();
5862 * @brief Returns the least upper bound value of the distribution.
5864 result_type
5865 max() const
5867 return _M_param._M_int.empty()
5868 ? result_type(1) : _M_param._M_int.back();
5872 * @brief Generating functions.
5874 template<typename _UniformRandomNumberGenerator>
5875 result_type
5876 operator()(_UniformRandomNumberGenerator& __urng)
5877 { return this->operator()(__urng, _M_param); }
5879 template<typename _UniformRandomNumberGenerator>
5880 result_type
5881 operator()(_UniformRandomNumberGenerator& __urng,
5882 const param_type& __p);
5884 template<typename _ForwardIterator,
5885 typename _UniformRandomNumberGenerator>
5886 void
5887 __generate(_ForwardIterator __f, _ForwardIterator __t,
5888 _UniformRandomNumberGenerator& __urng)
5889 { this->__generate(__f, __t, __urng, _M_param); }
5891 template<typename _ForwardIterator,
5892 typename _UniformRandomNumberGenerator>
5893 void
5894 __generate(_ForwardIterator __f, _ForwardIterator __t,
5895 _UniformRandomNumberGenerator& __urng,
5896 const param_type& __p)
5897 { this->__generate_impl(__f, __t, __urng, __p); }
5899 template<typename _UniformRandomNumberGenerator>
5900 void
5901 __generate(result_type* __f, result_type* __t,
5902 _UniformRandomNumberGenerator& __urng,
5903 const param_type& __p)
5904 { this->__generate_impl(__f, __t, __urng, __p); }
5907 * @brief Return true if two piecewise linear distributions have the
5908 * same parameters.
5910 friend bool
5911 operator==(const piecewise_linear_distribution& __d1,
5912 const piecewise_linear_distribution& __d2)
5913 { return __d1._M_param == __d2._M_param; }
5916 * @brief Inserts a %piecewise_linear_distribution random number
5917 * distribution @p __x into the output stream @p __os.
5919 * @param __os An output stream.
5920 * @param __x A %piecewise_linear_distribution random number
5921 * distribution.
5923 * @returns The output stream with the state of @p __x inserted or in
5924 * an error state.
5926 template<typename _RealType1, typename _CharT, typename _Traits>
5927 friend std::basic_ostream<_CharT, _Traits>&
5928 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5929 const std::piecewise_linear_distribution<_RealType1>& __x);
5932 * @brief Extracts a %piecewise_linear_distribution random number
5933 * distribution @p __x from the input stream @p __is.
5935 * @param __is An input stream.
5936 * @param __x A %piecewise_linear_distribution random number
5937 * generator engine.
5939 * @returns The input stream with @p __x extracted or in an error
5940 * state.
5942 template<typename _RealType1, typename _CharT, typename _Traits>
5943 friend std::basic_istream<_CharT, _Traits>&
5944 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5945 std::piecewise_linear_distribution<_RealType1>& __x);
5947 private:
5948 template<typename _ForwardIterator,
5949 typename _UniformRandomNumberGenerator>
5950 void
5951 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
5952 _UniformRandomNumberGenerator& __urng,
5953 const param_type& __p);
5955 param_type _M_param;
5959 * @brief Return true if two piecewise linear distributions have
5960 * different parameters.
5962 template<typename _RealType>
5963 inline bool
5964 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5965 const std::piecewise_linear_distribution<_RealType>& __d2)
5966 { return !(__d1 == __d2); }
5969 /* @} */ // group random_distributions_poisson
5971 /* @} */ // group random_distributions
5974 * @addtogroup random_utilities Random Number Utilities
5975 * @ingroup random
5976 * @{
5980 * @brief The seed_seq class generates sequences of seeds for random
5981 * number generators.
5983 class seed_seq
5985 public:
5986 /** The type of the seed vales. */
5987 typedef uint_least32_t result_type;
5989 /** Default constructor. */
5990 seed_seq() noexcept
5991 : _M_v()
5994 template<typename _IntType>
5995 seed_seq(std::initializer_list<_IntType> il);
5997 template<typename _InputIterator>
5998 seed_seq(_InputIterator __begin, _InputIterator __end);
6000 // generating functions
6001 template<typename _RandomAccessIterator>
6002 void
6003 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
6005 // property functions
6006 size_t size() const noexcept
6007 { return _M_v.size(); }
6009 template<typename OutputIterator>
6010 void
6011 param(OutputIterator __dest) const
6012 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
6014 // no copy functions
6015 seed_seq(const seed_seq&) = delete;
6016 seed_seq& operator=(const seed_seq&) = delete;
6018 private:
6019 std::vector<result_type> _M_v;
6022 /* @} */ // group random_utilities
6024 /* @} */ // group random
6026 _GLIBCXX_END_NAMESPACE_VERSION
6027 } // namespace std
6029 #endif