2012-01-18 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / bits / random.h
blobd109224d1bf2b38b799e1bedfa4d761fd6b7941f
1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /**
26 * @file bits/random.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{random}
31 #ifndef _RANDOM_H
32 #define _RANDOM_H 1
34 #include <vector>
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 // [26.4] Random number generation
42 /**
43 * @defgroup random Random Number Generation
44 * @ingroup numerics
46 * A facility for generating random numbers on selected distributions.
47 * @{
50 /**
51 * @brief A function template for converting the output of a (integral)
52 * uniform random number generator to a floatng point result in the range
53 * [0-1).
55 template<typename _RealType, size_t __bits,
56 typename _UniformRandomNumberGenerator>
57 _RealType
58 generate_canonical(_UniformRandomNumberGenerator& __g);
60 _GLIBCXX_END_NAMESPACE_VERSION
63 * Implementation-space details.
65 namespace __detail
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _UIntType, size_t __w,
70 bool = __w < static_cast<size_t>
71 (std::numeric_limits<_UIntType>::digits)>
72 struct _Shift
73 { static const _UIntType __value = 0; };
75 template<typename _UIntType, size_t __w>
76 struct _Shift<_UIntType, __w, true>
77 { static const _UIntType __value = _UIntType(1) << __w; };
79 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
80 struct _Mod;
82 // Dispatch based on modulus value to prevent divide-by-zero compile-time
83 // errors when m == 0.
84 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
85 inline _Tp
86 __mod(_Tp __x)
87 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
90 * An adaptor class for converting the output of any Generator into
91 * the input for a specific Distribution.
93 template<typename _Engine, typename _DInputType>
94 struct _Adaptor
97 public:
98 _Adaptor(_Engine& __g)
99 : _M_g(__g) { }
101 _DInputType
102 min() const
103 { return _DInputType(0); }
105 _DInputType
106 max() const
107 { return _DInputType(1); }
110 * Converts a value generated by the adapted random number generator
111 * into a value in the input domain for the dependent random number
112 * distribution.
114 _DInputType
115 operator()()
117 return std::generate_canonical<_DInputType,
118 std::numeric_limits<_DInputType>::digits,
119 _Engine>(_M_g);
122 private:
123 _Engine& _M_g;
126 _GLIBCXX_END_NAMESPACE_VERSION
127 } // namespace __detail
129 _GLIBCXX_BEGIN_NAMESPACE_VERSION
132 * @addtogroup random_generators Random Number Generators
133 * @ingroup random
135 * These classes define objects which provide random or pseudorandom
136 * numbers, either from a discrete or a continuous interval. The
137 * random number generator supplied as a part of this library are
138 * all uniform random number generators which provide a sequence of
139 * random number uniformly distributed over their range.
141 * A number generator is a function object with an operator() that
142 * takes zero arguments and returns a number.
144 * A compliant random number generator must satisfy the following
145 * requirements. <table border=1 cellpadding=10 cellspacing=0>
146 * <caption align=top>Random Number Generator Requirements</caption>
147 * <tr><td>To be documented.</td></tr> </table>
149 * @{
153 * @brief A model of a linear congruential random number generator.
155 * A random number generator that produces pseudorandom numbers via
156 * linear function:
157 * @f[
158 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
159 * @f]
161 * The template parameter @p _UIntType must be an unsigned integral type
162 * large enough to store values up to (__m-1). If the template parameter
163 * @p __m is 0, the modulus @p __m used is
164 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
165 * parameters @p __a and @p __c must be less than @p __m.
167 * The size of the state is @f$1@f$.
169 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
170 class linear_congruential_engine
172 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
173 "substituting _UIntType not an unsigned integral type");
174 static_assert(__m == 0u || (__a < __m && __c < __m),
175 "template argument substituting __m out of bounds");
177 public:
178 /** The type of the generated random value. */
179 typedef _UIntType result_type;
181 /** The multiplier. */
182 static constexpr result_type multiplier = __a;
183 /** An increment. */
184 static constexpr result_type increment = __c;
185 /** The modulus. */
186 static constexpr result_type modulus = __m;
187 static constexpr result_type default_seed = 1u;
190 * @brief Constructs a %linear_congruential_engine random number
191 * generator engine with seed @p __s. The default seed value
192 * is 1.
194 * @param __s The initial seed value.
196 explicit
197 linear_congruential_engine(result_type __s = default_seed)
198 { seed(__s); }
201 * @brief Constructs a %linear_congruential_engine random number
202 * generator engine seeded from the seed sequence @p __q.
204 * @param __q the seed sequence.
206 template<typename _Sseq, typename = typename
207 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
208 ::type>
209 explicit
210 linear_congruential_engine(_Sseq& __q)
211 { seed(__q); }
214 * @brief Reseeds the %linear_congruential_engine random number generator
215 * engine sequence to the seed @p __s.
217 * @param __s The new seed.
219 void
220 seed(result_type __s = default_seed);
223 * @brief Reseeds the %linear_congruential_engine random number generator
224 * engine
225 * sequence using values from the seed sequence @p __q.
227 * @param __q the seed sequence.
229 template<typename _Sseq>
230 typename std::enable_if<std::is_class<_Sseq>::value>::type
231 seed(_Sseq& __q);
234 * @brief Gets the smallest possible value in the output range.
236 * The minimum depends on the @p __c parameter: if it is zero, the
237 * minimum generated must be > 0, otherwise 0 is allowed.
239 static constexpr result_type
240 min()
241 { return __c == 0u ? 1u : 0u; }
244 * @brief Gets the largest possible value in the output range.
246 static constexpr result_type
247 max()
248 { return __m - 1u; }
251 * @brief Discard a sequence of random numbers.
253 void
254 discard(unsigned long long __z)
256 for (; __z != 0ULL; --__z)
257 (*this)();
261 * @brief Gets the next random number in the sequence.
263 result_type
264 operator()()
266 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
267 return _M_x;
271 * @brief Compares two linear congruential random number generator
272 * objects of the same type for equality.
274 * @param __lhs A linear congruential random number generator object.
275 * @param __rhs Another linear congruential random number generator
276 * object.
278 * @returns true if the infinite sequences of generated values
279 * would be equal, false otherwise.
281 friend bool
282 operator==(const linear_congruential_engine& __lhs,
283 const linear_congruential_engine& __rhs)
284 { return __lhs._M_x == __rhs._M_x; }
287 * @brief Writes the textual representation of the state x(i) of x to
288 * @p __os.
290 * @param __os The output stream.
291 * @param __lcr A % linear_congruential_engine random number generator.
292 * @returns __os.
294 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
295 _UIntType1 __m1, typename _CharT, typename _Traits>
296 friend std::basic_ostream<_CharT, _Traits>&
297 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
298 const std::linear_congruential_engine<_UIntType1,
299 __a1, __c1, __m1>& __lcr);
302 * @brief Sets the state of the engine by reading its textual
303 * representation from @p __is.
305 * The textual representation must have been previously written using
306 * an output stream whose imbued locale and whose type's template
307 * specialization arguments _CharT and _Traits were the same as those
308 * of @p __is.
310 * @param __is The input stream.
311 * @param __lcr A % linear_congruential_engine random number generator.
312 * @returns __is.
314 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
315 _UIntType1 __m1, typename _CharT, typename _Traits>
316 friend std::basic_istream<_CharT, _Traits>&
317 operator>>(std::basic_istream<_CharT, _Traits>& __is,
318 std::linear_congruential_engine<_UIntType1, __a1,
319 __c1, __m1>& __lcr);
321 private:
322 _UIntType _M_x;
326 * @brief Compares two linear congruential random number generator
327 * objects of the same type for inequality.
329 * @param __lhs A linear congruential random number generator object.
330 * @param __rhs Another linear congruential random number generator
331 * object.
333 * @returns true if the infinite sequences of generated values
334 * would be different, false otherwise.
336 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
337 inline bool
338 operator!=(const std::linear_congruential_engine<_UIntType, __a,
339 __c, __m>& __lhs,
340 const std::linear_congruential_engine<_UIntType, __a,
341 __c, __m>& __rhs)
342 { return !(__lhs == __rhs); }
346 * A generalized feedback shift register discrete random number generator.
348 * This algorithm avoids multiplication and division and is designed to be
349 * friendly to a pipelined architecture. If the parameters are chosen
350 * correctly, this generator will produce numbers with a very long period and
351 * fairly good apparent entropy, although still not cryptographically strong.
353 * The best way to use this generator is with the predefined mt19937 class.
355 * This algorithm was originally invented by Makoto Matsumoto and
356 * Takuji Nishimura.
358 * @tparam __w Word size, the number of bits in each element of
359 * the state vector.
360 * @tparam __n The degree of recursion.
361 * @tparam __m The period parameter.
362 * @tparam __r The separation point bit index.
363 * @tparam __a The last row of the twist matrix.
364 * @tparam __u The first right-shift tempering matrix parameter.
365 * @tparam __d The first right-shift tempering matrix mask.
366 * @tparam __s The first left-shift tempering matrix parameter.
367 * @tparam __b The first left-shift tempering matrix mask.
368 * @tparam __t The second left-shift tempering matrix parameter.
369 * @tparam __c The second left-shift tempering matrix mask.
370 * @tparam __l The second right-shift tempering matrix parameter.
371 * @tparam __f Initialization multiplier.
373 template<typename _UIntType, size_t __w,
374 size_t __n, size_t __m, size_t __r,
375 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
376 _UIntType __b, size_t __t,
377 _UIntType __c, size_t __l, _UIntType __f>
378 class mersenne_twister_engine
380 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
381 "substituting _UIntType not an unsigned integral type");
382 static_assert(1u <= __m && __m <= __n,
383 "template argument substituting __m out of bounds");
384 static_assert(__r <= __w, "template argument substituting "
385 "__r out of bound");
386 static_assert(__u <= __w, "template argument substituting "
387 "__u out of bound");
388 static_assert(__s <= __w, "template argument substituting "
389 "__s out of bound");
390 static_assert(__t <= __w, "template argument substituting "
391 "__t out of bound");
392 static_assert(__l <= __w, "template argument substituting "
393 "__l out of bound");
394 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
395 "template argument substituting __w out of bound");
396 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
397 "template argument substituting __a out of bound");
398 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
399 "template argument substituting __b out of bound");
400 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
401 "template argument substituting __c out of bound");
402 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
403 "template argument substituting __d out of bound");
404 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
405 "template argument substituting __f out of bound");
407 public:
408 /** The type of the generated random value. */
409 typedef _UIntType result_type;
411 // parameter values
412 static constexpr size_t word_size = __w;
413 static constexpr size_t state_size = __n;
414 static constexpr size_t shift_size = __m;
415 static constexpr size_t mask_bits = __r;
416 static constexpr result_type xor_mask = __a;
417 static constexpr size_t tempering_u = __u;
418 static constexpr result_type tempering_d = __d;
419 static constexpr size_t tempering_s = __s;
420 static constexpr result_type tempering_b = __b;
421 static constexpr size_t tempering_t = __t;
422 static constexpr result_type tempering_c = __c;
423 static constexpr size_t tempering_l = __l;
424 static constexpr result_type initialization_multiplier = __f;
425 static constexpr result_type default_seed = 5489u;
427 // constructors and member function
428 explicit
429 mersenne_twister_engine(result_type __sd = default_seed)
430 { seed(__sd); }
433 * @brief Constructs a %mersenne_twister_engine random number generator
434 * engine seeded from the seed sequence @p __q.
436 * @param __q the seed sequence.
438 template<typename _Sseq, typename = typename
439 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
440 ::type>
441 explicit
442 mersenne_twister_engine(_Sseq& __q)
443 { seed(__q); }
445 void
446 seed(result_type __sd = default_seed);
448 template<typename _Sseq>
449 typename std::enable_if<std::is_class<_Sseq>::value>::type
450 seed(_Sseq& __q);
453 * @brief Gets the smallest possible value in the output range.
455 static constexpr result_type
456 min()
457 { return 0; };
460 * @brief Gets the largest possible value in the output range.
462 static constexpr result_type
463 max()
464 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
467 * @brief Discard a sequence of random numbers.
469 void
470 discard(unsigned long long __z)
472 for (; __z != 0ULL; --__z)
473 (*this)();
476 result_type
477 operator()();
480 * @brief Compares two % mersenne_twister_engine random number generator
481 * objects of the same type for equality.
483 * @param __lhs A % mersenne_twister_engine random number generator
484 * object.
485 * @param __rhs Another % mersenne_twister_engine random number
486 * generator object.
488 * @returns true if the infinite sequences of generated values
489 * would be equal, false otherwise.
491 friend bool
492 operator==(const mersenne_twister_engine& __lhs,
493 const mersenne_twister_engine& __rhs)
494 { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
495 && __lhs._M_p == __rhs._M_p); }
498 * @brief Inserts the current state of a % mersenne_twister_engine
499 * random number generator engine @p __x into the output stream
500 * @p __os.
502 * @param __os An output stream.
503 * @param __x A % mersenne_twister_engine random number generator
504 * engine.
506 * @returns The output stream with the state of @p __x inserted or in
507 * an error state.
509 template<typename _UIntType1,
510 size_t __w1, size_t __n1,
511 size_t __m1, size_t __r1,
512 _UIntType1 __a1, size_t __u1,
513 _UIntType1 __d1, size_t __s1,
514 _UIntType1 __b1, size_t __t1,
515 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
516 typename _CharT, typename _Traits>
517 friend std::basic_ostream<_CharT, _Traits>&
518 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
519 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
520 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
521 __l1, __f1>& __x);
524 * @brief Extracts the current state of a % mersenne_twister_engine
525 * random number generator engine @p __x from the input stream
526 * @p __is.
528 * @param __is An input stream.
529 * @param __x A % mersenne_twister_engine random number generator
530 * engine.
532 * @returns The input stream with the state of @p __x extracted or in
533 * an error state.
535 template<typename _UIntType1,
536 size_t __w1, size_t __n1,
537 size_t __m1, size_t __r1,
538 _UIntType1 __a1, size_t __u1,
539 _UIntType1 __d1, size_t __s1,
540 _UIntType1 __b1, size_t __t1,
541 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
542 typename _CharT, typename _Traits>
543 friend std::basic_istream<_CharT, _Traits>&
544 operator>>(std::basic_istream<_CharT, _Traits>& __is,
545 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
546 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
547 __l1, __f1>& __x);
549 private:
550 _UIntType _M_x[state_size];
551 size_t _M_p;
555 * @brief Compares two % mersenne_twister_engine random number generator
556 * objects of the same type for inequality.
558 * @param __lhs A % mersenne_twister_engine random number generator
559 * object.
560 * @param __rhs Another % mersenne_twister_engine random number
561 * generator object.
563 * @returns true if the infinite sequences of generated values
564 * would be different, false otherwise.
566 template<typename _UIntType, size_t __w,
567 size_t __n, size_t __m, size_t __r,
568 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
569 _UIntType __b, size_t __t,
570 _UIntType __c, size_t __l, _UIntType __f>
571 inline bool
572 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
573 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
574 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
575 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
576 { return !(__lhs == __rhs); }
580 * @brief The Marsaglia-Zaman generator.
582 * This is a model of a Generalized Fibonacci discrete random number
583 * generator, sometimes referred to as the SWC generator.
585 * A discrete random number generator that produces pseudorandom
586 * numbers using:
587 * @f[
588 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
589 * @f]
591 * The size of the state is @f$r@f$
592 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
594 * @var _M_x The state of the generator. This is a ring buffer.
595 * @var _M_carry The carry.
596 * @var _M_p Current index of x(i - r).
598 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
599 class subtract_with_carry_engine
601 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
602 "substituting _UIntType not an unsigned integral type");
603 static_assert(0u < __s && __s < __r,
604 "template argument substituting __s out of bounds");
605 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
606 "template argument substituting __w out of bounds");
608 public:
609 /** The type of the generated random value. */
610 typedef _UIntType result_type;
612 // parameter values
613 static constexpr size_t word_size = __w;
614 static constexpr size_t short_lag = __s;
615 static constexpr size_t long_lag = __r;
616 static constexpr result_type default_seed = 19780503u;
619 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
620 * random number generator.
622 explicit
623 subtract_with_carry_engine(result_type __sd = default_seed)
624 { seed(__sd); }
627 * @brief Constructs a %subtract_with_carry_engine random number engine
628 * seeded from the seed sequence @p __q.
630 * @param __q the seed sequence.
632 template<typename _Sseq, typename = typename
633 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
634 ::type>
635 explicit
636 subtract_with_carry_engine(_Sseq& __q)
637 { seed(__q); }
640 * @brief Seeds the initial state @f$x_0@f$ of the random number
641 * generator.
643 * N1688[4.19] modifies this as follows. If @p __value == 0,
644 * sets value to 19780503. In any case, with a linear
645 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
646 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
647 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
648 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
649 * set carry to 1, otherwise sets carry to 0.
651 void
652 seed(result_type __sd = default_seed);
655 * @brief Seeds the initial state @f$x_0@f$ of the
656 * % subtract_with_carry_engine random number generator.
658 template<typename _Sseq>
659 typename std::enable_if<std::is_class<_Sseq>::value>::type
660 seed(_Sseq& __q);
663 * @brief Gets the inclusive minimum value of the range of random
664 * integers returned by this generator.
666 static constexpr result_type
667 min()
668 { return 0; }
671 * @brief Gets the inclusive maximum value of the range of random
672 * integers returned by this generator.
674 static constexpr result_type
675 max()
676 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
679 * @brief Discard a sequence of random numbers.
681 void
682 discard(unsigned long long __z)
684 for (; __z != 0ULL; --__z)
685 (*this)();
689 * @brief Gets the next random number in the sequence.
691 result_type
692 operator()();
695 * @brief Compares two % subtract_with_carry_engine random number
696 * generator objects of the same type for equality.
698 * @param __lhs A % subtract_with_carry_engine random number generator
699 * object.
700 * @param __rhs Another % subtract_with_carry_engine random number
701 * generator object.
703 * @returns true if the infinite sequences of generated values
704 * would be equal, false otherwise.
706 friend bool
707 operator==(const subtract_with_carry_engine& __lhs,
708 const subtract_with_carry_engine& __rhs)
709 { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
710 && __lhs._M_carry == __rhs._M_carry
711 && __lhs._M_p == __rhs._M_p); }
714 * @brief Inserts the current state of a % subtract_with_carry_engine
715 * random number generator engine @p __x into the output stream
716 * @p __os.
718 * @param __os An output stream.
719 * @param __x A % subtract_with_carry_engine random number generator
720 * engine.
722 * @returns The output stream with the state of @p __x inserted or in
723 * an error state.
725 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
726 typename _CharT, typename _Traits>
727 friend std::basic_ostream<_CharT, _Traits>&
728 operator<<(std::basic_ostream<_CharT, _Traits>&,
729 const std::subtract_with_carry_engine<_UIntType1, __w1,
730 __s1, __r1>&);
733 * @brief Extracts the current state of a % subtract_with_carry_engine
734 * random number generator engine @p __x from the input stream
735 * @p __is.
737 * @param __is An input stream.
738 * @param __x A % subtract_with_carry_engine random number generator
739 * engine.
741 * @returns The input stream with the state of @p __x extracted or in
742 * an error state.
744 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
745 typename _CharT, typename _Traits>
746 friend std::basic_istream<_CharT, _Traits>&
747 operator>>(std::basic_istream<_CharT, _Traits>&,
748 std::subtract_with_carry_engine<_UIntType1, __w1,
749 __s1, __r1>&);
751 private:
752 _UIntType _M_x[long_lag];
753 _UIntType _M_carry;
754 size_t _M_p;
758 * @brief Compares two % subtract_with_carry_engine random number
759 * generator objects of the same type for inequality.
761 * @param __lhs A % subtract_with_carry_engine random number generator
762 * object.
763 * @param __rhs Another % subtract_with_carry_engine random number
764 * generator object.
766 * @returns true if the infinite sequences of generated values
767 * would be different, false otherwise.
769 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
770 inline bool
771 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
772 __s, __r>& __lhs,
773 const std::subtract_with_carry_engine<_UIntType, __w,
774 __s, __r>& __rhs)
775 { return !(__lhs == __rhs); }
779 * Produces random numbers from some base engine by discarding blocks of
780 * data.
782 * 0 <= @p __r <= @p __p
784 template<typename _RandomNumberEngine, size_t __p, size_t __r>
785 class discard_block_engine
787 static_assert(1 <= __r && __r <= __p,
788 "template argument substituting __r out of bounds");
790 public:
791 /** The type of the generated random value. */
792 typedef typename _RandomNumberEngine::result_type result_type;
794 // parameter values
795 static constexpr size_t block_size = __p;
796 static constexpr size_t used_block = __r;
799 * @brief Constructs a default %discard_block_engine engine.
801 * The underlying engine is default constructed as well.
803 discard_block_engine()
804 : _M_b(), _M_n(0) { }
807 * @brief Copy constructs a %discard_block_engine engine.
809 * Copies an existing base class random number generator.
810 * @param __rng An existing (base class) engine object.
812 explicit
813 discard_block_engine(const _RandomNumberEngine& __rng)
814 : _M_b(__rng), _M_n(0) { }
817 * @brief Move constructs a %discard_block_engine engine.
819 * Copies an existing base class random number generator.
820 * @param __rng An existing (base class) engine object.
822 explicit
823 discard_block_engine(_RandomNumberEngine&& __rng)
824 : _M_b(std::move(__rng)), _M_n(0) { }
827 * @brief Seed constructs a %discard_block_engine engine.
829 * Constructs the underlying generator engine seeded with @p __s.
830 * @param __s A seed value for the base class engine.
832 explicit
833 discard_block_engine(result_type __s)
834 : _M_b(__s), _M_n(0) { }
837 * @brief Generator construct a %discard_block_engine engine.
839 * @param __q A seed sequence.
841 template<typename _Sseq, typename = typename
842 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
843 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
844 ::type>
845 explicit
846 discard_block_engine(_Sseq& __q)
847 : _M_b(__q), _M_n(0)
851 * @brief Reseeds the %discard_block_engine object with the default
852 * seed for the underlying base class generator engine.
854 void
855 seed()
857 _M_b.seed();
858 _M_n = 0;
862 * @brief Reseeds the %discard_block_engine object with the default
863 * seed for the underlying base class generator engine.
865 void
866 seed(result_type __s)
868 _M_b.seed(__s);
869 _M_n = 0;
873 * @brief Reseeds the %discard_block_engine object with the given seed
874 * sequence.
875 * @param __q A seed generator function.
877 template<typename _Sseq>
878 void
879 seed(_Sseq& __q)
881 _M_b.seed(__q);
882 _M_n = 0;
886 * @brief Gets a const reference to the underlying generator engine
887 * object.
889 const _RandomNumberEngine&
890 base() const noexcept
891 { return _M_b; }
894 * @brief Gets the minimum value in the generated random number range.
896 static constexpr result_type
897 min()
898 { return _RandomNumberEngine::min(); }
901 * @brief Gets the maximum value in the generated random number range.
903 static constexpr result_type
904 max()
905 { return _RandomNumberEngine::max(); }
908 * @brief Discard a sequence of random numbers.
910 void
911 discard(unsigned long long __z)
913 for (; __z != 0ULL; --__z)
914 (*this)();
918 * @brief Gets the next value in the generated random number sequence.
920 result_type
921 operator()();
924 * @brief Compares two %discard_block_engine random number generator
925 * objects of the same type for equality.
927 * @param __lhs A %discard_block_engine random number generator object.
928 * @param __rhs Another %discard_block_engine random number generator
929 * object.
931 * @returns true if the infinite sequences of generated values
932 * would be equal, false otherwise.
934 friend bool
935 operator==(const discard_block_engine& __lhs,
936 const discard_block_engine& __rhs)
937 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
940 * @brief Inserts the current state of a %discard_block_engine random
941 * number generator engine @p __x into the output stream
942 * @p __os.
944 * @param __os An output stream.
945 * @param __x A %discard_block_engine random number generator engine.
947 * @returns The output stream with the state of @p __x inserted or in
948 * an error state.
950 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
951 typename _CharT, typename _Traits>
952 friend std::basic_ostream<_CharT, _Traits>&
953 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
954 const std::discard_block_engine<_RandomNumberEngine1,
955 __p1, __r1>& __x);
958 * @brief Extracts the current state of a % subtract_with_carry_engine
959 * random number generator engine @p __x from the input stream
960 * @p __is.
962 * @param __is An input stream.
963 * @param __x A %discard_block_engine random number generator engine.
965 * @returns The input stream with the state of @p __x extracted or in
966 * an error state.
968 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
969 typename _CharT, typename _Traits>
970 friend std::basic_istream<_CharT, _Traits>&
971 operator>>(std::basic_istream<_CharT, _Traits>& __is,
972 std::discard_block_engine<_RandomNumberEngine1,
973 __p1, __r1>& __x);
975 private:
976 _RandomNumberEngine _M_b;
977 size_t _M_n;
981 * @brief Compares two %discard_block_engine random number generator
982 * objects of the same type for inequality.
984 * @param __lhs A %discard_block_engine random number generator object.
985 * @param __rhs Another %discard_block_engine random number generator
986 * object.
988 * @returns true if the infinite sequences of generated values
989 * would be different, false otherwise.
991 template<typename _RandomNumberEngine, size_t __p, size_t __r>
992 inline bool
993 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
994 __r>& __lhs,
995 const std::discard_block_engine<_RandomNumberEngine, __p,
996 __r>& __rhs)
997 { return !(__lhs == __rhs); }
1001 * Produces random numbers by combining random numbers from some base
1002 * engine to produce random numbers with a specifies number of bits @p __w.
1004 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1005 class independent_bits_engine
1007 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1008 "substituting _UIntType not an unsigned integral type");
1009 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1010 "template argument substituting __w out of bounds");
1012 public:
1013 /** The type of the generated random value. */
1014 typedef _UIntType result_type;
1017 * @brief Constructs a default %independent_bits_engine engine.
1019 * The underlying engine is default constructed as well.
1021 independent_bits_engine()
1022 : _M_b() { }
1025 * @brief Copy constructs a %independent_bits_engine engine.
1027 * Copies an existing base class random number generator.
1028 * @param __rng An existing (base class) engine object.
1030 explicit
1031 independent_bits_engine(const _RandomNumberEngine& __rng)
1032 : _M_b(__rng) { }
1035 * @brief Move constructs a %independent_bits_engine engine.
1037 * Copies an existing base class random number generator.
1038 * @param __rng An existing (base class) engine object.
1040 explicit
1041 independent_bits_engine(_RandomNumberEngine&& __rng)
1042 : _M_b(std::move(__rng)) { }
1045 * @brief Seed constructs a %independent_bits_engine engine.
1047 * Constructs the underlying generator engine seeded with @p __s.
1048 * @param __s A seed value for the base class engine.
1050 explicit
1051 independent_bits_engine(result_type __s)
1052 : _M_b(__s) { }
1055 * @brief Generator construct a %independent_bits_engine engine.
1057 * @param __q A seed sequence.
1059 template<typename _Sseq, typename = typename
1060 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1061 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1062 ::type>
1063 explicit
1064 independent_bits_engine(_Sseq& __q)
1065 : _M_b(__q)
1069 * @brief Reseeds the %independent_bits_engine object with the default
1070 * seed for the underlying base class generator engine.
1072 void
1073 seed()
1074 { _M_b.seed(); }
1077 * @brief Reseeds the %independent_bits_engine object with the default
1078 * seed for the underlying base class generator engine.
1080 void
1081 seed(result_type __s)
1082 { _M_b.seed(__s); }
1085 * @brief Reseeds the %independent_bits_engine object with the given
1086 * seed sequence.
1087 * @param __q A seed generator function.
1089 template<typename _Sseq>
1090 void
1091 seed(_Sseq& __q)
1092 { _M_b.seed(__q); }
1095 * @brief Gets a const reference to the underlying generator engine
1096 * object.
1098 const _RandomNumberEngine&
1099 base() const noexcept
1100 { return _M_b; }
1103 * @brief Gets the minimum value in the generated random number range.
1105 static constexpr result_type
1106 min()
1107 { return 0U; }
1110 * @brief Gets the maximum value in the generated random number range.
1112 static constexpr result_type
1113 max()
1114 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1117 * @brief Discard a sequence of random numbers.
1119 void
1120 discard(unsigned long long __z)
1122 for (; __z != 0ULL; --__z)
1123 (*this)();
1127 * @brief Gets the next value in the generated random number sequence.
1129 result_type
1130 operator()();
1133 * @brief Compares two %independent_bits_engine random number generator
1134 * objects of the same type for equality.
1136 * @param __lhs A %independent_bits_engine random number generator
1137 * object.
1138 * @param __rhs Another %independent_bits_engine random number generator
1139 * object.
1141 * @returns true if the infinite sequences of generated values
1142 * would be equal, false otherwise.
1144 friend bool
1145 operator==(const independent_bits_engine& __lhs,
1146 const independent_bits_engine& __rhs)
1147 { return __lhs._M_b == __rhs._M_b; }
1150 * @brief Extracts the current state of a % subtract_with_carry_engine
1151 * random number generator engine @p __x from the input stream
1152 * @p __is.
1154 * @param __is An input stream.
1155 * @param __x A %independent_bits_engine random number generator
1156 * engine.
1158 * @returns The input stream with the state of @p __x extracted or in
1159 * an error state.
1161 template<typename _CharT, typename _Traits>
1162 friend std::basic_istream<_CharT, _Traits>&
1163 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1164 std::independent_bits_engine<_RandomNumberEngine,
1165 __w, _UIntType>& __x)
1167 __is >> __x._M_b;
1168 return __is;
1171 private:
1172 _RandomNumberEngine _M_b;
1176 * @brief Compares two %independent_bits_engine random number generator
1177 * objects of the same type for inequality.
1179 * @param __lhs A %independent_bits_engine random number generator
1180 * object.
1181 * @param __rhs Another %independent_bits_engine random number generator
1182 * object.
1184 * @returns true if the infinite sequences of generated values
1185 * would be different, false otherwise.
1187 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1188 inline bool
1189 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1190 _UIntType>& __lhs,
1191 const std::independent_bits_engine<_RandomNumberEngine, __w,
1192 _UIntType>& __rhs)
1193 { return !(__lhs == __rhs); }
1196 * @brief Inserts the current state of a %independent_bits_engine random
1197 * number generator engine @p __x into the output stream @p __os.
1199 * @param __os An output stream.
1200 * @param __x A %independent_bits_engine random number generator engine.
1202 * @returns The output stream with the state of @p __x inserted or in
1203 * an error state.
1205 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1206 typename _CharT, typename _Traits>
1207 std::basic_ostream<_CharT, _Traits>&
1208 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1209 const std::independent_bits_engine<_RandomNumberEngine,
1210 __w, _UIntType>& __x)
1212 __os << __x.base();
1213 return __os;
1218 * @brief Produces random numbers by combining random numbers from some
1219 * base engine to produce random numbers with a specifies number of bits
1220 * @p __w.
1222 template<typename _RandomNumberEngine, size_t __k>
1223 class shuffle_order_engine
1225 static_assert(1u <= __k, "template argument substituting "
1226 "__k out of bound");
1228 public:
1229 /** The type of the generated random value. */
1230 typedef typename _RandomNumberEngine::result_type result_type;
1232 static constexpr size_t table_size = __k;
1235 * @brief Constructs a default %shuffle_order_engine engine.
1237 * The underlying engine is default constructed as well.
1239 shuffle_order_engine()
1240 : _M_b()
1241 { _M_initialize(); }
1244 * @brief Copy constructs a %shuffle_order_engine engine.
1246 * Copies an existing base class random number generator.
1247 * @param __rng An existing (base class) engine object.
1249 explicit
1250 shuffle_order_engine(const _RandomNumberEngine& __rng)
1251 : _M_b(__rng)
1252 { _M_initialize(); }
1255 * @brief Move constructs a %shuffle_order_engine engine.
1257 * Copies an existing base class random number generator.
1258 * @param __rng An existing (base class) engine object.
1260 explicit
1261 shuffle_order_engine(_RandomNumberEngine&& __rng)
1262 : _M_b(std::move(__rng))
1263 { _M_initialize(); }
1266 * @brief Seed constructs a %shuffle_order_engine engine.
1268 * Constructs the underlying generator engine seeded with @p __s.
1269 * @param __s A seed value for the base class engine.
1271 explicit
1272 shuffle_order_engine(result_type __s)
1273 : _M_b(__s)
1274 { _M_initialize(); }
1277 * @brief Generator construct a %shuffle_order_engine engine.
1279 * @param __q A seed sequence.
1281 template<typename _Sseq, typename = typename
1282 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1283 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1284 ::type>
1285 explicit
1286 shuffle_order_engine(_Sseq& __q)
1287 : _M_b(__q)
1288 { _M_initialize(); }
1291 * @brief Reseeds the %shuffle_order_engine object with the default seed
1292 for the underlying base class generator engine.
1294 void
1295 seed()
1297 _M_b.seed();
1298 _M_initialize();
1302 * @brief Reseeds the %shuffle_order_engine object with the default seed
1303 * for the underlying base class generator engine.
1305 void
1306 seed(result_type __s)
1308 _M_b.seed(__s);
1309 _M_initialize();
1313 * @brief Reseeds the %shuffle_order_engine object with the given seed
1314 * sequence.
1315 * @param __q A seed generator function.
1317 template<typename _Sseq>
1318 void
1319 seed(_Sseq& __q)
1321 _M_b.seed(__q);
1322 _M_initialize();
1326 * Gets a const reference to the underlying generator engine object.
1328 const _RandomNumberEngine&
1329 base() const noexcept
1330 { return _M_b; }
1333 * Gets the minimum value in the generated random number range.
1335 static constexpr result_type
1336 min()
1337 { return _RandomNumberEngine::min(); }
1340 * Gets the maximum value in the generated random number range.
1342 static constexpr result_type
1343 max()
1344 { return _RandomNumberEngine::max(); }
1347 * Discard a sequence of random numbers.
1349 void
1350 discard(unsigned long long __z)
1352 for (; __z != 0ULL; --__z)
1353 (*this)();
1357 * Gets the next value in the generated random number sequence.
1359 result_type
1360 operator()();
1363 * Compares two %shuffle_order_engine random number generator objects
1364 * of the same type for equality.
1366 * @param __lhs A %shuffle_order_engine random number generator object.
1367 * @param __rhs Another %shuffle_order_engine random number generator
1368 * object.
1370 * @returns true if the infinite sequences of generated values
1371 * would be equal, false otherwise.
1373 friend bool
1374 operator==(const shuffle_order_engine& __lhs,
1375 const shuffle_order_engine& __rhs)
1376 { return (__lhs._M_b == __rhs._M_b
1377 && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
1378 && __lhs._M_y == __rhs._M_y); }
1381 * @brief Inserts the current state of a %shuffle_order_engine random
1382 * number generator engine @p __x into the output stream
1383 @p __os.
1385 * @param __os An output stream.
1386 * @param __x A %shuffle_order_engine random number generator engine.
1388 * @returns The output stream with the state of @p __x inserted or in
1389 * an error state.
1391 template<typename _RandomNumberEngine1, size_t __k1,
1392 typename _CharT, typename _Traits>
1393 friend std::basic_ostream<_CharT, _Traits>&
1394 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1395 const std::shuffle_order_engine<_RandomNumberEngine1,
1396 __k1>& __x);
1399 * @brief Extracts the current state of a % subtract_with_carry_engine
1400 * random number generator engine @p __x from the input stream
1401 * @p __is.
1403 * @param __is An input stream.
1404 * @param __x A %shuffle_order_engine random number generator engine.
1406 * @returns The input stream with the state of @p __x extracted or in
1407 * an error state.
1409 template<typename _RandomNumberEngine1, size_t __k1,
1410 typename _CharT, typename _Traits>
1411 friend std::basic_istream<_CharT, _Traits>&
1412 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1413 std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
1415 private:
1416 void _M_initialize()
1418 for (size_t __i = 0; __i < __k; ++__i)
1419 _M_v[__i] = _M_b();
1420 _M_y = _M_b();
1423 _RandomNumberEngine _M_b;
1424 result_type _M_v[__k];
1425 result_type _M_y;
1429 * Compares two %shuffle_order_engine random number generator objects
1430 * of the same type for inequality.
1432 * @param __lhs A %shuffle_order_engine random number generator object.
1433 * @param __rhs Another %shuffle_order_engine random number generator
1434 * object.
1436 * @returns true if the infinite sequences of generated values
1437 * would be different, false otherwise.
1439 template<typename _RandomNumberEngine, size_t __k>
1440 inline bool
1441 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1442 __k>& __lhs,
1443 const std::shuffle_order_engine<_RandomNumberEngine,
1444 __k>& __rhs)
1445 { return !(__lhs == __rhs); }
1449 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1451 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1452 minstd_rand0;
1455 * An alternative LCR (Lehmer Generator function).
1457 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1458 minstd_rand;
1461 * The classic Mersenne Twister.
1463 * Reference:
1464 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1465 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1466 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1468 typedef mersenne_twister_engine<
1469 uint_fast32_t,
1470 32, 624, 397, 31,
1471 0x9908b0dfUL, 11,
1472 0xffffffffUL, 7,
1473 0x9d2c5680UL, 15,
1474 0xefc60000UL, 18, 1812433253UL> mt19937;
1477 * An alternative Mersenne Twister.
1479 typedef mersenne_twister_engine<
1480 uint_fast64_t,
1481 64, 312, 156, 31,
1482 0xb5026f5aa96619e9ULL, 29,
1483 0x5555555555555555ULL, 17,
1484 0x71d67fffeda60000ULL, 37,
1485 0xfff7eee000000000ULL, 43,
1486 6364136223846793005ULL> mt19937_64;
1488 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1489 ranlux24_base;
1491 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1492 ranlux48_base;
1494 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1496 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1498 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1500 typedef minstd_rand0 default_random_engine;
1503 * A standard interface to a platform-specific non-deterministic
1504 * random number generator (if any are available).
1506 class random_device
1508 public:
1509 /** The type of the generated random value. */
1510 typedef unsigned int result_type;
1512 // constructors, destructors and member functions
1514 #ifdef _GLIBCXX_USE_RANDOM_TR1
1516 explicit
1517 random_device(const std::string& __token = "/dev/urandom")
1519 if ((__token != "/dev/urandom" && __token != "/dev/random")
1520 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1521 std::__throw_runtime_error(__N("random_device::"
1522 "random_device(const std::string&)"));
1525 ~random_device()
1526 { std::fclose(_M_file); }
1528 #else
1530 explicit
1531 random_device(const std::string& __token = "mt19937")
1532 : _M_mt(_M_strtoul(__token)) { }
1534 private:
1535 static unsigned long
1536 _M_strtoul(const std::string& __str)
1538 unsigned long __ret = 5489UL;
1539 if (__str != "mt19937")
1541 const char* __nptr = __str.c_str();
1542 char* __endptr;
1543 __ret = std::strtoul(__nptr, &__endptr, 0);
1544 if (*__nptr == '\0' || *__endptr != '\0')
1545 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1546 "(const std::string&)"));
1548 return __ret;
1551 public:
1553 #endif
1555 static constexpr result_type
1556 min()
1557 { return std::numeric_limits<result_type>::min(); }
1559 static constexpr result_type
1560 max()
1561 { return std::numeric_limits<result_type>::max(); }
1563 double
1564 entropy() const noexcept
1565 { return 0.0; }
1567 result_type
1568 operator()()
1570 #ifdef _GLIBCXX_USE_RANDOM_TR1
1571 result_type __ret;
1572 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1573 1, _M_file);
1574 return __ret;
1575 #else
1576 return _M_mt();
1577 #endif
1580 // No copy functions.
1581 random_device(const random_device&) = delete;
1582 void operator=(const random_device&) = delete;
1584 private:
1586 #ifdef _GLIBCXX_USE_RANDOM_TR1
1587 FILE* _M_file;
1588 #else
1589 mt19937 _M_mt;
1590 #endif
1593 /* @} */ // group random_generators
1596 * @addtogroup random_distributions Random Number Distributions
1597 * @ingroup random
1598 * @{
1602 * @addtogroup random_distributions_uniform Uniform Distributions
1603 * @ingroup random_distributions
1604 * @{
1608 * @brief Uniform discrete distribution for random numbers.
1609 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1610 * probability throughout the range.
1612 template<typename _IntType = int>
1613 class uniform_int_distribution
1615 static_assert(std::is_integral<_IntType>::value,
1616 "template argument not an integral type");
1618 public:
1619 /** The type of the range of the distribution. */
1620 typedef _IntType result_type;
1621 /** Parameter type. */
1622 struct param_type
1624 typedef uniform_int_distribution<_IntType> distribution_type;
1626 explicit
1627 param_type(_IntType __a = 0,
1628 _IntType __b = std::numeric_limits<_IntType>::max())
1629 : _M_a(__a), _M_b(__b)
1631 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1634 result_type
1635 a() const
1636 { return _M_a; }
1638 result_type
1639 b() const
1640 { return _M_b; }
1642 friend bool
1643 operator==(const param_type& __p1, const param_type& __p2)
1644 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1646 private:
1647 _IntType _M_a;
1648 _IntType _M_b;
1651 public:
1653 * @brief Constructs a uniform distribution object.
1655 explicit
1656 uniform_int_distribution(_IntType __a = 0,
1657 _IntType __b = std::numeric_limits<_IntType>::max())
1658 : _M_param(__a, __b)
1661 explicit
1662 uniform_int_distribution(const param_type& __p)
1663 : _M_param(__p)
1667 * @brief Resets the distribution state.
1669 * Does nothing for the uniform integer distribution.
1671 void
1672 reset() { }
1674 result_type
1675 a() const
1676 { return _M_param.a(); }
1678 result_type
1679 b() const
1680 { return _M_param.b(); }
1683 * @brief Returns the parameter set of the distribution.
1685 param_type
1686 param() const
1687 { return _M_param; }
1690 * @brief Sets the parameter set of the distribution.
1691 * @param __param The new parameter set of the distribution.
1693 void
1694 param(const param_type& __param)
1695 { _M_param = __param; }
1698 * @brief Returns the inclusive lower bound of the distribution range.
1700 result_type
1701 min() const
1702 { return this->a(); }
1705 * @brief Returns the inclusive upper bound of the distribution range.
1707 result_type
1708 max() const
1709 { return this->b(); }
1712 * @brief Generating functions.
1714 template<typename _UniformRandomNumberGenerator>
1715 result_type
1716 operator()(_UniformRandomNumberGenerator& __urng)
1717 { return this->operator()(__urng, this->param()); }
1719 template<typename _UniformRandomNumberGenerator>
1720 result_type
1721 operator()(_UniformRandomNumberGenerator& __urng,
1722 const param_type& __p);
1724 param_type _M_param;
1728 * @brief Return true if two uniform integer distributions have
1729 * the same parameters.
1731 template<typename _IntType>
1732 inline bool
1733 operator==(const std::uniform_int_distribution<_IntType>& __d1,
1734 const std::uniform_int_distribution<_IntType>& __d2)
1735 { return __d1.param() == __d2.param(); }
1738 * @brief Return true if two uniform integer distributions have
1739 * different parameters.
1741 template<typename _IntType>
1742 inline bool
1743 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1744 const std::uniform_int_distribution<_IntType>& __d2)
1745 { return !(__d1 == __d2); }
1748 * @brief Inserts a %uniform_int_distribution random number
1749 * distribution @p __x into the output stream @p os.
1751 * @param __os An output stream.
1752 * @param __x A %uniform_int_distribution random number distribution.
1754 * @returns The output stream with the state of @p __x inserted or in
1755 * an error state.
1757 template<typename _IntType, typename _CharT, typename _Traits>
1758 std::basic_ostream<_CharT, _Traits>&
1759 operator<<(std::basic_ostream<_CharT, _Traits>&,
1760 const std::uniform_int_distribution<_IntType>&);
1763 * @brief Extracts a %uniform_int_distribution random number distribution
1764 * @p __x from the input stream @p __is.
1766 * @param __is An input stream.
1767 * @param __x A %uniform_int_distribution random number generator engine.
1769 * @returns The input stream with @p __x extracted or in an error state.
1771 template<typename _IntType, typename _CharT, typename _Traits>
1772 std::basic_istream<_CharT, _Traits>&
1773 operator>>(std::basic_istream<_CharT, _Traits>&,
1774 std::uniform_int_distribution<_IntType>&);
1778 * @brief Uniform continuous distribution for random numbers.
1780 * A continuous random distribution on the range [min, max) with equal
1781 * probability throughout the range. The URNG should be real-valued and
1782 * deliver number in the range [0, 1).
1784 template<typename _RealType = double>
1785 class uniform_real_distribution
1787 static_assert(std::is_floating_point<_RealType>::value,
1788 "template argument not a floating point type");
1790 public:
1791 /** The type of the range of the distribution. */
1792 typedef _RealType result_type;
1793 /** Parameter type. */
1794 struct param_type
1796 typedef uniform_real_distribution<_RealType> distribution_type;
1798 explicit
1799 param_type(_RealType __a = _RealType(0),
1800 _RealType __b = _RealType(1))
1801 : _M_a(__a), _M_b(__b)
1803 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1806 result_type
1807 a() const
1808 { return _M_a; }
1810 result_type
1811 b() const
1812 { return _M_b; }
1814 friend bool
1815 operator==(const param_type& __p1, const param_type& __p2)
1816 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1818 private:
1819 _RealType _M_a;
1820 _RealType _M_b;
1823 public:
1825 * @brief Constructs a uniform_real_distribution object.
1827 * @param __a [IN] The lower bound of the distribution.
1828 * @param __b [IN] The upper bound of the distribution.
1830 explicit
1831 uniform_real_distribution(_RealType __a = _RealType(0),
1832 _RealType __b = _RealType(1))
1833 : _M_param(__a, __b)
1836 explicit
1837 uniform_real_distribution(const param_type& __p)
1838 : _M_param(__p)
1842 * @brief Resets the distribution state.
1844 * Does nothing for the uniform real distribution.
1846 void
1847 reset() { }
1849 result_type
1850 a() const
1851 { return _M_param.a(); }
1853 result_type
1854 b() const
1855 { return _M_param.b(); }
1858 * @brief Returns the parameter set of the distribution.
1860 param_type
1861 param() const
1862 { return _M_param; }
1865 * @brief Sets the parameter set of the distribution.
1866 * @param __param The new parameter set of the distribution.
1868 void
1869 param(const param_type& __param)
1870 { _M_param = __param; }
1873 * @brief Returns the inclusive lower bound of the distribution range.
1875 result_type
1876 min() const
1877 { return this->a(); }
1880 * @brief Returns the inclusive upper bound of the distribution range.
1882 result_type
1883 max() const
1884 { return this->b(); }
1887 * @brief Generating functions.
1889 template<typename _UniformRandomNumberGenerator>
1890 result_type
1891 operator()(_UniformRandomNumberGenerator& __urng)
1892 { return this->operator()(__urng, this->param()); }
1894 template<typename _UniformRandomNumberGenerator>
1895 result_type
1896 operator()(_UniformRandomNumberGenerator& __urng,
1897 const param_type& __p)
1899 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1900 __aurng(__urng);
1901 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1904 private:
1905 param_type _M_param;
1909 * @brief Return true if two uniform real distributions have
1910 * the same parameters.
1912 template<typename _IntType>
1913 inline bool
1914 operator==(const std::uniform_real_distribution<_IntType>& __d1,
1915 const std::uniform_real_distribution<_IntType>& __d2)
1916 { return __d1.param() == __d2.param(); }
1919 * @brief Return true if two uniform real distributions have
1920 * different parameters.
1922 template<typename _IntType>
1923 inline bool
1924 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1925 const std::uniform_real_distribution<_IntType>& __d2)
1926 { return !(__d1 == __d2); }
1929 * @brief Inserts a %uniform_real_distribution random number
1930 * distribution @p __x into the output stream @p __os.
1932 * @param __os An output stream.
1933 * @param __x A %uniform_real_distribution random number distribution.
1935 * @returns The output stream with the state of @p __x inserted or in
1936 * an error state.
1938 template<typename _RealType, typename _CharT, typename _Traits>
1939 std::basic_ostream<_CharT, _Traits>&
1940 operator<<(std::basic_ostream<_CharT, _Traits>&,
1941 const std::uniform_real_distribution<_RealType>&);
1944 * @brief Extracts a %uniform_real_distribution random number distribution
1945 * @p __x from the input stream @p __is.
1947 * @param __is An input stream.
1948 * @param __x A %uniform_real_distribution random number generator engine.
1950 * @returns The input stream with @p __x extracted or in an error state.
1952 template<typename _RealType, typename _CharT, typename _Traits>
1953 std::basic_istream<_CharT, _Traits>&
1954 operator>>(std::basic_istream<_CharT, _Traits>&,
1955 std::uniform_real_distribution<_RealType>&);
1957 /* @} */ // group random_distributions_uniform
1960 * @addtogroup random_distributions_normal Normal Distributions
1961 * @ingroup random_distributions
1962 * @{
1966 * @brief A normal continuous distribution for random numbers.
1968 * The formula for the normal probability density function is
1969 * @f[
1970 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1971 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1972 * @f]
1974 template<typename _RealType = double>
1975 class normal_distribution
1977 static_assert(std::is_floating_point<_RealType>::value,
1978 "template argument not a floating point type");
1980 public:
1981 /** The type of the range of the distribution. */
1982 typedef _RealType result_type;
1983 /** Parameter type. */
1984 struct param_type
1986 typedef normal_distribution<_RealType> distribution_type;
1988 explicit
1989 param_type(_RealType __mean = _RealType(0),
1990 _RealType __stddev = _RealType(1))
1991 : _M_mean(__mean), _M_stddev(__stddev)
1993 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1996 _RealType
1997 mean() const
1998 { return _M_mean; }
2000 _RealType
2001 stddev() const
2002 { return _M_stddev; }
2004 friend bool
2005 operator==(const param_type& __p1, const param_type& __p2)
2006 { return (__p1._M_mean == __p2._M_mean
2007 && __p1._M_stddev == __p2._M_stddev); }
2009 private:
2010 _RealType _M_mean;
2011 _RealType _M_stddev;
2014 public:
2016 * Constructs a normal distribution with parameters @f$mean@f$ and
2017 * standard deviation.
2019 explicit
2020 normal_distribution(result_type __mean = result_type(0),
2021 result_type __stddev = result_type(1))
2022 : _M_param(__mean, __stddev), _M_saved_available(false)
2025 explicit
2026 normal_distribution(const param_type& __p)
2027 : _M_param(__p), _M_saved_available(false)
2031 * @brief Resets the distribution state.
2033 void
2034 reset()
2035 { _M_saved_available = false; }
2038 * @brief Returns the mean of the distribution.
2040 _RealType
2041 mean() const
2042 { return _M_param.mean(); }
2045 * @brief Returns the standard deviation of the distribution.
2047 _RealType
2048 stddev() const
2049 { return _M_param.stddev(); }
2052 * @brief Returns the parameter set of the distribution.
2054 param_type
2055 param() const
2056 { return _M_param; }
2059 * @brief Sets the parameter set of the distribution.
2060 * @param __param The new parameter set of the distribution.
2062 void
2063 param(const param_type& __param)
2064 { _M_param = __param; }
2067 * @brief Returns the greatest lower bound value of the distribution.
2069 result_type
2070 min() const
2071 { return std::numeric_limits<result_type>::min(); }
2074 * @brief Returns the least upper bound value of the distribution.
2076 result_type
2077 max() const
2078 { return std::numeric_limits<result_type>::max(); }
2081 * @brief Generating functions.
2083 template<typename _UniformRandomNumberGenerator>
2084 result_type
2085 operator()(_UniformRandomNumberGenerator& __urng)
2086 { return this->operator()(__urng, this->param()); }
2088 template<typename _UniformRandomNumberGenerator>
2089 result_type
2090 operator()(_UniformRandomNumberGenerator& __urng,
2091 const param_type& __p);
2094 * @brief Return true if two normal distributions have
2095 * the same parameters and the sequences that would
2096 * be generated are equal.
2098 template<typename _RealType1>
2099 friend bool
2100 operator==(const std::normal_distribution<_RealType1>& __d1,
2101 const std::normal_distribution<_RealType1>& __d2);
2104 * @brief Inserts a %normal_distribution random number distribution
2105 * @p __x into the output stream @p __os.
2107 * @param __os An output stream.
2108 * @param __x A %normal_distribution random number distribution.
2110 * @returns The output stream with the state of @p __x inserted or in
2111 * an error state.
2113 template<typename _RealType1, typename _CharT, typename _Traits>
2114 friend std::basic_ostream<_CharT, _Traits>&
2115 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2116 const std::normal_distribution<_RealType1>& __x);
2119 * @brief Extracts a %normal_distribution random number distribution
2120 * @p __x from the input stream @p __is.
2122 * @param __is An input stream.
2123 * @param __x A %normal_distribution random number generator engine.
2125 * @returns The input stream with @p __x extracted or in an error
2126 * state.
2128 template<typename _RealType1, typename _CharT, typename _Traits>
2129 friend std::basic_istream<_CharT, _Traits>&
2130 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2131 std::normal_distribution<_RealType1>& __x);
2133 private:
2134 param_type _M_param;
2135 result_type _M_saved;
2136 bool _M_saved_available;
2140 * @brief Return true if two normal distributions are different.
2142 template<typename _RealType>
2143 inline bool
2144 operator!=(const std::normal_distribution<_RealType>& __d1,
2145 const std::normal_distribution<_RealType>& __d2)
2146 { return !(__d1 == __d2); }
2150 * @brief A lognormal_distribution random number distribution.
2152 * The formula for the normal probability mass function is
2153 * @f[
2154 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2155 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2156 * @f]
2158 template<typename _RealType = double>
2159 class lognormal_distribution
2161 static_assert(std::is_floating_point<_RealType>::value,
2162 "template argument not a floating point type");
2164 public:
2165 /** The type of the range of the distribution. */
2166 typedef _RealType result_type;
2167 /** Parameter type. */
2168 struct param_type
2170 typedef lognormal_distribution<_RealType> distribution_type;
2172 explicit
2173 param_type(_RealType __m = _RealType(0),
2174 _RealType __s = _RealType(1))
2175 : _M_m(__m), _M_s(__s)
2178 _RealType
2179 m() const
2180 { return _M_m; }
2182 _RealType
2183 s() const
2184 { return _M_s; }
2186 friend bool
2187 operator==(const param_type& __p1, const param_type& __p2)
2188 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2190 private:
2191 _RealType _M_m;
2192 _RealType _M_s;
2195 explicit
2196 lognormal_distribution(_RealType __m = _RealType(0),
2197 _RealType __s = _RealType(1))
2198 : _M_param(__m, __s), _M_nd()
2201 explicit
2202 lognormal_distribution(const param_type& __p)
2203 : _M_param(__p), _M_nd()
2207 * Resets the distribution state.
2209 void
2210 reset()
2211 { _M_nd.reset(); }
2216 _RealType
2217 m() const
2218 { return _M_param.m(); }
2220 _RealType
2221 s() const
2222 { return _M_param.s(); }
2225 * @brief Returns the parameter set of the distribution.
2227 param_type
2228 param() const
2229 { return _M_param; }
2232 * @brief Sets the parameter set of the distribution.
2233 * @param __param The new parameter set of the distribution.
2235 void
2236 param(const param_type& __param)
2237 { _M_param = __param; }
2240 * @brief Returns the greatest lower bound value of the distribution.
2242 result_type
2243 min() const
2244 { return result_type(0); }
2247 * @brief Returns the least upper bound value of the distribution.
2249 result_type
2250 max() const
2251 { return std::numeric_limits<result_type>::max(); }
2254 * @brief Generating functions.
2256 template<typename _UniformRandomNumberGenerator>
2257 result_type
2258 operator()(_UniformRandomNumberGenerator& __urng)
2259 { return this->operator()(__urng, this->param()); }
2261 template<typename _UniformRandomNumberGenerator>
2262 result_type
2263 operator()(_UniformRandomNumberGenerator& __urng,
2264 const param_type& __p)
2265 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2268 * @brief Return true if two lognormal distributions have
2269 * the same parameters and the sequences that would
2270 * be generated are equal.
2272 template<typename _RealType1>
2273 friend bool
2274 operator==(const std::lognormal_distribution<_RealType1>& __d1,
2275 const std::lognormal_distribution<_RealType1>& __d2)
2276 { return (__d1.param() == __d2.param()
2277 && __d1._M_nd == __d2._M_nd); }
2280 * @brief Inserts a %lognormal_distribution random number distribution
2281 * @p __x into the output stream @p __os.
2283 * @param __os An output stream.
2284 * @param __x A %lognormal_distribution random number distribution.
2286 * @returns The output stream with the state of @p __x inserted or in
2287 * an error state.
2289 template<typename _RealType1, typename _CharT, typename _Traits>
2290 friend std::basic_ostream<_CharT, _Traits>&
2291 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2292 const std::lognormal_distribution<_RealType1>& __x);
2295 * @brief Extracts a %lognormal_distribution random number distribution
2296 * @p __x from the input stream @p __is.
2298 * @param __is An input stream.
2299 * @param __x A %lognormal_distribution random number
2300 * generator engine.
2302 * @returns The input stream with @p __x extracted or in an error state.
2304 template<typename _RealType1, typename _CharT, typename _Traits>
2305 friend std::basic_istream<_CharT, _Traits>&
2306 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2307 std::lognormal_distribution<_RealType1>& __x);
2309 private:
2310 param_type _M_param;
2312 std::normal_distribution<result_type> _M_nd;
2316 * @brief Return true if two lognormal distributions are different.
2318 template<typename _RealType>
2319 inline bool
2320 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2321 const std::lognormal_distribution<_RealType>& __d2)
2322 { return !(__d1 == __d2); }
2326 * @brief A gamma continuous distribution for random numbers.
2328 * The formula for the gamma probability density function is:
2329 * @f[
2330 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2331 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2332 * @f]
2334 template<typename _RealType = double>
2335 class gamma_distribution
2337 static_assert(std::is_floating_point<_RealType>::value,
2338 "template argument not a floating point type");
2340 public:
2341 /** The type of the range of the distribution. */
2342 typedef _RealType result_type;
2343 /** Parameter type. */
2344 struct param_type
2346 typedef gamma_distribution<_RealType> distribution_type;
2347 friend class gamma_distribution<_RealType>;
2349 explicit
2350 param_type(_RealType __alpha_val = _RealType(1),
2351 _RealType __beta_val = _RealType(1))
2352 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2354 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2355 _M_initialize();
2358 _RealType
2359 alpha() const
2360 { return _M_alpha; }
2362 _RealType
2363 beta() const
2364 { return _M_beta; }
2366 friend bool
2367 operator==(const param_type& __p1, const param_type& __p2)
2368 { return (__p1._M_alpha == __p2._M_alpha
2369 && __p1._M_beta == __p2._M_beta); }
2371 private:
2372 void
2373 _M_initialize();
2375 _RealType _M_alpha;
2376 _RealType _M_beta;
2378 _RealType _M_malpha, _M_a2;
2381 public:
2383 * @brief Constructs a gamma distribution with parameters
2384 * @f$\alpha@f$ and @f$\beta@f$.
2386 explicit
2387 gamma_distribution(_RealType __alpha_val = _RealType(1),
2388 _RealType __beta_val = _RealType(1))
2389 : _M_param(__alpha_val, __beta_val), _M_nd()
2392 explicit
2393 gamma_distribution(const param_type& __p)
2394 : _M_param(__p), _M_nd()
2398 * @brief Resets the distribution state.
2400 void
2401 reset()
2402 { _M_nd.reset(); }
2405 * @brief Returns the @f$\alpha@f$ of the distribution.
2407 _RealType
2408 alpha() const
2409 { return _M_param.alpha(); }
2412 * @brief Returns the @f$\beta@f$ of the distribution.
2414 _RealType
2415 beta() const
2416 { return _M_param.beta(); }
2419 * @brief Returns the parameter set of the distribution.
2421 param_type
2422 param() const
2423 { return _M_param; }
2426 * @brief Sets the parameter set of the distribution.
2427 * @param __param The new parameter set of the distribution.
2429 void
2430 param(const param_type& __param)
2431 { _M_param = __param; }
2434 * @brief Returns the greatest lower bound value of the distribution.
2436 result_type
2437 min() const
2438 { return result_type(0); }
2441 * @brief Returns the least upper bound value of the distribution.
2443 result_type
2444 max() const
2445 { return std::numeric_limits<result_type>::max(); }
2448 * @brief Generating functions.
2450 template<typename _UniformRandomNumberGenerator>
2451 result_type
2452 operator()(_UniformRandomNumberGenerator& __urng)
2453 { return this->operator()(__urng, this->param()); }
2455 template<typename _UniformRandomNumberGenerator>
2456 result_type
2457 operator()(_UniformRandomNumberGenerator& __urng,
2458 const param_type& __p);
2461 * @brief Return true if two gamma distributions have the same
2462 * parameters and the sequences that would be generated
2463 * are equal.
2465 template<typename _RealType1>
2466 friend bool
2467 operator==(const std::gamma_distribution<_RealType1>& __d1,
2468 const std::gamma_distribution<_RealType1>& __d2)
2469 { return (__d1.param() == __d2.param()
2470 && __d1._M_nd == __d2._M_nd); }
2473 * @brief Inserts a %gamma_distribution random number distribution
2474 * @p __x into the output stream @p __os.
2476 * @param __os An output stream.
2477 * @param __x A %gamma_distribution random number distribution.
2479 * @returns The output stream with the state of @p __x inserted or in
2480 * an error state.
2482 template<typename _RealType1, typename _CharT, typename _Traits>
2483 friend std::basic_ostream<_CharT, _Traits>&
2484 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2485 const std::gamma_distribution<_RealType1>& __x);
2488 * @brief Extracts a %gamma_distribution random number distribution
2489 * @p __x from the input stream @p __is.
2491 * @param __is An input stream.
2492 * @param __x A %gamma_distribution random number generator engine.
2494 * @returns The input stream with @p __x extracted or in an error state.
2496 template<typename _RealType1, typename _CharT, typename _Traits>
2497 friend std::basic_istream<_CharT, _Traits>&
2498 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2499 std::gamma_distribution<_RealType1>& __x);
2501 private:
2502 param_type _M_param;
2504 std::normal_distribution<result_type> _M_nd;
2508 * @brief Return true if two gamma distributions are different.
2510 template<typename _RealType>
2511 inline bool
2512 operator!=(const std::gamma_distribution<_RealType>& __d1,
2513 const std::gamma_distribution<_RealType>& __d2)
2514 { return !(__d1 == __d2); }
2518 * @brief A chi_squared_distribution random number distribution.
2520 * The formula for the normal probability mass function is
2521 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2523 template<typename _RealType = double>
2524 class chi_squared_distribution
2526 static_assert(std::is_floating_point<_RealType>::value,
2527 "template argument not a floating point type");
2529 public:
2530 /** The type of the range of the distribution. */
2531 typedef _RealType result_type;
2532 /** Parameter type. */
2533 struct param_type
2535 typedef chi_squared_distribution<_RealType> distribution_type;
2537 explicit
2538 param_type(_RealType __n = _RealType(1))
2539 : _M_n(__n)
2542 _RealType
2543 n() const
2544 { return _M_n; }
2546 friend bool
2547 operator==(const param_type& __p1, const param_type& __p2)
2548 { return __p1._M_n == __p2._M_n; }
2550 private:
2551 _RealType _M_n;
2554 explicit
2555 chi_squared_distribution(_RealType __n = _RealType(1))
2556 : _M_param(__n), _M_gd(__n / 2)
2559 explicit
2560 chi_squared_distribution(const param_type& __p)
2561 : _M_param(__p), _M_gd(__p.n() / 2)
2565 * @brief Resets the distribution state.
2567 void
2568 reset()
2569 { _M_gd.reset(); }
2574 _RealType
2575 n() const
2576 { return _M_param.n(); }
2579 * @brief Returns the parameter set of the distribution.
2581 param_type
2582 param() const
2583 { return _M_param; }
2586 * @brief Sets the parameter set of the distribution.
2587 * @param __param The new parameter set of the distribution.
2589 void
2590 param(const param_type& __param)
2591 { _M_param = __param; }
2594 * @brief Returns the greatest lower bound value of the distribution.
2596 result_type
2597 min() const
2598 { return result_type(0); }
2601 * @brief Returns the least upper bound value of the distribution.
2603 result_type
2604 max() const
2605 { return std::numeric_limits<result_type>::max(); }
2608 * @brief Generating functions.
2610 template<typename _UniformRandomNumberGenerator>
2611 result_type
2612 operator()(_UniformRandomNumberGenerator& __urng)
2613 { return 2 * _M_gd(__urng); }
2615 template<typename _UniformRandomNumberGenerator>
2616 result_type
2617 operator()(_UniformRandomNumberGenerator& __urng,
2618 const param_type& __p)
2620 typedef typename std::gamma_distribution<result_type>::param_type
2621 param_type;
2622 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2626 * @brief Return true if two Chi-squared distributions have
2627 * the same parameters and the sequences that would be
2628 * generated are equal.
2630 template<typename _RealType1>
2631 friend bool
2632 operator==(const std::chi_squared_distribution<_RealType1>& __d1,
2633 const std::chi_squared_distribution<_RealType1>& __d2)
2634 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2637 * @brief Inserts a %chi_squared_distribution random number distribution
2638 * @p __x into the output stream @p __os.
2640 * @param __os An output stream.
2641 * @param __x A %chi_squared_distribution random number distribution.
2643 * @returns The output stream with the state of @p __x inserted or in
2644 * an error state.
2646 template<typename _RealType1, typename _CharT, typename _Traits>
2647 friend std::basic_ostream<_CharT, _Traits>&
2648 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2649 const std::chi_squared_distribution<_RealType1>& __x);
2652 * @brief Extracts a %chi_squared_distribution random number distribution
2653 * @p __x from the input stream @p __is.
2655 * @param __is An input stream.
2656 * @param __x A %chi_squared_distribution random number
2657 * generator engine.
2659 * @returns The input stream with @p __x extracted or in an error state.
2661 template<typename _RealType1, typename _CharT, typename _Traits>
2662 friend std::basic_istream<_CharT, _Traits>&
2663 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2664 std::chi_squared_distribution<_RealType1>& __x);
2666 private:
2667 param_type _M_param;
2669 std::gamma_distribution<result_type> _M_gd;
2673 * @brief Return true if two Chi-squared distributions are different.
2675 template<typename _RealType>
2676 inline bool
2677 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2678 const std::chi_squared_distribution<_RealType>& __d2)
2679 { return !(__d1 == __d2); }
2683 * @brief A cauchy_distribution random number distribution.
2685 * The formula for the normal probability mass function is
2686 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2688 template<typename _RealType = double>
2689 class cauchy_distribution
2691 static_assert(std::is_floating_point<_RealType>::value,
2692 "template argument not a floating point type");
2694 public:
2695 /** The type of the range of the distribution. */
2696 typedef _RealType result_type;
2697 /** Parameter type. */
2698 struct param_type
2700 typedef cauchy_distribution<_RealType> distribution_type;
2702 explicit
2703 param_type(_RealType __a = _RealType(0),
2704 _RealType __b = _RealType(1))
2705 : _M_a(__a), _M_b(__b)
2708 _RealType
2709 a() const
2710 { return _M_a; }
2712 _RealType
2713 b() const
2714 { return _M_b; }
2716 friend bool
2717 operator==(const param_type& __p1, const param_type& __p2)
2718 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2720 private:
2721 _RealType _M_a;
2722 _RealType _M_b;
2725 explicit
2726 cauchy_distribution(_RealType __a = _RealType(0),
2727 _RealType __b = _RealType(1))
2728 : _M_param(__a, __b)
2731 explicit
2732 cauchy_distribution(const param_type& __p)
2733 : _M_param(__p)
2737 * @brief Resets the distribution state.
2739 void
2740 reset()
2746 _RealType
2747 a() const
2748 { return _M_param.a(); }
2750 _RealType
2751 b() const
2752 { return _M_param.b(); }
2755 * @brief Returns the parameter set of the distribution.
2757 param_type
2758 param() const
2759 { return _M_param; }
2762 * @brief Sets the parameter set of the distribution.
2763 * @param __param The new parameter set of the distribution.
2765 void
2766 param(const param_type& __param)
2767 { _M_param = __param; }
2770 * @brief Returns the greatest lower bound value of the distribution.
2772 result_type
2773 min() const
2774 { return std::numeric_limits<result_type>::min(); }
2777 * @brief Returns the least upper bound value of the distribution.
2779 result_type
2780 max() const
2781 { return std::numeric_limits<result_type>::max(); }
2784 * @brief Generating functions.
2786 template<typename _UniformRandomNumberGenerator>
2787 result_type
2788 operator()(_UniformRandomNumberGenerator& __urng)
2789 { return this->operator()(__urng, this->param()); }
2791 template<typename _UniformRandomNumberGenerator>
2792 result_type
2793 operator()(_UniformRandomNumberGenerator& __urng,
2794 const param_type& __p);
2796 private:
2797 param_type _M_param;
2801 * @brief Return true if two Cauchy distributions have
2802 * the same parameters.
2804 template<typename _RealType>
2805 inline bool
2806 operator==(const std::cauchy_distribution<_RealType>& __d1,
2807 const std::cauchy_distribution<_RealType>& __d2)
2808 { return __d1.param() == __d2.param(); }
2811 * @brief Return true if two Cauchy distributions have
2812 * different parameters.
2814 template<typename _RealType>
2815 inline bool
2816 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2817 const std::cauchy_distribution<_RealType>& __d2)
2818 { return !(__d1 == __d2); }
2821 * @brief Inserts a %cauchy_distribution random number distribution
2822 * @p __x into the output stream @p __os.
2824 * @param __os An output stream.
2825 * @param __x A %cauchy_distribution random number distribution.
2827 * @returns The output stream with the state of @p __x inserted or in
2828 * an error state.
2830 template<typename _RealType, typename _CharT, typename _Traits>
2831 std::basic_ostream<_CharT, _Traits>&
2832 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2833 const std::cauchy_distribution<_RealType>& __x);
2836 * @brief Extracts a %cauchy_distribution random number distribution
2837 * @p __x from the input stream @p __is.
2839 * @param __is An input stream.
2840 * @param __x A %cauchy_distribution random number
2841 * generator engine.
2843 * @returns The input stream with @p __x extracted or in an error state.
2845 template<typename _RealType, typename _CharT, typename _Traits>
2846 std::basic_istream<_CharT, _Traits>&
2847 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2848 std::cauchy_distribution<_RealType>& __x);
2852 * @brief A fisher_f_distribution random number distribution.
2854 * The formula for the normal probability mass function is
2855 * @f[
2856 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2857 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2858 * (1 + \frac{mx}{n})^{-(m+n)/2}
2859 * @f]
2861 template<typename _RealType = double>
2862 class fisher_f_distribution
2864 static_assert(std::is_floating_point<_RealType>::value,
2865 "template argument not a floating point type");
2867 public:
2868 /** The type of the range of the distribution. */
2869 typedef _RealType result_type;
2870 /** Parameter type. */
2871 struct param_type
2873 typedef fisher_f_distribution<_RealType> distribution_type;
2875 explicit
2876 param_type(_RealType __m = _RealType(1),
2877 _RealType __n = _RealType(1))
2878 : _M_m(__m), _M_n(__n)
2881 _RealType
2882 m() const
2883 { return _M_m; }
2885 _RealType
2886 n() const
2887 { return _M_n; }
2889 friend bool
2890 operator==(const param_type& __p1, const param_type& __p2)
2891 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2893 private:
2894 _RealType _M_m;
2895 _RealType _M_n;
2898 explicit
2899 fisher_f_distribution(_RealType __m = _RealType(1),
2900 _RealType __n = _RealType(1))
2901 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2904 explicit
2905 fisher_f_distribution(const param_type& __p)
2906 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2910 * @brief Resets the distribution state.
2912 void
2913 reset()
2915 _M_gd_x.reset();
2916 _M_gd_y.reset();
2922 _RealType
2923 m() const
2924 { return _M_param.m(); }
2926 _RealType
2927 n() const
2928 { return _M_param.n(); }
2931 * @brief Returns the parameter set of the distribution.
2933 param_type
2934 param() const
2935 { return _M_param; }
2938 * @brief Sets the parameter set of the distribution.
2939 * @param __param The new parameter set of the distribution.
2941 void
2942 param(const param_type& __param)
2943 { _M_param = __param; }
2946 * @brief Returns the greatest lower bound value of the distribution.
2948 result_type
2949 min() const
2950 { return result_type(0); }
2953 * @brief Returns the least upper bound value of the distribution.
2955 result_type
2956 max() const
2957 { return std::numeric_limits<result_type>::max(); }
2960 * @brief Generating functions.
2962 template<typename _UniformRandomNumberGenerator>
2963 result_type
2964 operator()(_UniformRandomNumberGenerator& __urng)
2965 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2967 template<typename _UniformRandomNumberGenerator>
2968 result_type
2969 operator()(_UniformRandomNumberGenerator& __urng,
2970 const param_type& __p)
2972 typedef typename std::gamma_distribution<result_type>::param_type
2973 param_type;
2974 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2975 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2979 * @brief Return true if two Fisher f distributions have
2980 * the same parameters and the sequences that would
2981 * be generated are equal.
2983 template<typename _RealType1>
2984 friend bool
2985 operator==(const std::fisher_f_distribution<_RealType1>& __d1,
2986 const std::fisher_f_distribution<_RealType1>& __d2)
2987 { return (__d1.param() == __d2.param()
2988 && __d1._M_gd_x == __d2._M_gd_x
2989 && __d1._M_gd_y == __d2._M_gd_y); }
2992 * @brief Inserts a %fisher_f_distribution random number distribution
2993 * @p __x into the output stream @p __os.
2995 * @param __os An output stream.
2996 * @param __x A %fisher_f_distribution random number distribution.
2998 * @returns The output stream with the state of @p __x inserted or in
2999 * an error state.
3001 template<typename _RealType1, typename _CharT, typename _Traits>
3002 friend std::basic_ostream<_CharT, _Traits>&
3003 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3004 const std::fisher_f_distribution<_RealType1>& __x);
3007 * @brief Extracts a %fisher_f_distribution random number distribution
3008 * @p __x from the input stream @p __is.
3010 * @param __is An input stream.
3011 * @param __x A %fisher_f_distribution random number
3012 * generator engine.
3014 * @returns The input stream with @p __x extracted or in an error state.
3016 template<typename _RealType1, typename _CharT, typename _Traits>
3017 friend std::basic_istream<_CharT, _Traits>&
3018 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3019 std::fisher_f_distribution<_RealType1>& __x);
3021 private:
3022 param_type _M_param;
3024 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3028 * @brief Return true if two Fisher f distributions are diferent.
3030 template<typename _RealType>
3031 inline bool
3032 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3033 const std::fisher_f_distribution<_RealType>& __d2)
3034 { return !(__d1 == __d2); }
3037 * @brief A student_t_distribution random number distribution.
3039 * The formula for the normal probability mass function is:
3040 * @f[
3041 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3042 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3043 * @f]
3045 template<typename _RealType = double>
3046 class student_t_distribution
3048 static_assert(std::is_floating_point<_RealType>::value,
3049 "template argument not a floating point type");
3051 public:
3052 /** The type of the range of the distribution. */
3053 typedef _RealType result_type;
3054 /** Parameter type. */
3055 struct param_type
3057 typedef student_t_distribution<_RealType> distribution_type;
3059 explicit
3060 param_type(_RealType __n = _RealType(1))
3061 : _M_n(__n)
3064 _RealType
3065 n() const
3066 { return _M_n; }
3068 friend bool
3069 operator==(const param_type& __p1, const param_type& __p2)
3070 { return __p1._M_n == __p2._M_n; }
3072 private:
3073 _RealType _M_n;
3076 explicit
3077 student_t_distribution(_RealType __n = _RealType(1))
3078 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3081 explicit
3082 student_t_distribution(const param_type& __p)
3083 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3087 * @brief Resets the distribution state.
3089 void
3090 reset()
3092 _M_nd.reset();
3093 _M_gd.reset();
3099 _RealType
3100 n() const
3101 { return _M_param.n(); }
3104 * @brief Returns the parameter set of the distribution.
3106 param_type
3107 param() const
3108 { return _M_param; }
3111 * @brief Sets the parameter set of the distribution.
3112 * @param __param The new parameter set of the distribution.
3114 void
3115 param(const param_type& __param)
3116 { _M_param = __param; }
3119 * @brief Returns the greatest lower bound value of the distribution.
3121 result_type
3122 min() const
3123 { return std::numeric_limits<result_type>::min(); }
3126 * @brief Returns the least upper bound value of the distribution.
3128 result_type
3129 max() const
3130 { return std::numeric_limits<result_type>::max(); }
3133 * @brief Generating functions.
3135 template<typename _UniformRandomNumberGenerator>
3136 result_type
3137 operator()(_UniformRandomNumberGenerator& __urng)
3138 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3140 template<typename _UniformRandomNumberGenerator>
3141 result_type
3142 operator()(_UniformRandomNumberGenerator& __urng,
3143 const param_type& __p)
3145 typedef typename std::gamma_distribution<result_type>::param_type
3146 param_type;
3148 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3149 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3153 * @brief Return true if two Student t distributions have
3154 * the same parameters and the sequences that would
3155 * be generated are equal.
3157 template<typename _RealType1>
3158 friend bool
3159 operator==(const std::student_t_distribution<_RealType1>& __d1,
3160 const std::student_t_distribution<_RealType1>& __d2)
3161 { return (__d1.param() == __d2.param()
3162 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3165 * @brief Inserts a %student_t_distribution random number distribution
3166 * @p __x into the output stream @p __os.
3168 * @param __os An output stream.
3169 * @param __x A %student_t_distribution random number distribution.
3171 * @returns The output stream with the state of @p __x inserted or in
3172 * an error state.
3174 template<typename _RealType1, typename _CharT, typename _Traits>
3175 friend std::basic_ostream<_CharT, _Traits>&
3176 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3177 const std::student_t_distribution<_RealType1>& __x);
3180 * @brief Extracts a %student_t_distribution random number distribution
3181 * @p __x from the input stream @p __is.
3183 * @param __is An input stream.
3184 * @param __x A %student_t_distribution random number
3185 * generator engine.
3187 * @returns The input stream with @p __x extracted or in an error state.
3189 template<typename _RealType1, typename _CharT, typename _Traits>
3190 friend std::basic_istream<_CharT, _Traits>&
3191 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3192 std::student_t_distribution<_RealType1>& __x);
3194 private:
3195 param_type _M_param;
3197 std::normal_distribution<result_type> _M_nd;
3198 std::gamma_distribution<result_type> _M_gd;
3202 * @brief Return true if two Student t distributions are different.
3204 template<typename _RealType>
3205 inline bool
3206 operator!=(const std::student_t_distribution<_RealType>& __d1,
3207 const std::student_t_distribution<_RealType>& __d2)
3208 { return !(__d1 == __d2); }
3211 /* @} */ // group random_distributions_normal
3214 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3215 * @ingroup random_distributions
3216 * @{
3220 * @brief A Bernoulli random number distribution.
3222 * Generates a sequence of true and false values with likelihood @f$p@f$
3223 * that true will come up and @f$(1 - p)@f$ that false will appear.
3225 class bernoulli_distribution
3227 public:
3228 /** The type of the range of the distribution. */
3229 typedef bool result_type;
3230 /** Parameter type. */
3231 struct param_type
3233 typedef bernoulli_distribution distribution_type;
3235 explicit
3236 param_type(double __p = 0.5)
3237 : _M_p(__p)
3239 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3242 double
3243 p() const
3244 { return _M_p; }
3246 friend bool
3247 operator==(const param_type& __p1, const param_type& __p2)
3248 { return __p1._M_p == __p2._M_p; }
3250 private:
3251 double _M_p;
3254 public:
3256 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3258 * @param __p [IN] The likelihood of a true result being returned.
3259 * Must be in the interval @f$[0, 1]@f$.
3261 explicit
3262 bernoulli_distribution(double __p = 0.5)
3263 : _M_param(__p)
3266 explicit
3267 bernoulli_distribution(const param_type& __p)
3268 : _M_param(__p)
3272 * @brief Resets the distribution state.
3274 * Does nothing for a Bernoulli distribution.
3276 void
3277 reset() { }
3280 * @brief Returns the @p p parameter of the distribution.
3282 double
3283 p() const
3284 { return _M_param.p(); }
3287 * @brief Returns the parameter set of the distribution.
3289 param_type
3290 param() const
3291 { return _M_param; }
3294 * @brief Sets the parameter set of the distribution.
3295 * @param __param The new parameter set of the distribution.
3297 void
3298 param(const param_type& __param)
3299 { _M_param = __param; }
3302 * @brief Returns the greatest lower bound value of the distribution.
3304 result_type
3305 min() const
3306 { return std::numeric_limits<result_type>::min(); }
3309 * @brief Returns the least upper bound value of the distribution.
3311 result_type
3312 max() const
3313 { return std::numeric_limits<result_type>::max(); }
3316 * @brief Generating functions.
3318 template<typename _UniformRandomNumberGenerator>
3319 result_type
3320 operator()(_UniformRandomNumberGenerator& __urng)
3321 { return this->operator()(__urng, this->param()); }
3323 template<typename _UniformRandomNumberGenerator>
3324 result_type
3325 operator()(_UniformRandomNumberGenerator& __urng,
3326 const param_type& __p)
3328 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3329 __aurng(__urng);
3330 if ((__aurng() - __aurng.min())
3331 < __p.p() * (__aurng.max() - __aurng.min()))
3332 return true;
3333 return false;
3336 private:
3337 param_type _M_param;
3341 * @brief Return true if two Bernoulli distributions have
3342 * the same parameters.
3344 inline bool
3345 operator==(const std::bernoulli_distribution& __d1,
3346 const std::bernoulli_distribution& __d2)
3347 { return __d1.param() == __d2.param(); }
3350 * @brief Return true if two Bernoulli distributions have
3351 * different parameters.
3353 inline bool
3354 operator!=(const std::bernoulli_distribution& __d1,
3355 const std::bernoulli_distribution& __d2)
3356 { return !(__d1 == __d2); }
3359 * @brief Inserts a %bernoulli_distribution random number distribution
3360 * @p __x into the output stream @p __os.
3362 * @param __os An output stream.
3363 * @param __x A %bernoulli_distribution random number distribution.
3365 * @returns The output stream with the state of @p __x inserted or in
3366 * an error state.
3368 template<typename _CharT, typename _Traits>
3369 std::basic_ostream<_CharT, _Traits>&
3370 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3371 const std::bernoulli_distribution& __x);
3374 * @brief Extracts a %bernoulli_distribution random number distribution
3375 * @p __x from the input stream @p __is.
3377 * @param __is An input stream.
3378 * @param __x A %bernoulli_distribution random number generator engine.
3380 * @returns The input stream with @p __x extracted or in an error state.
3382 template<typename _CharT, typename _Traits>
3383 std::basic_istream<_CharT, _Traits>&
3384 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3385 std::bernoulli_distribution& __x)
3387 double __p;
3388 __is >> __p;
3389 __x.param(bernoulli_distribution::param_type(__p));
3390 return __is;
3395 * @brief A discrete binomial random number distribution.
3397 * The formula for the binomial probability density function is
3398 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3399 * and @f$p@f$ are the parameters of the distribution.
3401 template<typename _IntType = int>
3402 class binomial_distribution
3404 static_assert(std::is_integral<_IntType>::value,
3405 "template argument not an integral type");
3407 public:
3408 /** The type of the range of the distribution. */
3409 typedef _IntType result_type;
3410 /** Parameter type. */
3411 struct param_type
3413 typedef binomial_distribution<_IntType> distribution_type;
3414 friend class binomial_distribution<_IntType>;
3416 explicit
3417 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3418 : _M_t(__t), _M_p(__p)
3420 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3421 && (_M_p >= 0.0)
3422 && (_M_p <= 1.0));
3423 _M_initialize();
3426 _IntType
3427 t() const
3428 { return _M_t; }
3430 double
3431 p() const
3432 { return _M_p; }
3434 friend bool
3435 operator==(const param_type& __p1, const param_type& __p2)
3436 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3438 private:
3439 void
3440 _M_initialize();
3442 _IntType _M_t;
3443 double _M_p;
3445 double _M_q;
3446 #if _GLIBCXX_USE_C99_MATH_TR1
3447 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3448 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3449 #endif
3450 bool _M_easy;
3453 // constructors and member function
3454 explicit
3455 binomial_distribution(_IntType __t = _IntType(1),
3456 double __p = 0.5)
3457 : _M_param(__t, __p), _M_nd()
3460 explicit
3461 binomial_distribution(const param_type& __p)
3462 : _M_param(__p), _M_nd()
3466 * @brief Resets the distribution state.
3468 void
3469 reset()
3470 { _M_nd.reset(); }
3473 * @brief Returns the distribution @p t parameter.
3475 _IntType
3476 t() const
3477 { return _M_param.t(); }
3480 * @brief Returns the distribution @p p parameter.
3482 double
3483 p() const
3484 { return _M_param.p(); }
3487 * @brief Returns the parameter set of the distribution.
3489 param_type
3490 param() const
3491 { return _M_param; }
3494 * @brief Sets the parameter set of the distribution.
3495 * @param __param The new parameter set of the distribution.
3497 void
3498 param(const param_type& __param)
3499 { _M_param = __param; }
3502 * @brief Returns the greatest lower bound value of the distribution.
3504 result_type
3505 min() const
3506 { return 0; }
3509 * @brief Returns the least upper bound value of the distribution.
3511 result_type
3512 max() const
3513 { return _M_param.t(); }
3516 * @brief Generating functions.
3518 template<typename _UniformRandomNumberGenerator>
3519 result_type
3520 operator()(_UniformRandomNumberGenerator& __urng)
3521 { return this->operator()(__urng, this->param()); }
3523 template<typename _UniformRandomNumberGenerator>
3524 result_type
3525 operator()(_UniformRandomNumberGenerator& __urng,
3526 const param_type& __p);
3529 * @brief Return true if two binomial distributions have
3530 * the same parameters and the sequences that would
3531 * be generated are equal.
3533 template<typename _IntType1>
3534 friend bool
3535 operator==(const std::binomial_distribution<_IntType1>& __d1,
3536 const std::binomial_distribution<_IntType1>& __d2)
3537 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3538 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3539 #else
3540 { return __d1.param() == __d2.param(); }
3541 #endif
3544 * @brief Inserts a %binomial_distribution random number distribution
3545 * @p __x into the output stream @p __os.
3547 * @param __os An output stream.
3548 * @param __x A %binomial_distribution random number distribution.
3550 * @returns The output stream with the state of @p __x inserted or in
3551 * an error state.
3553 template<typename _IntType1,
3554 typename _CharT, typename _Traits>
3555 friend std::basic_ostream<_CharT, _Traits>&
3556 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3557 const std::binomial_distribution<_IntType1>& __x);
3560 * @brief Extracts a %binomial_distribution random number distribution
3561 * @p __x from the input stream @p __is.
3563 * @param __is An input stream.
3564 * @param __x A %binomial_distribution random number generator engine.
3566 * @returns The input stream with @p __x extracted or in an error
3567 * state.
3569 template<typename _IntType1,
3570 typename _CharT, typename _Traits>
3571 friend std::basic_istream<_CharT, _Traits>&
3572 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3573 std::binomial_distribution<_IntType1>& __x);
3575 private:
3576 template<typename _UniformRandomNumberGenerator>
3577 result_type
3578 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3580 param_type _M_param;
3582 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3583 std::normal_distribution<double> _M_nd;
3587 * @brief Return true if two binomial distributions are different.
3589 template<typename _IntType>
3590 inline bool
3591 operator!=(const std::binomial_distribution<_IntType>& __d1,
3592 const std::binomial_distribution<_IntType>& __d2)
3593 { return !(__d1 == __d2); }
3597 * @brief A discrete geometric random number distribution.
3599 * The formula for the geometric probability density function is
3600 * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3601 * distribution.
3603 template<typename _IntType = int>
3604 class geometric_distribution
3606 static_assert(std::is_integral<_IntType>::value,
3607 "template argument not an integral type");
3609 public:
3610 /** The type of the range of the distribution. */
3611 typedef _IntType result_type;
3612 /** Parameter type. */
3613 struct param_type
3615 typedef geometric_distribution<_IntType> distribution_type;
3616 friend class geometric_distribution<_IntType>;
3618 explicit
3619 param_type(double __p = 0.5)
3620 : _M_p(__p)
3622 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
3623 _M_initialize();
3626 double
3627 p() const
3628 { return _M_p; }
3630 friend bool
3631 operator==(const param_type& __p1, const param_type& __p2)
3632 { return __p1._M_p == __p2._M_p; }
3634 private:
3635 void
3636 _M_initialize()
3637 { _M_log_1_p = std::log(1.0 - _M_p); }
3639 double _M_p;
3641 double _M_log_1_p;
3644 // constructors and member function
3645 explicit
3646 geometric_distribution(double __p = 0.5)
3647 : _M_param(__p)
3650 explicit
3651 geometric_distribution(const param_type& __p)
3652 : _M_param(__p)
3656 * @brief Resets the distribution state.
3658 * Does nothing for the geometric distribution.
3660 void
3661 reset() { }
3664 * @brief Returns the distribution parameter @p p.
3666 double
3667 p() const
3668 { return _M_param.p(); }
3671 * @brief Returns the parameter set of the distribution.
3673 param_type
3674 param() const
3675 { return _M_param; }
3678 * @brief Sets the parameter set of the distribution.
3679 * @param __param The new parameter set of the distribution.
3681 void
3682 param(const param_type& __param)
3683 { _M_param = __param; }
3686 * @brief Returns the greatest lower bound value of the distribution.
3688 result_type
3689 min() const
3690 { return 0; }
3693 * @brief Returns the least upper bound value of the distribution.
3695 result_type
3696 max() const
3697 { return std::numeric_limits<result_type>::max(); }
3700 * @brief Generating functions.
3702 template<typename _UniformRandomNumberGenerator>
3703 result_type
3704 operator()(_UniformRandomNumberGenerator& __urng)
3705 { return this->operator()(__urng, this->param()); }
3707 template<typename _UniformRandomNumberGenerator>
3708 result_type
3709 operator()(_UniformRandomNumberGenerator& __urng,
3710 const param_type& __p);
3712 private:
3713 param_type _M_param;
3717 * @brief Return true if two geometric distributions have
3718 * the same parameters.
3720 template<typename _IntType>
3721 inline bool
3722 operator==(const std::geometric_distribution<_IntType>& __d1,
3723 const std::geometric_distribution<_IntType>& __d2)
3724 { return __d1.param() == __d2.param(); }
3727 * @brief Return true if two geometric distributions have
3728 * different parameters.
3730 template<typename _IntType>
3731 inline bool
3732 operator!=(const std::geometric_distribution<_IntType>& __d1,
3733 const std::geometric_distribution<_IntType>& __d2)
3734 { return !(__d1 == __d2); }
3737 * @brief Inserts a %geometric_distribution random number distribution
3738 * @p __x into the output stream @p __os.
3740 * @param __os An output stream.
3741 * @param __x A %geometric_distribution random number distribution.
3743 * @returns The output stream with the state of @p __x inserted or in
3744 * an error state.
3746 template<typename _IntType,
3747 typename _CharT, typename _Traits>
3748 std::basic_ostream<_CharT, _Traits>&
3749 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3750 const std::geometric_distribution<_IntType>& __x);
3753 * @brief Extracts a %geometric_distribution random number distribution
3754 * @p __x from the input stream @p __is.
3756 * @param __is An input stream.
3757 * @param __x A %geometric_distribution random number generator engine.
3759 * @returns The input stream with @p __x extracted or in an error state.
3761 template<typename _IntType,
3762 typename _CharT, typename _Traits>
3763 std::basic_istream<_CharT, _Traits>&
3764 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3765 std::geometric_distribution<_IntType>& __x);
3769 * @brief A negative_binomial_distribution random number distribution.
3771 * The formula for the negative binomial probability mass function is
3772 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3773 * and @f$p@f$ are the parameters of the distribution.
3775 template<typename _IntType = int>
3776 class negative_binomial_distribution
3778 static_assert(std::is_integral<_IntType>::value,
3779 "template argument not an integral type");
3781 public:
3782 /** The type of the range of the distribution. */
3783 typedef _IntType result_type;
3784 /** Parameter type. */
3785 struct param_type
3787 typedef negative_binomial_distribution<_IntType> distribution_type;
3789 explicit
3790 param_type(_IntType __k = 1, double __p = 0.5)
3791 : _M_k(__k), _M_p(__p)
3793 _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
3796 _IntType
3797 k() const
3798 { return _M_k; }
3800 double
3801 p() const
3802 { return _M_p; }
3804 friend bool
3805 operator==(const param_type& __p1, const param_type& __p2)
3806 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3808 private:
3809 _IntType _M_k;
3810 double _M_p;
3813 explicit
3814 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3815 : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
3818 explicit
3819 negative_binomial_distribution(const param_type& __p)
3820 : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
3824 * @brief Resets the distribution state.
3826 void
3827 reset()
3828 { _M_gd.reset(); }
3831 * @brief Return the @f$k@f$ parameter of the distribution.
3833 _IntType
3834 k() const
3835 { return _M_param.k(); }
3838 * @brief Return the @f$p@f$ parameter of the distribution.
3840 double
3841 p() const
3842 { return _M_param.p(); }
3845 * @brief Returns the parameter set of the distribution.
3847 param_type
3848 param() const
3849 { return _M_param; }
3852 * @brief Sets the parameter set of the distribution.
3853 * @param __param The new parameter set of the distribution.
3855 void
3856 param(const param_type& __param)
3857 { _M_param = __param; }
3860 * @brief Returns the greatest lower bound value of the distribution.
3862 result_type
3863 min() const
3864 { return result_type(0); }
3867 * @brief Returns the least upper bound value of the distribution.
3869 result_type
3870 max() const
3871 { return std::numeric_limits<result_type>::max(); }
3874 * @brief Generating functions.
3876 template<typename _UniformRandomNumberGenerator>
3877 result_type
3878 operator()(_UniformRandomNumberGenerator& __urng);
3880 template<typename _UniformRandomNumberGenerator>
3881 result_type
3882 operator()(_UniformRandomNumberGenerator& __urng,
3883 const param_type& __p);
3886 * @brief Return true if two negative binomial distributions have
3887 * the same parameters and the sequences that would be
3888 * generated are equal.
3890 template<typename _IntType1>
3891 friend bool
3892 operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
3893 const std::negative_binomial_distribution<_IntType1>& __d2)
3894 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3897 * @brief Inserts a %negative_binomial_distribution random
3898 * number distribution @p __x into the output stream @p __os.
3900 * @param __os An output stream.
3901 * @param __x A %negative_binomial_distribution random number
3902 * distribution.
3904 * @returns The output stream with the state of @p __x inserted or in
3905 * an error state.
3907 template<typename _IntType1, typename _CharT, typename _Traits>
3908 friend std::basic_ostream<_CharT, _Traits>&
3909 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3910 const std::negative_binomial_distribution<_IntType1>& __x);
3913 * @brief Extracts a %negative_binomial_distribution random number
3914 * distribution @p __x from the input stream @p __is.
3916 * @param __is An input stream.
3917 * @param __x A %negative_binomial_distribution random number
3918 * generator engine.
3920 * @returns The input stream with @p __x extracted or in an error state.
3922 template<typename _IntType1, typename _CharT, typename _Traits>
3923 friend std::basic_istream<_CharT, _Traits>&
3924 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3925 std::negative_binomial_distribution<_IntType1>& __x);
3927 private:
3928 param_type _M_param;
3930 std::gamma_distribution<double> _M_gd;
3934 * @brief Return true if two negative binomial distributions are different.
3936 template<typename _IntType>
3937 inline bool
3938 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3939 const std::negative_binomial_distribution<_IntType>& __d2)
3940 { return !(__d1 == __d2); }
3943 /* @} */ // group random_distributions_bernoulli
3946 * @addtogroup random_distributions_poisson Poisson Distributions
3947 * @ingroup random_distributions
3948 * @{
3952 * @brief A discrete Poisson random number distribution.
3954 * The formula for the Poisson probability density function is
3955 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3956 * parameter of the distribution.
3958 template<typename _IntType = int>
3959 class poisson_distribution
3961 static_assert(std::is_integral<_IntType>::value,
3962 "template argument not an integral type");
3964 public:
3965 /** The type of the range of the distribution. */
3966 typedef _IntType result_type;
3967 /** Parameter type. */
3968 struct param_type
3970 typedef poisson_distribution<_IntType> distribution_type;
3971 friend class poisson_distribution<_IntType>;
3973 explicit
3974 param_type(double __mean = 1.0)
3975 : _M_mean(__mean)
3977 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3978 _M_initialize();
3981 double
3982 mean() const
3983 { return _M_mean; }
3985 friend bool
3986 operator==(const param_type& __p1, const param_type& __p2)
3987 { return __p1._M_mean == __p2._M_mean; }
3989 private:
3990 // Hosts either log(mean) or the threshold of the simple method.
3991 void
3992 _M_initialize();
3994 double _M_mean;
3996 double _M_lm_thr;
3997 #if _GLIBCXX_USE_C99_MATH_TR1
3998 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3999 #endif
4002 // constructors and member function
4003 explicit
4004 poisson_distribution(double __mean = 1.0)
4005 : _M_param(__mean), _M_nd()
4008 explicit
4009 poisson_distribution(const param_type& __p)
4010 : _M_param(__p), _M_nd()
4014 * @brief Resets the distribution state.
4016 void
4017 reset()
4018 { _M_nd.reset(); }
4021 * @brief Returns the distribution parameter @p mean.
4023 double
4024 mean() const
4025 { return _M_param.mean(); }
4028 * @brief Returns the parameter set of the distribution.
4030 param_type
4031 param() const
4032 { return _M_param; }
4035 * @brief Sets the parameter set of the distribution.
4036 * @param __param The new parameter set of the distribution.
4038 void
4039 param(const param_type& __param)
4040 { _M_param = __param; }
4043 * @brief Returns the greatest lower bound value of the distribution.
4045 result_type
4046 min() const
4047 { return 0; }
4050 * @brief Returns the least upper bound value of the distribution.
4052 result_type
4053 max() const
4054 { return std::numeric_limits<result_type>::max(); }
4057 * @brief Generating functions.
4059 template<typename _UniformRandomNumberGenerator>
4060 result_type
4061 operator()(_UniformRandomNumberGenerator& __urng)
4062 { return this->operator()(__urng, this->param()); }
4064 template<typename _UniformRandomNumberGenerator>
4065 result_type
4066 operator()(_UniformRandomNumberGenerator& __urng,
4067 const param_type& __p);
4070 * @brief Return true if two Poisson distributions have the same
4071 * parameters and the sequences that would be generated
4072 * are equal.
4074 template<typename _IntType1>
4075 friend bool
4076 operator==(const std::poisson_distribution<_IntType1>& __d1,
4077 const std::poisson_distribution<_IntType1>& __d2)
4078 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4079 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4080 #else
4081 { return __d1.param() == __d2.param(); }
4082 #endif
4085 * @brief Inserts a %poisson_distribution random number distribution
4086 * @p __x into the output stream @p __os.
4088 * @param __os An output stream.
4089 * @param __x A %poisson_distribution random number distribution.
4091 * @returns The output stream with the state of @p __x inserted or in
4092 * an error state.
4094 template<typename _IntType1, typename _CharT, typename _Traits>
4095 friend std::basic_ostream<_CharT, _Traits>&
4096 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4097 const std::poisson_distribution<_IntType1>& __x);
4100 * @brief Extracts a %poisson_distribution random number distribution
4101 * @p __x from the input stream @p __is.
4103 * @param __is An input stream.
4104 * @param __x A %poisson_distribution random number generator engine.
4106 * @returns The input stream with @p __x extracted or in an error
4107 * state.
4109 template<typename _IntType1, typename _CharT, typename _Traits>
4110 friend std::basic_istream<_CharT, _Traits>&
4111 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4112 std::poisson_distribution<_IntType1>& __x);
4114 private:
4115 param_type _M_param;
4117 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4118 std::normal_distribution<double> _M_nd;
4122 * @brief Return true if two Poisson distributions are different.
4124 template<typename _IntType>
4125 inline bool
4126 operator!=(const std::poisson_distribution<_IntType>& __d1,
4127 const std::poisson_distribution<_IntType>& __d2)
4128 { return !(__d1 == __d2); }
4132 * @brief An exponential continuous distribution for random numbers.
4134 * The formula for the exponential probability density function is
4135 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4137 * <table border=1 cellpadding=10 cellspacing=0>
4138 * <caption align=top>Distribution Statistics</caption>
4139 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4140 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4141 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4142 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4143 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4144 * </table>
4146 template<typename _RealType = double>
4147 class exponential_distribution
4149 static_assert(std::is_floating_point<_RealType>::value,
4150 "template argument not a floating point type");
4152 public:
4153 /** The type of the range of the distribution. */
4154 typedef _RealType result_type;
4155 /** Parameter type. */
4156 struct param_type
4158 typedef exponential_distribution<_RealType> distribution_type;
4160 explicit
4161 param_type(_RealType __lambda = _RealType(1))
4162 : _M_lambda(__lambda)
4164 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4167 _RealType
4168 lambda() const
4169 { return _M_lambda; }
4171 friend bool
4172 operator==(const param_type& __p1, const param_type& __p2)
4173 { return __p1._M_lambda == __p2._M_lambda; }
4175 private:
4176 _RealType _M_lambda;
4179 public:
4181 * @brief Constructs an exponential distribution with inverse scale
4182 * parameter @f$\lambda@f$.
4184 explicit
4185 exponential_distribution(const result_type& __lambda = result_type(1))
4186 : _M_param(__lambda)
4189 explicit
4190 exponential_distribution(const param_type& __p)
4191 : _M_param(__p)
4195 * @brief Resets the distribution state.
4197 * Has no effect on exponential distributions.
4199 void
4200 reset() { }
4203 * @brief Returns the inverse scale parameter of the distribution.
4205 _RealType
4206 lambda() const
4207 { return _M_param.lambda(); }
4210 * @brief Returns the parameter set of the distribution.
4212 param_type
4213 param() const
4214 { return _M_param; }
4217 * @brief Sets the parameter set of the distribution.
4218 * @param __param The new parameter set of the distribution.
4220 void
4221 param(const param_type& __param)
4222 { _M_param = __param; }
4225 * @brief Returns the greatest lower bound value of the distribution.
4227 result_type
4228 min() const
4229 { return result_type(0); }
4232 * @brief Returns the least upper bound value of the distribution.
4234 result_type
4235 max() const
4236 { return std::numeric_limits<result_type>::max(); }
4239 * @brief Generating functions.
4241 template<typename _UniformRandomNumberGenerator>
4242 result_type
4243 operator()(_UniformRandomNumberGenerator& __urng)
4244 { return this->operator()(__urng, this->param()); }
4246 template<typename _UniformRandomNumberGenerator>
4247 result_type
4248 operator()(_UniformRandomNumberGenerator& __urng,
4249 const param_type& __p)
4251 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4252 __aurng(__urng);
4253 return -std::log(__aurng()) / __p.lambda();
4256 private:
4257 param_type _M_param;
4261 * @brief Return true if two exponential distributions have the same
4262 * parameters.
4264 template<typename _RealType>
4265 inline bool
4266 operator==(const std::exponential_distribution<_RealType>& __d1,
4267 const std::exponential_distribution<_RealType>& __d2)
4268 { return __d1.param() == __d2.param(); }
4271 * @brief Return true if two exponential distributions have different
4272 * parameters.
4274 template<typename _RealType>
4275 inline bool
4276 operator!=(const std::exponential_distribution<_RealType>& __d1,
4277 const std::exponential_distribution<_RealType>& __d2)
4278 { return !(__d1 == __d2); }
4281 * @brief Inserts a %exponential_distribution random number distribution
4282 * @p __x into the output stream @p __os.
4284 * @param __os An output stream.
4285 * @param __x A %exponential_distribution random number distribution.
4287 * @returns The output stream with the state of @p __x inserted or in
4288 * an error state.
4290 template<typename _RealType, typename _CharT, typename _Traits>
4291 std::basic_ostream<_CharT, _Traits>&
4292 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4293 const std::exponential_distribution<_RealType>& __x);
4296 * @brief Extracts a %exponential_distribution random number distribution
4297 * @p __x from the input stream @p __is.
4299 * @param __is An input stream.
4300 * @param __x A %exponential_distribution random number
4301 * generator engine.
4303 * @returns The input stream with @p __x extracted or in an error state.
4305 template<typename _RealType, typename _CharT, typename _Traits>
4306 std::basic_istream<_CharT, _Traits>&
4307 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4308 std::exponential_distribution<_RealType>& __x);
4312 * @brief A weibull_distribution random number distribution.
4314 * The formula for the normal probability density function is:
4315 * @f[
4316 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4317 * \exp{(-(\frac{x}{\beta})^\alpha)}
4318 * @f]
4320 template<typename _RealType = double>
4321 class weibull_distribution
4323 static_assert(std::is_floating_point<_RealType>::value,
4324 "template argument not a floating point type");
4326 public:
4327 /** The type of the range of the distribution. */
4328 typedef _RealType result_type;
4329 /** Parameter type. */
4330 struct param_type
4332 typedef weibull_distribution<_RealType> distribution_type;
4334 explicit
4335 param_type(_RealType __a = _RealType(1),
4336 _RealType __b = _RealType(1))
4337 : _M_a(__a), _M_b(__b)
4340 _RealType
4341 a() const
4342 { return _M_a; }
4344 _RealType
4345 b() const
4346 { return _M_b; }
4348 friend bool
4349 operator==(const param_type& __p1, const param_type& __p2)
4350 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4352 private:
4353 _RealType _M_a;
4354 _RealType _M_b;
4357 explicit
4358 weibull_distribution(_RealType __a = _RealType(1),
4359 _RealType __b = _RealType(1))
4360 : _M_param(__a, __b)
4363 explicit
4364 weibull_distribution(const param_type& __p)
4365 : _M_param(__p)
4369 * @brief Resets the distribution state.
4371 void
4372 reset()
4376 * @brief Return the @f$a@f$ parameter of the distribution.
4378 _RealType
4379 a() const
4380 { return _M_param.a(); }
4383 * @brief Return the @f$b@f$ parameter of the distribution.
4385 _RealType
4386 b() const
4387 { return _M_param.b(); }
4390 * @brief Returns the parameter set of the distribution.
4392 param_type
4393 param() const
4394 { return _M_param; }
4397 * @brief Sets the parameter set of the distribution.
4398 * @param __param The new parameter set of the distribution.
4400 void
4401 param(const param_type& __param)
4402 { _M_param = __param; }
4405 * @brief Returns the greatest lower bound value of the distribution.
4407 result_type
4408 min() const
4409 { return result_type(0); }
4412 * @brief Returns the least upper bound value of the distribution.
4414 result_type
4415 max() const
4416 { return std::numeric_limits<result_type>::max(); }
4419 * @brief Generating functions.
4421 template<typename _UniformRandomNumberGenerator>
4422 result_type
4423 operator()(_UniformRandomNumberGenerator& __urng)
4424 { return this->operator()(__urng, this->param()); }
4426 template<typename _UniformRandomNumberGenerator>
4427 result_type
4428 operator()(_UniformRandomNumberGenerator& __urng,
4429 const param_type& __p);
4431 private:
4432 param_type _M_param;
4436 * @brief Return true if two Weibull distributions have the same
4437 * parameters.
4439 template<typename _RealType>
4440 inline bool
4441 operator==(const std::weibull_distribution<_RealType>& __d1,
4442 const std::weibull_distribution<_RealType>& __d2)
4443 { return __d1.param() == __d2.param(); }
4446 * @brief Return true if two Weibull distributions have different
4447 * parameters.
4449 template<typename _RealType>
4450 inline bool
4451 operator!=(const std::weibull_distribution<_RealType>& __d1,
4452 const std::weibull_distribution<_RealType>& __d2)
4453 { return !(__d1 == __d2); }
4456 * @brief Inserts a %weibull_distribution random number distribution
4457 * @p __x into the output stream @p __os.
4459 * @param __os An output stream.
4460 * @param __x A %weibull_distribution random number distribution.
4462 * @returns The output stream with the state of @p __x inserted or in
4463 * an error state.
4465 template<typename _RealType, typename _CharT, typename _Traits>
4466 std::basic_ostream<_CharT, _Traits>&
4467 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4468 const std::weibull_distribution<_RealType>& __x);
4471 * @brief Extracts a %weibull_distribution random number distribution
4472 * @p __x from the input stream @p __is.
4474 * @param __is An input stream.
4475 * @param __x A %weibull_distribution random number
4476 * generator engine.
4478 * @returns The input stream with @p __x extracted or in an error state.
4480 template<typename _RealType, typename _CharT, typename _Traits>
4481 std::basic_istream<_CharT, _Traits>&
4482 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4483 std::weibull_distribution<_RealType>& __x);
4487 * @brief A extreme_value_distribution random number distribution.
4489 * The formula for the normal probability mass function is
4490 * @f[
4491 * p(x|a,b) = \frac{1}{b}
4492 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4493 * @f]
4495 template<typename _RealType = double>
4496 class extreme_value_distribution
4498 static_assert(std::is_floating_point<_RealType>::value,
4499 "template argument not a floating point type");
4501 public:
4502 /** The type of the range of the distribution. */
4503 typedef _RealType result_type;
4504 /** Parameter type. */
4505 struct param_type
4507 typedef extreme_value_distribution<_RealType> distribution_type;
4509 explicit
4510 param_type(_RealType __a = _RealType(0),
4511 _RealType __b = _RealType(1))
4512 : _M_a(__a), _M_b(__b)
4515 _RealType
4516 a() const
4517 { return _M_a; }
4519 _RealType
4520 b() const
4521 { return _M_b; }
4523 friend bool
4524 operator==(const param_type& __p1, const param_type& __p2)
4525 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4527 private:
4528 _RealType _M_a;
4529 _RealType _M_b;
4532 explicit
4533 extreme_value_distribution(_RealType __a = _RealType(0),
4534 _RealType __b = _RealType(1))
4535 : _M_param(__a, __b)
4538 explicit
4539 extreme_value_distribution(const param_type& __p)
4540 : _M_param(__p)
4544 * @brief Resets the distribution state.
4546 void
4547 reset()
4551 * @brief Return the @f$a@f$ parameter of the distribution.
4553 _RealType
4554 a() const
4555 { return _M_param.a(); }
4558 * @brief Return the @f$b@f$ parameter of the distribution.
4560 _RealType
4561 b() const
4562 { return _M_param.b(); }
4565 * @brief Returns the parameter set of the distribution.
4567 param_type
4568 param() const
4569 { return _M_param; }
4572 * @brief Sets the parameter set of the distribution.
4573 * @param __param The new parameter set of the distribution.
4575 void
4576 param(const param_type& __param)
4577 { _M_param = __param; }
4580 * @brief Returns the greatest lower bound value of the distribution.
4582 result_type
4583 min() const
4584 { return std::numeric_limits<result_type>::min(); }
4587 * @brief Returns the least upper bound value of the distribution.
4589 result_type
4590 max() const
4591 { return std::numeric_limits<result_type>::max(); }
4594 * @brief Generating functions.
4596 template<typename _UniformRandomNumberGenerator>
4597 result_type
4598 operator()(_UniformRandomNumberGenerator& __urng)
4599 { return this->operator()(__urng, this->param()); }
4601 template<typename _UniformRandomNumberGenerator>
4602 result_type
4603 operator()(_UniformRandomNumberGenerator& __urng,
4604 const param_type& __p);
4606 private:
4607 param_type _M_param;
4611 * @brief Return true if two extreme value distributions have the same
4612 * parameters.
4614 template<typename _RealType>
4615 inline bool
4616 operator==(const std::extreme_value_distribution<_RealType>& __d1,
4617 const std::extreme_value_distribution<_RealType>& __d2)
4618 { return __d1.param() == __d2.param(); }
4621 * @brief Return true if two extreme value distributions have different
4622 * parameters.
4624 template<typename _RealType>
4625 inline bool
4626 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4627 const std::extreme_value_distribution<_RealType>& __d2)
4628 { return !(__d1 == __d2); }
4631 * @brief Inserts a %extreme_value_distribution random number distribution
4632 * @p __x into the output stream @p __os.
4634 * @param __os An output stream.
4635 * @param __x A %extreme_value_distribution random number distribution.
4637 * @returns The output stream with the state of @p __x inserted or in
4638 * an error state.
4640 template<typename _RealType, typename _CharT, typename _Traits>
4641 std::basic_ostream<_CharT, _Traits>&
4642 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4643 const std::extreme_value_distribution<_RealType>& __x);
4646 * @brief Extracts a %extreme_value_distribution random number
4647 * distribution @p __x from the input stream @p __is.
4649 * @param __is An input stream.
4650 * @param __x A %extreme_value_distribution random number
4651 * generator engine.
4653 * @returns The input stream with @p __x extracted or in an error state.
4655 template<typename _RealType, typename _CharT, typename _Traits>
4656 std::basic_istream<_CharT, _Traits>&
4657 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4658 std::extreme_value_distribution<_RealType>& __x);
4662 * @brief A discrete_distribution random number distribution.
4664 * The formula for the discrete probability mass function is
4667 template<typename _IntType = int>
4668 class discrete_distribution
4670 static_assert(std::is_integral<_IntType>::value,
4671 "template argument not an integral type");
4673 public:
4674 /** The type of the range of the distribution. */
4675 typedef _IntType result_type;
4676 /** Parameter type. */
4677 struct param_type
4679 typedef discrete_distribution<_IntType> distribution_type;
4680 friend class discrete_distribution<_IntType>;
4682 param_type()
4683 : _M_prob(), _M_cp()
4686 template<typename _InputIterator>
4687 param_type(_InputIterator __wbegin,
4688 _InputIterator __wend)
4689 : _M_prob(__wbegin, __wend), _M_cp()
4690 { _M_initialize(); }
4692 param_type(initializer_list<double> __wil)
4693 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4694 { _M_initialize(); }
4696 template<typename _Func>
4697 param_type(size_t __nw, double __xmin, double __xmax,
4698 _Func __fw);
4700 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4701 param_type(const param_type&) = default;
4702 param_type& operator=(const param_type&) = default;
4704 std::vector<double>
4705 probabilities() const
4706 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4708 friend bool
4709 operator==(const param_type& __p1, const param_type& __p2)
4710 { return __p1._M_prob == __p2._M_prob; }
4712 private:
4713 void
4714 _M_initialize();
4716 std::vector<double> _M_prob;
4717 std::vector<double> _M_cp;
4720 discrete_distribution()
4721 : _M_param()
4724 template<typename _InputIterator>
4725 discrete_distribution(_InputIterator __wbegin,
4726 _InputIterator __wend)
4727 : _M_param(__wbegin, __wend)
4730 discrete_distribution(initializer_list<double> __wl)
4731 : _M_param(__wl)
4734 template<typename _Func>
4735 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4736 _Func __fw)
4737 : _M_param(__nw, __xmin, __xmax, __fw)
4740 explicit
4741 discrete_distribution(const param_type& __p)
4742 : _M_param(__p)
4746 * @brief Resets the distribution state.
4748 void
4749 reset()
4753 * @brief Returns the probabilities of the distribution.
4755 std::vector<double>
4756 probabilities() const
4758 return _M_param._M_prob.empty()
4759 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4763 * @brief Returns the parameter set of the distribution.
4765 param_type
4766 param() const
4767 { return _M_param; }
4770 * @brief Sets the parameter set of the distribution.
4771 * @param __param The new parameter set of the distribution.
4773 void
4774 param(const param_type& __param)
4775 { _M_param = __param; }
4778 * @brief Returns the greatest lower bound value of the distribution.
4780 result_type
4781 min() const
4782 { return result_type(0); }
4785 * @brief Returns the least upper bound value of the distribution.
4787 result_type
4788 max() const
4790 return _M_param._M_prob.empty()
4791 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4795 * @brief Generating functions.
4797 template<typename _UniformRandomNumberGenerator>
4798 result_type
4799 operator()(_UniformRandomNumberGenerator& __urng)
4800 { return this->operator()(__urng, this->param()); }
4802 template<typename _UniformRandomNumberGenerator>
4803 result_type
4804 operator()(_UniformRandomNumberGenerator& __urng,
4805 const param_type& __p);
4808 * @brief Inserts a %discrete_distribution random number distribution
4809 * @p __x into the output stream @p __os.
4811 * @param __os An output stream.
4812 * @param __x A %discrete_distribution random number distribution.
4814 * @returns The output stream with the state of @p __x inserted or in
4815 * an error state.
4817 template<typename _IntType1, typename _CharT, typename _Traits>
4818 friend std::basic_ostream<_CharT, _Traits>&
4819 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
4820 const std::discrete_distribution<_IntType1>& __x);
4823 * @brief Extracts a %discrete_distribution random number distribution
4824 * @p __x from the input stream @p __is.
4826 * @param __is An input stream.
4827 * @param __x A %discrete_distribution random number
4828 * generator engine.
4830 * @returns The input stream with @p __x extracted or in an error
4831 * state.
4833 template<typename _IntType1, typename _CharT, typename _Traits>
4834 friend std::basic_istream<_CharT, _Traits>&
4835 operator>>(std::basic_istream<_CharT, _Traits>& __is,
4836 std::discrete_distribution<_IntType1>& __x);
4838 private:
4839 param_type _M_param;
4843 * @brief Return true if two discrete distributions have the same
4844 * parameters.
4846 template<typename _IntType>
4847 inline bool
4848 operator==(const std::discrete_distribution<_IntType>& __d1,
4849 const std::discrete_distribution<_IntType>& __d2)
4850 { return __d1.param() == __d2.param(); }
4853 * @brief Return true if two discrete distributions have different
4854 * parameters.
4856 template<typename _IntType>
4857 inline bool
4858 operator!=(const std::discrete_distribution<_IntType>& __d1,
4859 const std::discrete_distribution<_IntType>& __d2)
4860 { return !(__d1 == __d2); }
4864 * @brief A piecewise_constant_distribution random number distribution.
4866 * The formula for the piecewise constant probability mass function is
4869 template<typename _RealType = double>
4870 class piecewise_constant_distribution
4872 static_assert(std::is_floating_point<_RealType>::value,
4873 "template argument not a floating point type");
4875 public:
4876 /** The type of the range of the distribution. */
4877 typedef _RealType result_type;
4878 /** Parameter type. */
4879 struct param_type
4881 typedef piecewise_constant_distribution<_RealType> distribution_type;
4882 friend class piecewise_constant_distribution<_RealType>;
4884 param_type()
4885 : _M_int(), _M_den(), _M_cp()
4888 template<typename _InputIteratorB, typename _InputIteratorW>
4889 param_type(_InputIteratorB __bfirst,
4890 _InputIteratorB __bend,
4891 _InputIteratorW __wbegin);
4893 template<typename _Func>
4894 param_type(initializer_list<_RealType> __bi, _Func __fw);
4896 template<typename _Func>
4897 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4898 _Func __fw);
4900 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4901 param_type(const param_type&) = default;
4902 param_type& operator=(const param_type&) = default;
4904 std::vector<_RealType>
4905 intervals() const
4907 if (_M_int.empty())
4909 std::vector<_RealType> __tmp(2);
4910 __tmp[1] = _RealType(1);
4911 return __tmp;
4913 else
4914 return _M_int;
4917 std::vector<double>
4918 densities() const
4919 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4921 friend bool
4922 operator==(const param_type& __p1, const param_type& __p2)
4923 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4925 private:
4926 void
4927 _M_initialize();
4929 std::vector<_RealType> _M_int;
4930 std::vector<double> _M_den;
4931 std::vector<double> _M_cp;
4934 explicit
4935 piecewise_constant_distribution()
4936 : _M_param()
4939 template<typename _InputIteratorB, typename _InputIteratorW>
4940 piecewise_constant_distribution(_InputIteratorB __bfirst,
4941 _InputIteratorB __bend,
4942 _InputIteratorW __wbegin)
4943 : _M_param(__bfirst, __bend, __wbegin)
4946 template<typename _Func>
4947 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4948 _Func __fw)
4949 : _M_param(__bl, __fw)
4952 template<typename _Func>
4953 piecewise_constant_distribution(size_t __nw,
4954 _RealType __xmin, _RealType __xmax,
4955 _Func __fw)
4956 : _M_param(__nw, __xmin, __xmax, __fw)
4959 explicit
4960 piecewise_constant_distribution(const param_type& __p)
4961 : _M_param(__p)
4965 * @brief Resets the distribution state.
4967 void
4968 reset()
4972 * @brief Returns a vector of the intervals.
4974 std::vector<_RealType>
4975 intervals() const
4977 if (_M_param._M_int.empty())
4979 std::vector<_RealType> __tmp(2);
4980 __tmp[1] = _RealType(1);
4981 return __tmp;
4983 else
4984 return _M_param._M_int;
4988 * @brief Returns a vector of the probability densities.
4990 std::vector<double>
4991 densities() const
4993 return _M_param._M_den.empty()
4994 ? std::vector<double>(1, 1.0) : _M_param._M_den;
4998 * @brief Returns the parameter set of the distribution.
5000 param_type
5001 param() const
5002 { return _M_param; }
5005 * @brief Sets the parameter set of the distribution.
5006 * @param __param The new parameter set of the distribution.
5008 void
5009 param(const param_type& __param)
5010 { _M_param = __param; }
5013 * @brief Returns the greatest lower bound value of the distribution.
5015 result_type
5016 min() const
5018 return _M_param._M_int.empty()
5019 ? result_type(0) : _M_param._M_int.front();
5023 * @brief Returns the least upper bound value of the distribution.
5025 result_type
5026 max() const
5028 return _M_param._M_int.empty()
5029 ? result_type(1) : _M_param._M_int.back();
5033 * @brief Generating functions.
5035 template<typename _UniformRandomNumberGenerator>
5036 result_type
5037 operator()(_UniformRandomNumberGenerator& __urng)
5038 { return this->operator()(__urng, this->param()); }
5040 template<typename _UniformRandomNumberGenerator>
5041 result_type
5042 operator()(_UniformRandomNumberGenerator& __urng,
5043 const param_type& __p);
5046 * @brief Inserts a %piecewise_constan_distribution random
5047 * number distribution @p __x into the output stream @p __os.
5049 * @param __os An output stream.
5050 * @param __x A %piecewise_constan_distribution random number
5051 * distribution.
5053 * @returns The output stream with the state of @p __x inserted or in
5054 * an error state.
5056 template<typename _RealType1, typename _CharT, typename _Traits>
5057 friend std::basic_ostream<_CharT, _Traits>&
5058 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5059 const std::piecewise_constant_distribution<_RealType1>& __x);
5062 * @brief Extracts a %piecewise_constan_distribution random
5063 * number distribution @p __x from the input stream @p __is.
5065 * @param __is An input stream.
5066 * @param __x A %piecewise_constan_distribution random number
5067 * generator engine.
5069 * @returns The input stream with @p __x extracted or in an error
5070 * state.
5072 template<typename _RealType1, typename _CharT, typename _Traits>
5073 friend std::basic_istream<_CharT, _Traits>&
5074 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5075 std::piecewise_constant_distribution<_RealType1>& __x);
5077 private:
5078 param_type _M_param;
5082 * @brief Return true if two piecewise constant distributions have the
5083 * same parameters.
5085 template<typename _RealType>
5086 inline bool
5087 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
5088 const std::piecewise_constant_distribution<_RealType>& __d2)
5089 { return __d1.param() == __d2.param(); }
5092 * @brief Return true if two piecewise constant distributions have
5093 * different parameters.
5095 template<typename _RealType>
5096 inline bool
5097 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5098 const std::piecewise_constant_distribution<_RealType>& __d2)
5099 { return !(__d1 == __d2); }
5103 * @brief A piecewise_linear_distribution random number distribution.
5105 * The formula for the piecewise linear probability mass function is
5108 template<typename _RealType = double>
5109 class piecewise_linear_distribution
5111 static_assert(std::is_floating_point<_RealType>::value,
5112 "template argument not a floating point type");
5114 public:
5115 /** The type of the range of the distribution. */
5116 typedef _RealType result_type;
5117 /** Parameter type. */
5118 struct param_type
5120 typedef piecewise_linear_distribution<_RealType> distribution_type;
5121 friend class piecewise_linear_distribution<_RealType>;
5123 param_type()
5124 : _M_int(), _M_den(), _M_cp(), _M_m()
5127 template<typename _InputIteratorB, typename _InputIteratorW>
5128 param_type(_InputIteratorB __bfirst,
5129 _InputIteratorB __bend,
5130 _InputIteratorW __wbegin);
5132 template<typename _Func>
5133 param_type(initializer_list<_RealType> __bl, _Func __fw);
5135 template<typename _Func>
5136 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5137 _Func __fw);
5139 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5140 param_type(const param_type&) = default;
5141 param_type& operator=(const param_type&) = default;
5143 std::vector<_RealType>
5144 intervals() const
5146 if (_M_int.empty())
5148 std::vector<_RealType> __tmp(2);
5149 __tmp[1] = _RealType(1);
5150 return __tmp;
5152 else
5153 return _M_int;
5156 std::vector<double>
5157 densities() const
5158 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5160 friend bool
5161 operator==(const param_type& __p1, const param_type& __p2)
5162 { return (__p1._M_int == __p2._M_int
5163 && __p1._M_den == __p2._M_den); }
5165 private:
5166 void
5167 _M_initialize();
5169 std::vector<_RealType> _M_int;
5170 std::vector<double> _M_den;
5171 std::vector<double> _M_cp;
5172 std::vector<double> _M_m;
5175 explicit
5176 piecewise_linear_distribution()
5177 : _M_param()
5180 template<typename _InputIteratorB, typename _InputIteratorW>
5181 piecewise_linear_distribution(_InputIteratorB __bfirst,
5182 _InputIteratorB __bend,
5183 _InputIteratorW __wbegin)
5184 : _M_param(__bfirst, __bend, __wbegin)
5187 template<typename _Func>
5188 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5189 _Func __fw)
5190 : _M_param(__bl, __fw)
5193 template<typename _Func>
5194 piecewise_linear_distribution(size_t __nw,
5195 _RealType __xmin, _RealType __xmax,
5196 _Func __fw)
5197 : _M_param(__nw, __xmin, __xmax, __fw)
5200 explicit
5201 piecewise_linear_distribution(const param_type& __p)
5202 : _M_param(__p)
5206 * Resets the distribution state.
5208 void
5209 reset()
5213 * @brief Return the intervals of the distribution.
5215 std::vector<_RealType>
5216 intervals() const
5218 if (_M_param._M_int.empty())
5220 std::vector<_RealType> __tmp(2);
5221 __tmp[1] = _RealType(1);
5222 return __tmp;
5224 else
5225 return _M_param._M_int;
5229 * @brief Return a vector of the probability densities of the
5230 * distribution.
5232 std::vector<double>
5233 densities() const
5235 return _M_param._M_den.empty()
5236 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5240 * @brief Returns the parameter set of the distribution.
5242 param_type
5243 param() const
5244 { return _M_param; }
5247 * @brief Sets the parameter set of the distribution.
5248 * @param __param The new parameter set of the distribution.
5250 void
5251 param(const param_type& __param)
5252 { _M_param = __param; }
5255 * @brief Returns the greatest lower bound value of the distribution.
5257 result_type
5258 min() const
5260 return _M_param._M_int.empty()
5261 ? result_type(0) : _M_param._M_int.front();
5265 * @brief Returns the least upper bound value of the distribution.
5267 result_type
5268 max() const
5270 return _M_param._M_int.empty()
5271 ? result_type(1) : _M_param._M_int.back();
5275 * @brief Generating functions.
5277 template<typename _UniformRandomNumberGenerator>
5278 result_type
5279 operator()(_UniformRandomNumberGenerator& __urng)
5280 { return this->operator()(__urng, this->param()); }
5282 template<typename _UniformRandomNumberGenerator>
5283 result_type
5284 operator()(_UniformRandomNumberGenerator& __urng,
5285 const param_type& __p);
5288 * @brief Inserts a %piecewise_linear_distribution random number
5289 * distribution @p __x into the output stream @p __os.
5291 * @param __os An output stream.
5292 * @param __x A %piecewise_linear_distribution random number
5293 * distribution.
5295 * @returns The output stream with the state of @p __x inserted or in
5296 * an error state.
5298 template<typename _RealType1, typename _CharT, typename _Traits>
5299 friend std::basic_ostream<_CharT, _Traits>&
5300 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
5301 const std::piecewise_linear_distribution<_RealType1>& __x);
5304 * @brief Extracts a %piecewise_linear_distribution random number
5305 * distribution @p __x from the input stream @p __is.
5307 * @param __is An input stream.
5308 * @param __x A %piecewise_linear_distribution random number
5309 * generator engine.
5311 * @returns The input stream with @p __x extracted or in an error
5312 * state.
5314 template<typename _RealType1, typename _CharT, typename _Traits>
5315 friend std::basic_istream<_CharT, _Traits>&
5316 operator>>(std::basic_istream<_CharT, _Traits>& __is,
5317 std::piecewise_linear_distribution<_RealType1>& __x);
5319 private:
5320 param_type _M_param;
5324 * @brief Return true if two piecewise linear distributions have the
5325 * same parameters.
5327 template<typename _RealType>
5328 inline bool
5329 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
5330 const std::piecewise_linear_distribution<_RealType>& __d2)
5331 { return __d1.param() == __d2.param(); }
5334 * @brief Return true if two piecewise linear distributions have
5335 * different parameters.
5337 template<typename _RealType>
5338 inline bool
5339 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5340 const std::piecewise_linear_distribution<_RealType>& __d2)
5341 { return !(__d1 == __d2); }
5344 /* @} */ // group random_distributions_poisson
5346 /* @} */ // group random_distributions
5349 * @addtogroup random_utilities Random Number Utilities
5350 * @ingroup random
5351 * @{
5355 * @brief The seed_seq class generates sequences of seeds for random
5356 * number generators.
5358 class seed_seq
5361 public:
5362 /** The type of the seed vales. */
5363 typedef uint_least32_t result_type;
5365 /** Default constructor. */
5366 seed_seq()
5367 : _M_v()
5370 template<typename _IntType>
5371 seed_seq(std::initializer_list<_IntType> il);
5373 template<typename _InputIterator>
5374 seed_seq(_InputIterator __begin, _InputIterator __end);
5376 // generating functions
5377 template<typename _RandomAccessIterator>
5378 void
5379 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5381 // property functions
5382 size_t size() const
5383 { return _M_v.size(); }
5385 template<typename OutputIterator>
5386 void
5387 param(OutputIterator __dest) const
5388 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5390 private:
5392 std::vector<result_type> _M_v;
5395 /* @} */ // group random_utilities
5397 /* @} */ // group random
5399 _GLIBCXX_END_NAMESPACE_VERSION
5400 } // namespace std
5402 #endif