Merge from mainline (168000:168310).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / bits / random.h
blob9feb0f448c8f110a83b11f31dc70001cdfce2c2d
1 // random number generation -*- C++ -*-
3 // Copyright (C) 2009, 2010 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 _GLIBCXX_BEGIN_NAMESPACE(std)
38 // [26.4] Random number generation
40 /**
41 * @defgroup random Random Number Generation
42 * @ingroup numerics
44 * A facility for generating random numbers on selected distributions.
45 * @{
48 /**
49 * @brief A function template for converting the output of a (integral)
50 * uniform random number generator to a floatng point result in the range
51 * [0-1).
53 template<typename _RealType, size_t __bits,
54 typename _UniformRandomNumberGenerator>
55 _RealType
56 generate_canonical(_UniformRandomNumberGenerator& __g);
59 * Implementation-space details.
61 namespace __detail
63 template<typename _UIntType, size_t __w,
64 bool = __w < static_cast<size_t>
65 (std::numeric_limits<_UIntType>::digits)>
66 struct _Shift
67 { static const _UIntType __value = 0; };
69 template<typename _UIntType, size_t __w>
70 struct _Shift<_UIntType, __w, true>
71 { static const _UIntType __value = _UIntType(1) << __w; };
73 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
74 struct _Mod;
76 // Dispatch based on modulus value to prevent divide-by-zero compile-time
77 // errors when m == 0.
78 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
79 inline _Tp
80 __mod(_Tp __x)
81 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
84 * An adaptor class for converting the output of any Generator into
85 * the input for a specific Distribution.
87 template<typename _Engine, typename _DInputType>
88 struct _Adaptor
91 public:
92 _Adaptor(_Engine& __g)
93 : _M_g(__g) { }
95 _DInputType
96 min() const
97 { return _DInputType(0); }
99 _DInputType
100 max() const
101 { return _DInputType(1); }
104 * Converts a value generated by the adapted random number generator
105 * into a value in the input domain for the dependent random number
106 * distribution.
108 _DInputType
109 operator()()
111 return std::generate_canonical<_DInputType,
112 std::numeric_limits<_DInputType>::digits,
113 _Engine>(_M_g);
116 private:
117 _Engine& _M_g;
119 } // namespace __detail
122 * @addtogroup random_generators Random Number Generators
123 * @ingroup random
125 * These classes define objects which provide random or pseudorandom
126 * numbers, either from a discrete or a continuous interval. The
127 * random number generator supplied as a part of this library are
128 * all uniform random number generators which provide a sequence of
129 * random number uniformly distributed over their range.
131 * A number generator is a function object with an operator() that
132 * takes zero arguments and returns a number.
134 * A compliant random number generator must satisfy the following
135 * requirements. <table border=1 cellpadding=10 cellspacing=0>
136 * <caption align=top>Random Number Generator Requirements</caption>
137 * <tr><td>To be documented.</td></tr> </table>
139 * @{
143 * @brief A model of a linear congruential random number generator.
145 * A random number generator that produces pseudorandom numbers via
146 * linear function:
147 * @f[
148 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
149 * @f]
151 * The template parameter @p _UIntType must be an unsigned integral type
152 * large enough to store values up to (__m-1). If the template parameter
153 * @p __m is 0, the modulus @p __m used is
154 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
155 * parameters @p __a and @p __c must be less than @p __m.
157 * The size of the state is @f$1@f$.
159 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
160 class linear_congruential_engine
162 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
163 "substituting _UIntType not an unsigned integral type");
164 static_assert(__m == 0u || (__a < __m && __c < __m),
165 "template argument substituting __m out of bounds");
167 public:
168 /** The type of the generated random value. */
169 typedef _UIntType result_type;
171 /** The multiplier. */
172 static constexpr result_type multiplier = __a;
173 /** An increment. */
174 static constexpr result_type increment = __c;
175 /** The modulus. */
176 static constexpr result_type modulus = __m;
177 static constexpr result_type default_seed = 1u;
180 * @brief Constructs a %linear_congruential_engine random number
181 * generator engine with seed @p __s. The default seed value
182 * is 1.
184 * @param __s The initial seed value.
186 explicit
187 linear_congruential_engine(result_type __s = default_seed)
188 { seed(__s); }
191 * @brief Constructs a %linear_congruential_engine random number
192 * generator engine seeded from the seed sequence @p __q.
194 * @param __q the seed sequence.
196 template<typename _Sseq, typename = typename
197 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
198 ::type>
199 explicit
200 linear_congruential_engine(_Sseq& __q)
201 { seed(__q); }
204 * @brief Reseeds the %linear_congruential_engine random number generator
205 * engine sequence to the seed @p __s.
207 * @param __s The new seed.
209 void
210 seed(result_type __s = default_seed);
213 * @brief Reseeds the %linear_congruential_engine random number generator
214 * engine
215 * sequence using values from the seed sequence @p __q.
217 * @param __q the seed sequence.
219 template<typename _Sseq>
220 typename std::enable_if<std::is_class<_Sseq>::value>::type
221 seed(_Sseq& __q);
224 * @brief Gets the smallest possible value in the output range.
226 * The minimum depends on the @p __c parameter: if it is zero, the
227 * minimum generated must be > 0, otherwise 0 is allowed.
229 static constexpr result_type
230 min()
231 { return __c == 0u ? 1u : 0u; }
234 * @brief Gets the largest possible value in the output range.
236 static constexpr result_type
237 max()
238 { return __m - 1u; }
241 * @brief Discard a sequence of random numbers.
243 void
244 discard(unsigned long long __z)
246 for (; __z != 0ULL; --__z)
247 (*this)();
251 * @brief Gets the next random number in the sequence.
253 result_type
254 operator()()
256 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
257 return _M_x;
261 * @brief Compares two linear congruential random number generator
262 * objects of the same type for equality.
264 * @param __lhs A linear congruential random number generator object.
265 * @param __rhs Another linear congruential random number generator
266 * object.
268 * @returns true if the infinite sequences of generated values
269 * would be equal, false otherwise.
271 friend bool
272 operator==(const linear_congruential_engine& __lhs,
273 const linear_congruential_engine& __rhs)
274 { return __lhs._M_x == __rhs._M_x; }
277 * @brief Writes the textual representation of the state x(i) of x to
278 * @p __os.
280 * @param __os The output stream.
281 * @param __lcr A % linear_congruential_engine random number generator.
282 * @returns __os.
284 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
285 _UIntType1 __m1, typename _CharT, typename _Traits>
286 friend std::basic_ostream<_CharT, _Traits>&
287 operator<<(std::basic_ostream<_CharT, _Traits>&,
288 const std::linear_congruential_engine<_UIntType1,
289 __a1, __c1, __m1>&);
292 * @brief Sets the state of the engine by reading its textual
293 * representation from @p __is.
295 * The textual representation must have been previously written using
296 * an output stream whose imbued locale and whose type's template
297 * specialization arguments _CharT and _Traits were the same as those
298 * of @p __is.
300 * @param __is The input stream.
301 * @param __lcr A % linear_congruential_engine random number generator.
302 * @returns __is.
304 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
305 _UIntType1 __m1, typename _CharT, typename _Traits>
306 friend std::basic_istream<_CharT, _Traits>&
307 operator>>(std::basic_istream<_CharT, _Traits>&,
308 std::linear_congruential_engine<_UIntType1, __a1,
309 __c1, __m1>&);
311 private:
312 _UIntType _M_x;
316 * @brief Compares two linear congruential random number generator
317 * objects of the same type for inequality.
319 * @param __lhs A linear congruential random number generator object.
320 * @param __rhs Another linear congruential random number generator
321 * object.
323 * @returns true if the infinite sequences of generated values
324 * would be different, false otherwise.
326 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
327 inline bool
328 operator!=(const std::linear_congruential_engine<_UIntType, __a,
329 __c, __m>& __lhs,
330 const std::linear_congruential_engine<_UIntType, __a,
331 __c, __m>& __rhs)
332 { return !(__lhs == __rhs); }
336 * A generalized feedback shift register discrete random number generator.
338 * This algorithm avoids multiplication and division and is designed to be
339 * friendly to a pipelined architecture. If the parameters are chosen
340 * correctly, this generator will produce numbers with a very long period and
341 * fairly good apparent entropy, although still not cryptographically strong.
343 * The best way to use this generator is with the predefined mt19937 class.
345 * This algorithm was originally invented by Makoto Matsumoto and
346 * Takuji Nishimura.
348 * @var word_size The number of bits in each element of the state vector.
349 * @var state_size The degree of recursion.
350 * @var shift_size The period parameter.
351 * @var mask_bits The separation point bit index.
352 * @var parameter_a The last row of the twist matrix.
353 * @var output_u The first right-shift tempering matrix parameter.
354 * @var output_s The first left-shift tempering matrix parameter.
355 * @var output_b The first left-shift tempering matrix mask.
356 * @var output_t The second left-shift tempering matrix parameter.
357 * @var output_c The second left-shift tempering matrix mask.
358 * @var output_l The second right-shift tempering matrix parameter.
360 template<typename _UIntType, size_t __w,
361 size_t __n, size_t __m, size_t __r,
362 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
363 _UIntType __b, size_t __t,
364 _UIntType __c, size_t __l, _UIntType __f>
365 class mersenne_twister_engine
367 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
368 "substituting _UIntType not an unsigned integral type");
369 static_assert(1u <= __m && __m <= __n,
370 "template argument substituting __m out of bounds");
371 static_assert(__r <= __w, "template argument substituting "
372 "__r out of bound");
373 static_assert(__u <= __w, "template argument substituting "
374 "__u out of bound");
375 static_assert(__s <= __w, "template argument substituting "
376 "__s out of bound");
377 static_assert(__t <= __w, "template argument substituting "
378 "__t out of bound");
379 static_assert(__l <= __w, "template argument substituting "
380 "__l out of bound");
381 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
382 "template argument substituting __w out of bound");
383 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
384 "template argument substituting __a out of bound");
385 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
386 "template argument substituting __b out of bound");
387 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
388 "template argument substituting __c out of bound");
389 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
390 "template argument substituting __d out of bound");
391 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
392 "template argument substituting __f out of bound");
394 public:
395 /** The type of the generated random value. */
396 typedef _UIntType result_type;
398 // parameter values
399 static constexpr size_t word_size = __w;
400 static constexpr size_t state_size = __n;
401 static constexpr size_t shift_size = __m;
402 static constexpr size_t mask_bits = __r;
403 static constexpr result_type xor_mask = __a;
404 static constexpr size_t tempering_u = __u;
405 static constexpr result_type tempering_d = __d;
406 static constexpr size_t tempering_s = __s;
407 static constexpr result_type tempering_b = __b;
408 static constexpr size_t tempering_t = __t;
409 static constexpr result_type tempering_c = __c;
410 static constexpr size_t tempering_l = __l;
411 static constexpr result_type initialization_multiplier = __f;
412 static constexpr result_type default_seed = 5489u;
414 // constructors and member function
415 explicit
416 mersenne_twister_engine(result_type __sd = default_seed)
417 { seed(__sd); }
420 * @brief Constructs a %mersenne_twister_engine random number generator
421 * engine seeded from the seed sequence @p __q.
423 * @param __q the seed sequence.
425 template<typename _Sseq, typename = typename
426 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
427 ::type>
428 explicit
429 mersenne_twister_engine(_Sseq& __q)
430 { seed(__q); }
432 void
433 seed(result_type __sd = default_seed);
435 template<typename _Sseq>
436 typename std::enable_if<std::is_class<_Sseq>::value>::type
437 seed(_Sseq& __q);
440 * @brief Gets the smallest possible value in the output range.
442 static constexpr result_type
443 min()
444 { return 0; };
447 * @brief Gets the largest possible value in the output range.
449 static constexpr result_type
450 max()
451 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
454 * @brief Discard a sequence of random numbers.
456 void
457 discard(unsigned long long __z)
459 for (; __z != 0ULL; --__z)
460 (*this)();
463 result_type
464 operator()();
467 * @brief Compares two % mersenne_twister_engine random number generator
468 * objects of the same type for equality.
470 * @param __lhs A % mersenne_twister_engine random number generator
471 * object.
472 * @param __rhs Another % mersenne_twister_engine random number
473 * generator object.
475 * @returns true if the infinite sequences of generated values
476 * would be equal, false otherwise.
478 friend bool
479 operator==(const mersenne_twister_engine& __lhs,
480 const mersenne_twister_engine& __rhs)
481 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
484 * @brief Inserts the current state of a % mersenne_twister_engine
485 * random number generator engine @p __x into the output stream
486 * @p __os.
488 * @param __os An output stream.
489 * @param __x A % mersenne_twister_engine random number generator
490 * engine.
492 * @returns The output stream with the state of @p __x inserted or in
493 * an error state.
495 template<typename _UIntType1,
496 size_t __w1, size_t __n1,
497 size_t __m1, size_t __r1,
498 _UIntType1 __a1, size_t __u1,
499 _UIntType1 __d1, size_t __s1,
500 _UIntType1 __b1, size_t __t1,
501 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
502 typename _CharT, typename _Traits>
503 friend std::basic_ostream<_CharT, _Traits>&
504 operator<<(std::basic_ostream<_CharT, _Traits>&,
505 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
506 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
507 __l1, __f1>&);
510 * @brief Extracts the current state of a % mersenne_twister_engine
511 * random number generator engine @p __x from the input stream
512 * @p __is.
514 * @param __is An input stream.
515 * @param __x A % mersenne_twister_engine random number generator
516 * engine.
518 * @returns The input stream with the state of @p __x extracted or in
519 * an error state.
521 template<typename _UIntType1,
522 size_t __w1, size_t __n1,
523 size_t __m1, size_t __r1,
524 _UIntType1 __a1, size_t __u1,
525 _UIntType1 __d1, size_t __s1,
526 _UIntType1 __b1, size_t __t1,
527 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
528 typename _CharT, typename _Traits>
529 friend std::basic_istream<_CharT, _Traits>&
530 operator>>(std::basic_istream<_CharT, _Traits>&,
531 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
532 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
533 __l1, __f1>&);
535 private:
536 _UIntType _M_x[state_size];
537 size_t _M_p;
541 * @brief Compares two % mersenne_twister_engine random number generator
542 * objects of the same type for inequality.
544 * @param __lhs A % mersenne_twister_engine random number generator
545 * object.
546 * @param __rhs Another % mersenne_twister_engine random number
547 * generator object.
549 * @returns true if the infinite sequences of generated values
550 * would be different, false otherwise.
552 template<typename _UIntType, size_t __w,
553 size_t __n, size_t __m, size_t __r,
554 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
555 _UIntType __b, size_t __t,
556 _UIntType __c, size_t __l, _UIntType __f>
557 inline bool
558 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
559 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
560 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
561 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
562 { return !(__lhs == __rhs); }
566 * @brief The Marsaglia-Zaman generator.
568 * This is a model of a Generalized Fibonacci discrete random number
569 * generator, sometimes referred to as the SWC generator.
571 * A discrete random number generator that produces pseudorandom
572 * numbers using:
573 * @f[
574 * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
575 * @f]
577 * The size of the state is @f$r@f$
578 * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
580 * @var _M_x The state of the generator. This is a ring buffer.
581 * @var _M_carry The carry.
582 * @var _M_p Current index of x(i - r).
584 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
585 class subtract_with_carry_engine
587 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
588 "substituting _UIntType not an unsigned integral type");
589 static_assert(0u < __s && __s < __r,
590 "template argument substituting __s out of bounds");
591 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
592 "template argument substituting __w out of bounds");
594 public:
595 /** The type of the generated random value. */
596 typedef _UIntType result_type;
598 // parameter values
599 static constexpr size_t word_size = __w;
600 static constexpr size_t short_lag = __s;
601 static constexpr size_t long_lag = __r;
602 static constexpr result_type default_seed = 19780503u;
605 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
606 * random number generator.
608 explicit
609 subtract_with_carry_engine(result_type __sd = default_seed)
610 { seed(__sd); }
613 * @brief Constructs a %subtract_with_carry_engine random number engine
614 * seeded from the seed sequence @p __q.
616 * @param __q the seed sequence.
618 template<typename _Sseq, typename = typename
619 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
620 ::type>
621 explicit
622 subtract_with_carry_engine(_Sseq& __q)
623 { seed(__q); }
626 * @brief Seeds the initial state @f$x_0@f$ of the random number
627 * generator.
629 * N1688[4.19] modifies this as follows. If @p __value == 0,
630 * sets value to 19780503. In any case, with a linear
631 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
632 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
633 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
634 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
635 * set carry to 1, otherwise sets carry to 0.
637 void
638 seed(result_type __sd = default_seed);
641 * @brief Seeds the initial state @f$x_0@f$ of the
642 * % subtract_with_carry_engine random number generator.
644 template<typename _Sseq>
645 typename std::enable_if<std::is_class<_Sseq>::value>::type
646 seed(_Sseq& __q);
649 * @brief Gets the inclusive minimum value of the range of random
650 * integers returned by this generator.
652 static constexpr result_type
653 min()
654 { return 0; }
657 * @brief Gets the inclusive maximum value of the range of random
658 * integers returned by this generator.
660 static constexpr result_type
661 max()
662 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
665 * @brief Discard a sequence of random numbers.
667 void
668 discard(unsigned long long __z)
670 for (; __z != 0ULL; --__z)
671 (*this)();
675 * @brief Gets the next random number in the sequence.
677 result_type
678 operator()();
681 * @brief Compares two % subtract_with_carry_engine random number
682 * generator objects of the same type for equality.
684 * @param __lhs A % subtract_with_carry_engine random number generator
685 * object.
686 * @param __rhs Another % subtract_with_carry_engine random number
687 * generator object.
689 * @returns true if the infinite sequences of generated values
690 * would be equal, false otherwise.
692 friend bool
693 operator==(const subtract_with_carry_engine& __lhs,
694 const subtract_with_carry_engine& __rhs)
695 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
698 * @brief Inserts the current state of a % subtract_with_carry_engine
699 * random number generator engine @p __x into the output stream
700 * @p __os.
702 * @param __os An output stream.
703 * @param __x A % subtract_with_carry_engine random number generator
704 * engine.
706 * @returns The output stream with the state of @p __x inserted or in
707 * an error state.
709 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
710 typename _CharT, typename _Traits>
711 friend std::basic_ostream<_CharT, _Traits>&
712 operator<<(std::basic_ostream<_CharT, _Traits>&,
713 const std::subtract_with_carry_engine<_UIntType1, __w1,
714 __s1, __r1>&);
717 * @brief Extracts the current state of a % subtract_with_carry_engine
718 * random number generator engine @p __x from the input stream
719 * @p __is.
721 * @param __is An input stream.
722 * @param __x A % subtract_with_carry_engine random number generator
723 * engine.
725 * @returns The input stream with the state of @p __x extracted or in
726 * an error state.
728 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
729 typename _CharT, typename _Traits>
730 friend std::basic_istream<_CharT, _Traits>&
731 operator>>(std::basic_istream<_CharT, _Traits>&,
732 std::subtract_with_carry_engine<_UIntType1, __w1,
733 __s1, __r1>&);
735 private:
736 _UIntType _M_x[long_lag];
737 _UIntType _M_carry;
738 size_t _M_p;
742 * @brief Compares two % subtract_with_carry_engine random number
743 * generator objects of the same type for inequality.
745 * @param __lhs A % subtract_with_carry_engine random number generator
746 * object.
747 * @param __rhs Another % subtract_with_carry_engine random number
748 * generator object.
750 * @returns true if the infinite sequences of generated values
751 * would be different, false otherwise.
753 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
754 inline bool
755 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
756 __s, __r>& __lhs,
757 const std::subtract_with_carry_engine<_UIntType, __w,
758 __s, __r>& __rhs)
759 { return !(__lhs == __rhs); }
763 * Produces random numbers from some base engine by discarding blocks of
764 * data.
766 * 0 <= @p __r <= @p __p
768 template<typename _RandomNumberEngine, size_t __p, size_t __r>
769 class discard_block_engine
771 static_assert(1 <= __r && __r <= __p,
772 "template argument substituting __r out of bounds");
774 public:
775 /** The type of the generated random value. */
776 typedef typename _RandomNumberEngine::result_type result_type;
778 // parameter values
779 static constexpr size_t block_size = __p;
780 static constexpr size_t used_block = __r;
783 * @brief Constructs a default %discard_block_engine engine.
785 * The underlying engine is default constructed as well.
787 discard_block_engine()
788 : _M_b(), _M_n(0) { }
791 * @brief Copy constructs a %discard_block_engine engine.
793 * Copies an existing base class random number generator.
794 * @param rng An existing (base class) engine object.
796 explicit
797 discard_block_engine(const _RandomNumberEngine& __rne)
798 : _M_b(__rne), _M_n(0) { }
801 * @brief Move constructs a %discard_block_engine engine.
803 * Copies an existing base class random number generator.
804 * @param rng An existing (base class) engine object.
806 explicit
807 discard_block_engine(_RandomNumberEngine&& __rne)
808 : _M_b(std::move(__rne)), _M_n(0) { }
811 * @brief Seed constructs a %discard_block_engine engine.
813 * Constructs the underlying generator engine seeded with @p __s.
814 * @param __s A seed value for the base class engine.
816 explicit
817 discard_block_engine(result_type __s)
818 : _M_b(__s), _M_n(0) { }
821 * @brief Generator construct a %discard_block_engine engine.
823 * @param __q A seed sequence.
825 template<typename _Sseq, typename = typename
826 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
827 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
828 ::type>
829 explicit
830 discard_block_engine(_Sseq& __q)
831 : _M_b(__q), _M_n(0)
835 * @brief Reseeds the %discard_block_engine object with the default
836 * seed for the underlying base class generator engine.
838 void
839 seed()
841 _M_b.seed();
842 _M_n = 0;
846 * @brief Reseeds the %discard_block_engine object with the default
847 * seed for the underlying base class generator engine.
849 void
850 seed(result_type __s)
852 _M_b.seed(__s);
853 _M_n = 0;
857 * @brief Reseeds the %discard_block_engine object with the given seed
858 * sequence.
859 * @param __q A seed generator function.
861 template<typename _Sseq>
862 void
863 seed(_Sseq& __q)
865 _M_b.seed(__q);
866 _M_n = 0;
870 * @brief Gets a const reference to the underlying generator engine
871 * object.
873 const _RandomNumberEngine&
874 base() const
875 { return _M_b; }
878 * @brief Gets the minimum value in the generated random number range.
880 static constexpr result_type
881 min()
882 { return _RandomNumberEngine::min(); }
885 * @brief Gets the maximum value in the generated random number range.
887 static constexpr result_type
888 max()
889 { return _RandomNumberEngine::max(); }
892 * @brief Discard a sequence of random numbers.
894 void
895 discard(unsigned long long __z)
897 for (; __z != 0ULL; --__z)
898 (*this)();
902 * @brief Gets the next value in the generated random number sequence.
904 result_type
905 operator()();
908 * @brief Compares two %discard_block_engine random number generator
909 * objects of the same type for equality.
911 * @param __lhs A %discard_block_engine random number generator object.
912 * @param __rhs Another %discard_block_engine random number generator
913 * object.
915 * @returns true if the infinite sequences of generated values
916 * would be equal, false otherwise.
918 friend bool
919 operator==(const discard_block_engine& __lhs,
920 const discard_block_engine& __rhs)
921 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
924 * @brief Inserts the current state of a %discard_block_engine random
925 * number generator engine @p __x into the output stream
926 * @p __os.
928 * @param __os An output stream.
929 * @param __x A %discard_block_engine random number generator engine.
931 * @returns The output stream with the state of @p __x inserted or in
932 * an error state.
934 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
935 typename _CharT, typename _Traits>
936 friend std::basic_ostream<_CharT, _Traits>&
937 operator<<(std::basic_ostream<_CharT, _Traits>&,
938 const std::discard_block_engine<_RandomNumberEngine1,
939 __p1, __r1>&);
942 * @brief Extracts the current state of a % subtract_with_carry_engine
943 * random number generator engine @p __x from the input stream
944 * @p __is.
946 * @param __is An input stream.
947 * @param __x A %discard_block_engine random number generator engine.
949 * @returns The input stream with the state of @p __x extracted or in
950 * an error state.
952 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
953 typename _CharT, typename _Traits>
954 friend std::basic_istream<_CharT, _Traits>&
955 operator>>(std::basic_istream<_CharT, _Traits>&,
956 std::discard_block_engine<_RandomNumberEngine1,
957 __p1, __r1>&);
959 private:
960 _RandomNumberEngine _M_b;
961 size_t _M_n;
965 * @brief Compares two %discard_block_engine random number generator
966 * objects of the same type for inequality.
968 * @param __lhs A %discard_block_engine random number generator object.
969 * @param __rhs Another %discard_block_engine random number generator
970 * object.
972 * @returns true if the infinite sequences of generated values
973 * would be different, false otherwise.
975 template<typename _RandomNumberEngine, size_t __p, size_t __r>
976 inline bool
977 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
978 __r>& __lhs,
979 const std::discard_block_engine<_RandomNumberEngine, __p,
980 __r>& __rhs)
981 { return !(__lhs == __rhs); }
985 * Produces random numbers by combining random numbers from some base
986 * engine to produce random numbers with a specifies number of bits @p __w.
988 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
989 class independent_bits_engine
991 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
992 "substituting _UIntType not an unsigned integral type");
993 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
994 "template argument substituting __w out of bounds");
996 public:
997 /** The type of the generated random value. */
998 typedef _UIntType result_type;
1001 * @brief Constructs a default %independent_bits_engine engine.
1003 * The underlying engine is default constructed as well.
1005 independent_bits_engine()
1006 : _M_b() { }
1009 * @brief Copy constructs a %independent_bits_engine engine.
1011 * Copies an existing base class random number generator.
1012 * @param rng An existing (base class) engine object.
1014 explicit
1015 independent_bits_engine(const _RandomNumberEngine& __rne)
1016 : _M_b(__rne) { }
1019 * @brief Move constructs a %independent_bits_engine engine.
1021 * Copies an existing base class random number generator.
1022 * @param rng An existing (base class) engine object.
1024 explicit
1025 independent_bits_engine(_RandomNumberEngine&& __rne)
1026 : _M_b(std::move(__rne)) { }
1029 * @brief Seed constructs a %independent_bits_engine engine.
1031 * Constructs the underlying generator engine seeded with @p __s.
1032 * @param __s A seed value for the base class engine.
1034 explicit
1035 independent_bits_engine(result_type __s)
1036 : _M_b(__s) { }
1039 * @brief Generator construct a %independent_bits_engine engine.
1041 * @param __q A seed sequence.
1043 template<typename _Sseq, typename = typename
1044 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
1045 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1046 ::type>
1047 explicit
1048 independent_bits_engine(_Sseq& __q)
1049 : _M_b(__q)
1053 * @brief Reseeds the %independent_bits_engine object with the default
1054 * seed for the underlying base class generator engine.
1056 void
1057 seed()
1058 { _M_b.seed(); }
1061 * @brief Reseeds the %independent_bits_engine object with the default
1062 * seed for the underlying base class generator engine.
1064 void
1065 seed(result_type __s)
1066 { _M_b.seed(__s); }
1069 * @brief Reseeds the %independent_bits_engine object with the given
1070 * seed sequence.
1071 * @param __q A seed generator function.
1073 template<typename _Sseq>
1074 void
1075 seed(_Sseq& __q)
1076 { _M_b.seed(__q); }
1079 * @brief Gets a const reference to the underlying generator engine
1080 * object.
1082 const _RandomNumberEngine&
1083 base() const
1084 { return _M_b; }
1087 * @brief Gets the minimum value in the generated random number range.
1089 static constexpr result_type
1090 min()
1091 { return 0U; }
1094 * @brief Gets the maximum value in the generated random number range.
1096 static constexpr result_type
1097 max()
1098 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1101 * @brief Discard a sequence of random numbers.
1103 void
1104 discard(unsigned long long __z)
1106 for (; __z != 0ULL; --__z)
1107 (*this)();
1111 * @brief Gets the next value in the generated random number sequence.
1113 result_type
1114 operator()();
1117 * @brief Compares two %independent_bits_engine random number generator
1118 * objects of the same type for equality.
1120 * @param __lhs A %independent_bits_engine random number generator
1121 * object.
1122 * @param __rhs Another %independent_bits_engine random number generator
1123 * object.
1125 * @returns true if the infinite sequences of generated values
1126 * would be equal, false otherwise.
1128 friend bool
1129 operator==(const independent_bits_engine& __lhs,
1130 const independent_bits_engine& __rhs)
1131 { return __lhs._M_b == __rhs._M_b; }
1134 * @brief Extracts the current state of a % subtract_with_carry_engine
1135 * random number generator engine @p __x from the input stream
1136 * @p __is.
1138 * @param __is An input stream.
1139 * @param __x A %independent_bits_engine random number generator
1140 * engine.
1142 * @returns The input stream with the state of @p __x extracted or in
1143 * an error state.
1145 template<typename _CharT, typename _Traits>
1146 friend std::basic_istream<_CharT, _Traits>&
1147 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1148 std::independent_bits_engine<_RandomNumberEngine,
1149 __w, _UIntType>& __x)
1151 __is >> __x._M_b;
1152 return __is;
1155 private:
1156 _RandomNumberEngine _M_b;
1160 * @brief Compares two %independent_bits_engine random number generator
1161 * objects of the same type for inequality.
1163 * @param __lhs A %independent_bits_engine random number generator
1164 * object.
1165 * @param __rhs Another %independent_bits_engine random number generator
1166 * object.
1168 * @returns true if the infinite sequences of generated values
1169 * would be different, false otherwise.
1171 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1172 inline bool
1173 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1174 _UIntType>& __lhs,
1175 const std::independent_bits_engine<_RandomNumberEngine, __w,
1176 _UIntType>& __rhs)
1177 { return !(__lhs == __rhs); }
1180 * @brief Inserts the current state of a %independent_bits_engine random
1181 * number generator engine @p __x into the output stream @p __os.
1183 * @param __os An output stream.
1184 * @param __x A %independent_bits_engine random number generator engine.
1186 * @returns The output stream with the state of @p __x inserted or in
1187 * an error state.
1189 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1190 typename _CharT, typename _Traits>
1191 std::basic_ostream<_CharT, _Traits>&
1192 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1193 const std::independent_bits_engine<_RandomNumberEngine,
1194 __w, _UIntType>& __x)
1196 __os << __x.base();
1197 return __os;
1202 * @brief Produces random numbers by combining random numbers from some
1203 * base engine to produce random numbers with a specifies number of bits
1204 * @p __w.
1206 template<typename _RandomNumberEngine, size_t __k>
1207 class shuffle_order_engine
1209 static_assert(1u <= __k, "template argument substituting "
1210 "__k out of bound");
1212 public:
1213 /** The type of the generated random value. */
1214 typedef typename _RandomNumberEngine::result_type result_type;
1216 static constexpr size_t table_size = __k;
1219 * @brief Constructs a default %shuffle_order_engine engine.
1221 * The underlying engine is default constructed as well.
1223 shuffle_order_engine()
1224 : _M_b()
1225 { _M_initialize(); }
1228 * @brief Copy constructs a %shuffle_order_engine engine.
1230 * Copies an existing base class random number generator.
1231 * @param rng An existing (base class) engine object.
1233 explicit
1234 shuffle_order_engine(const _RandomNumberEngine& __rne)
1235 : _M_b(__rne)
1236 { _M_initialize(); }
1239 * @brief Move constructs a %shuffle_order_engine engine.
1241 * Copies an existing base class random number generator.
1242 * @param rng An existing (base class) engine object.
1244 explicit
1245 shuffle_order_engine(_RandomNumberEngine&& __rne)
1246 : _M_b(std::move(__rne))
1247 { _M_initialize(); }
1250 * @brief Seed constructs a %shuffle_order_engine engine.
1252 * Constructs the underlying generator engine seeded with @p __s.
1253 * @param __s A seed value for the base class engine.
1255 explicit
1256 shuffle_order_engine(result_type __s)
1257 : _M_b(__s)
1258 { _M_initialize(); }
1261 * @brief Generator construct a %shuffle_order_engine engine.
1263 * @param __q A seed sequence.
1265 template<typename _Sseq, typename = typename
1266 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
1267 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
1268 ::type>
1269 explicit
1270 shuffle_order_engine(_Sseq& __q)
1271 : _M_b(__q)
1272 { _M_initialize(); }
1275 * @brief Reseeds the %shuffle_order_engine object with the default seed
1276 for the underlying base class generator engine.
1278 void
1279 seed()
1281 _M_b.seed();
1282 _M_initialize();
1286 * @brief Reseeds the %shuffle_order_engine object with the default seed
1287 * for the underlying base class generator engine.
1289 void
1290 seed(result_type __s)
1292 _M_b.seed(__s);
1293 _M_initialize();
1297 * @brief Reseeds the %shuffle_order_engine object with the given seed
1298 * sequence.
1299 * @param __q A seed generator function.
1301 template<typename _Sseq>
1302 void
1303 seed(_Sseq& __q)
1305 _M_b.seed(__q);
1306 _M_initialize();
1310 * Gets a const reference to the underlying generator engine object.
1312 const _RandomNumberEngine&
1313 base() const
1314 { return _M_b; }
1317 * Gets the minimum value in the generated random number range.
1319 static constexpr result_type
1320 min()
1321 { return _RandomNumberEngine::min(); }
1324 * Gets the maximum value in the generated random number range.
1326 static constexpr result_type
1327 max()
1328 { return _RandomNumberEngine::max(); }
1331 * Discard a sequence of random numbers.
1333 void
1334 discard(unsigned long long __z)
1336 for (; __z != 0ULL; --__z)
1337 (*this)();
1341 * Gets the next value in the generated random number sequence.
1343 result_type
1344 operator()();
1347 * Compares two %shuffle_order_engine random number generator objects
1348 * of the same type for equality.
1350 * @param __lhs A %shuffle_order_engine random number generator object.
1351 * @param __rhs Another %shuffle_order_engine random number generator
1352 * object.
1354 * @returns true if the infinite sequences of generated values
1355 * would be equal, false otherwise.
1357 friend bool
1358 operator==(const shuffle_order_engine& __lhs,
1359 const shuffle_order_engine& __rhs)
1360 { return __lhs._M_b == __rhs._M_b; }
1363 * @brief Inserts the current state of a %shuffle_order_engine random
1364 * number generator engine @p __x into the output stream
1365 @p __os.
1367 * @param __os An output stream.
1368 * @param __x A %shuffle_order_engine random number generator engine.
1370 * @returns The output stream with the state of @p __x inserted or in
1371 * an error state.
1373 template<typename _RandomNumberEngine1, size_t __k1,
1374 typename _CharT, typename _Traits>
1375 friend std::basic_ostream<_CharT, _Traits>&
1376 operator<<(std::basic_ostream<_CharT, _Traits>&,
1377 const std::shuffle_order_engine<_RandomNumberEngine1,
1378 __k1>&);
1381 * @brief Extracts the current state of a % subtract_with_carry_engine
1382 * random number generator engine @p __x from the input stream
1383 * @p __is.
1385 * @param __is An input stream.
1386 * @param __x A %shuffle_order_engine random number generator engine.
1388 * @returns The input stream with the state of @p __x extracted or in
1389 * an error state.
1391 template<typename _RandomNumberEngine1, size_t __k1,
1392 typename _CharT, typename _Traits>
1393 friend std::basic_istream<_CharT, _Traits>&
1394 operator>>(std::basic_istream<_CharT, _Traits>&,
1395 std::shuffle_order_engine<_RandomNumberEngine1, __k1>&);
1397 private:
1398 void _M_initialize()
1400 for (size_t __i = 0; __i < __k; ++__i)
1401 _M_v[__i] = _M_b();
1402 _M_y = _M_b();
1405 _RandomNumberEngine _M_b;
1406 result_type _M_v[__k];
1407 result_type _M_y;
1411 * Compares two %shuffle_order_engine random number generator objects
1412 * of the same type for inequality.
1414 * @param __lhs A %shuffle_order_engine random number generator object.
1415 * @param __rhs Another %shuffle_order_engine random number generator
1416 * object.
1418 * @returns true if the infinite sequences of generated values
1419 * would be different, false otherwise.
1421 template<typename _RandomNumberEngine, size_t __k>
1422 inline bool
1423 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1424 __k>& __lhs,
1425 const std::shuffle_order_engine<_RandomNumberEngine,
1426 __k>& __rhs)
1427 { return !(__lhs == __rhs); }
1431 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1433 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1434 minstd_rand0;
1437 * An alternative LCR (Lehmer Generator function).
1439 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1440 minstd_rand;
1443 * The classic Mersenne Twister.
1445 * Reference:
1446 * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1447 * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1448 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1450 typedef mersenne_twister_engine<
1451 uint_fast32_t,
1452 32, 624, 397, 31,
1453 0x9908b0dfUL, 11,
1454 0xffffffffUL, 7,
1455 0x9d2c5680UL, 15,
1456 0xefc60000UL, 18, 1812433253UL> mt19937;
1459 * An alternative Mersenne Twister.
1461 typedef mersenne_twister_engine<
1462 uint_fast64_t,
1463 64, 312, 156, 31,
1464 0xb5026f5aa96619e9ULL, 29,
1465 0x5555555555555555ULL, 17,
1466 0x71d67fffeda60000ULL, 37,
1467 0xfff7eee000000000ULL, 43,
1468 6364136223846793005ULL> mt19937_64;
1470 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1471 ranlux24_base;
1473 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1474 ranlux48_base;
1476 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1478 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1480 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1482 typedef minstd_rand0 default_random_engine;
1485 * A standard interface to a platform-specific non-deterministic
1486 * random number generator (if any are available).
1488 class random_device
1490 public:
1491 /** The type of the generated random value. */
1492 typedef unsigned int result_type;
1494 // constructors, destructors and member functions
1496 #ifdef _GLIBCXX_USE_RANDOM_TR1
1498 explicit
1499 random_device(const std::string& __token = "/dev/urandom")
1501 if ((__token != "/dev/urandom" && __token != "/dev/random")
1502 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1503 std::__throw_runtime_error(__N("random_device::"
1504 "random_device(const std::string&)"));
1507 ~random_device()
1508 { std::fclose(_M_file); }
1510 #else
1512 explicit
1513 random_device(const std::string& __token = "mt19937")
1514 : _M_mt(_M_strtoul(__token)) { }
1516 private:
1517 static unsigned long
1518 _M_strtoul(const std::string& __str)
1520 unsigned long __ret = 5489UL;
1521 if (__str != "mt19937")
1523 const char* __nptr = __str.c_str();
1524 char* __endptr;
1525 __ret = std::strtoul(__nptr, &__endptr, 0);
1526 if (*__nptr == '\0' || *__endptr != '\0')
1527 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1528 "(const std::string&)"));
1530 return __ret;
1533 public:
1535 #endif
1537 result_type
1538 min() const
1539 { return std::numeric_limits<result_type>::min(); }
1541 result_type
1542 max() const
1543 { return std::numeric_limits<result_type>::max(); }
1545 double
1546 entropy() const
1547 { return 0.0; }
1549 result_type
1550 operator()()
1552 #ifdef _GLIBCXX_USE_RANDOM_TR1
1553 result_type __ret;
1554 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1555 1, _M_file);
1556 return __ret;
1557 #else
1558 return _M_mt();
1559 #endif
1562 // No copy functions.
1563 random_device(const random_device&) = delete;
1564 void operator=(const random_device&) = delete;
1566 private:
1568 #ifdef _GLIBCXX_USE_RANDOM_TR1
1569 FILE* _M_file;
1570 #else
1571 mt19937 _M_mt;
1572 #endif
1575 /* @} */ // group random_generators
1578 * @addtogroup random_distributions Random Number Distributions
1579 * @ingroup random
1580 * @{
1584 * @addtogroup random_distributions_uniform Uniform Distributions
1585 * @ingroup random_distributions
1586 * @{
1590 * @brief Uniform discrete distribution for random numbers.
1591 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1592 * probability throughout the range.
1594 template<typename _IntType = int>
1595 class uniform_int_distribution
1597 static_assert(std::is_integral<_IntType>::value,
1598 "template argument not an integral type");
1600 public:
1601 /** The type of the range of the distribution. */
1602 typedef _IntType result_type;
1603 /** Parameter type. */
1604 struct param_type
1606 typedef uniform_int_distribution<_IntType> distribution_type;
1608 explicit
1609 param_type(_IntType __a = 0,
1610 _IntType __b = std::numeric_limits<_IntType>::max())
1611 : _M_a(__a), _M_b(__b)
1613 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1616 result_type
1617 a() const
1618 { return _M_a; }
1620 result_type
1621 b() const
1622 { return _M_b; }
1624 friend bool
1625 operator==(const param_type& __p1, const param_type& __p2)
1626 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1628 private:
1629 _IntType _M_a;
1630 _IntType _M_b;
1633 public:
1635 * @brief Constructs a uniform distribution object.
1637 explicit
1638 uniform_int_distribution(_IntType __a = 0,
1639 _IntType __b = std::numeric_limits<_IntType>::max())
1640 : _M_param(__a, __b)
1643 explicit
1644 uniform_int_distribution(const param_type& __p)
1645 : _M_param(__p)
1649 * @brief Resets the distribution state.
1651 * Does nothing for the uniform integer distribution.
1653 void
1654 reset() { }
1656 result_type
1657 a() const
1658 { return _M_param.a(); }
1660 result_type
1661 b() const
1662 { return _M_param.b(); }
1665 * @brief Returns the parameter set of the distribution.
1667 param_type
1668 param() const
1669 { return _M_param; }
1672 * @brief Sets the parameter set of the distribution.
1673 * @param __param The new parameter set of the distribution.
1675 void
1676 param(const param_type& __param)
1677 { _M_param = __param; }
1680 * @brief Returns the inclusive lower bound of the distribution range.
1682 result_type
1683 min() const
1684 { return this->a(); }
1687 * @brief Returns the inclusive upper bound of the distribution range.
1689 result_type
1690 max() const
1691 { return this->b(); }
1694 * @brief Generating functions.
1696 template<typename _UniformRandomNumberGenerator>
1697 result_type
1698 operator()(_UniformRandomNumberGenerator& __urng)
1699 { return this->operator()(__urng, this->param()); }
1701 template<typename _UniformRandomNumberGenerator>
1702 result_type
1703 operator()(_UniformRandomNumberGenerator& __urng,
1704 const param_type& __p);
1706 param_type _M_param;
1710 * @brief Return true if two uniform integer distributions have
1711 * the same parameters.
1713 template<typename _IntType>
1714 inline bool
1715 operator==(const std::uniform_int_distribution<_IntType>& __d1,
1716 const std::uniform_int_distribution<_IntType>& __d2)
1717 { return __d1.param() == __d2.param(); }
1720 * @brief Return true if two uniform integer distributions have
1721 * different parameters.
1723 template<typename _IntType>
1724 inline bool
1725 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
1726 const std::uniform_int_distribution<_IntType>& __d2)
1727 { return !(__d1 == __d2); }
1730 * @brief Inserts a %uniform_int_distribution random number
1731 * distribution @p __x into the output stream @p os.
1733 * @param __os An output stream.
1734 * @param __x A %uniform_int_distribution random number distribution.
1736 * @returns The output stream with the state of @p __x inserted or in
1737 * an error state.
1739 template<typename _IntType, typename _CharT, typename _Traits>
1740 std::basic_ostream<_CharT, _Traits>&
1741 operator<<(std::basic_ostream<_CharT, _Traits>&,
1742 const std::uniform_int_distribution<_IntType>&);
1745 * @brief Extracts a %uniform_int_distribution random number distribution
1746 * @p __x from the input stream @p __is.
1748 * @param __is An input stream.
1749 * @param __x A %uniform_int_distribution random number generator engine.
1751 * @returns The input stream with @p __x extracted or in an error state.
1753 template<typename _IntType, typename _CharT, typename _Traits>
1754 std::basic_istream<_CharT, _Traits>&
1755 operator>>(std::basic_istream<_CharT, _Traits>&,
1756 std::uniform_int_distribution<_IntType>&);
1760 * @brief Uniform continuous distribution for random numbers.
1762 * A continuous random distribution on the range [min, max) with equal
1763 * probability throughout the range. The URNG should be real-valued and
1764 * deliver number in the range [0, 1).
1766 template<typename _RealType = double>
1767 class uniform_real_distribution
1769 static_assert(std::is_floating_point<_RealType>::value,
1770 "template argument not a floating point type");
1772 public:
1773 /** The type of the range of the distribution. */
1774 typedef _RealType result_type;
1775 /** Parameter type. */
1776 struct param_type
1778 typedef uniform_real_distribution<_RealType> distribution_type;
1780 explicit
1781 param_type(_RealType __a = _RealType(0),
1782 _RealType __b = _RealType(1))
1783 : _M_a(__a), _M_b(__b)
1785 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1788 result_type
1789 a() const
1790 { return _M_a; }
1792 result_type
1793 b() const
1794 { return _M_b; }
1796 friend bool
1797 operator==(const param_type& __p1, const param_type& __p2)
1798 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1800 private:
1801 _RealType _M_a;
1802 _RealType _M_b;
1805 public:
1807 * @brief Constructs a uniform_real_distribution object.
1809 * @param __min [IN] The lower bound of the distribution.
1810 * @param __max [IN] The upper bound of the distribution.
1812 explicit
1813 uniform_real_distribution(_RealType __a = _RealType(0),
1814 _RealType __b = _RealType(1))
1815 : _M_param(__a, __b)
1818 explicit
1819 uniform_real_distribution(const param_type& __p)
1820 : _M_param(__p)
1824 * @brief Resets the distribution state.
1826 * Does nothing for the uniform real distribution.
1828 void
1829 reset() { }
1831 result_type
1832 a() const
1833 { return _M_param.a(); }
1835 result_type
1836 b() const
1837 { return _M_param.b(); }
1840 * @brief Returns the parameter set of the distribution.
1842 param_type
1843 param() const
1844 { return _M_param; }
1847 * @brief Sets the parameter set of the distribution.
1848 * @param __param The new parameter set of the distribution.
1850 void
1851 param(const param_type& __param)
1852 { _M_param = __param; }
1855 * @brief Returns the inclusive lower bound of the distribution range.
1857 result_type
1858 min() const
1859 { return this->a(); }
1862 * @brief Returns the inclusive upper bound of the distribution range.
1864 result_type
1865 max() const
1866 { return this->b(); }
1869 * @brief Generating functions.
1871 template<typename _UniformRandomNumberGenerator>
1872 result_type
1873 operator()(_UniformRandomNumberGenerator& __urng)
1874 { return this->operator()(__urng, this->param()); }
1876 template<typename _UniformRandomNumberGenerator>
1877 result_type
1878 operator()(_UniformRandomNumberGenerator& __urng,
1879 const param_type& __p)
1881 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1882 __aurng(__urng);
1883 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1886 private:
1887 param_type _M_param;
1891 * @brief Return true if two uniform real distributions have
1892 * the same parameters.
1894 template<typename _IntType>
1895 inline bool
1896 operator==(const std::uniform_real_distribution<_IntType>& __d1,
1897 const std::uniform_real_distribution<_IntType>& __d2)
1898 { return __d1.param() == __d2.param(); }
1901 * @brief Return true if two uniform real distributions have
1902 * different parameters.
1904 template<typename _IntType>
1905 inline bool
1906 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
1907 const std::uniform_real_distribution<_IntType>& __d2)
1908 { return !(__d1 == __d2); }
1911 * @brief Inserts a %uniform_real_distribution random number
1912 * distribution @p __x into the output stream @p __os.
1914 * @param __os An output stream.
1915 * @param __x A %uniform_real_distribution random number distribution.
1917 * @returns The output stream with the state of @p __x inserted or in
1918 * an error state.
1920 template<typename _RealType, typename _CharT, typename _Traits>
1921 std::basic_ostream<_CharT, _Traits>&
1922 operator<<(std::basic_ostream<_CharT, _Traits>&,
1923 const std::uniform_real_distribution<_RealType>&);
1926 * @brief Extracts a %uniform_real_distribution random number distribution
1927 * @p __x from the input stream @p __is.
1929 * @param __is An input stream.
1930 * @param __x A %uniform_real_distribution random number generator engine.
1932 * @returns The input stream with @p __x extracted or in an error state.
1934 template<typename _RealType, typename _CharT, typename _Traits>
1935 std::basic_istream<_CharT, _Traits>&
1936 operator>>(std::basic_istream<_CharT, _Traits>&,
1937 std::uniform_real_distribution<_RealType>&);
1939 /* @} */ // group random_distributions_uniform
1942 * @addtogroup random_distributions_normal Normal Distributions
1943 * @ingroup random_distributions
1944 * @{
1948 * @brief A normal continuous distribution for random numbers.
1950 * The formula for the normal probability density function is
1951 * @f[
1952 * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1953 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1954 * @f]
1956 template<typename _RealType = double>
1957 class normal_distribution
1959 static_assert(std::is_floating_point<_RealType>::value,
1960 "template argument not a floating point type");
1962 public:
1963 /** The type of the range of the distribution. */
1964 typedef _RealType result_type;
1965 /** Parameter type. */
1966 struct param_type
1968 typedef normal_distribution<_RealType> distribution_type;
1970 explicit
1971 param_type(_RealType __mean = _RealType(0),
1972 _RealType __stddev = _RealType(1))
1973 : _M_mean(__mean), _M_stddev(__stddev)
1975 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1978 _RealType
1979 mean() const
1980 { return _M_mean; }
1982 _RealType
1983 stddev() const
1984 { return _M_stddev; }
1986 friend bool
1987 operator==(const param_type& __p1, const param_type& __p2)
1988 { return (__p1._M_mean == __p2._M_mean
1989 && __p1._M_stddev == __p2._M_stddev); }
1991 private:
1992 _RealType _M_mean;
1993 _RealType _M_stddev;
1996 public:
1998 * Constructs a normal distribution with parameters @f$mean@f$ and
1999 * standard deviation.
2001 explicit
2002 normal_distribution(result_type __mean = result_type(0),
2003 result_type __stddev = result_type(1))
2004 : _M_param(__mean, __stddev), _M_saved_available(false)
2007 explicit
2008 normal_distribution(const param_type& __p)
2009 : _M_param(__p), _M_saved_available(false)
2013 * @brief Resets the distribution state.
2015 void
2016 reset()
2017 { _M_saved_available = false; }
2020 * @brief Returns the mean of the distribution.
2022 _RealType
2023 mean() const
2024 { return _M_param.mean(); }
2027 * @brief Returns the standard deviation of the distribution.
2029 _RealType
2030 stddev() const
2031 { return _M_param.stddev(); }
2034 * @brief Returns the parameter set of the distribution.
2036 param_type
2037 param() const
2038 { return _M_param; }
2041 * @brief Sets the parameter set of the distribution.
2042 * @param __param The new parameter set of the distribution.
2044 void
2045 param(const param_type& __param)
2046 { _M_param = __param; }
2049 * @brief Returns the greatest lower bound value of the distribution.
2051 result_type
2052 min() const
2053 { return std::numeric_limits<result_type>::min(); }
2056 * @brief Returns the least upper bound value of the distribution.
2058 result_type
2059 max() const
2060 { return std::numeric_limits<result_type>::max(); }
2063 * @brief Generating functions.
2065 template<typename _UniformRandomNumberGenerator>
2066 result_type
2067 operator()(_UniformRandomNumberGenerator& __urng)
2068 { return this->operator()(__urng, this->param()); }
2070 template<typename _UniformRandomNumberGenerator>
2071 result_type
2072 operator()(_UniformRandomNumberGenerator& __urng,
2073 const param_type& __p);
2076 * @brief Return true if two normal distributions have
2077 * the same parameters and the sequences that would
2078 * be generated are equal.
2080 template<typename _RealType1>
2081 friend bool
2082 operator==(const std::normal_distribution<_RealType1>& __d1,
2083 const std::normal_distribution<_RealType1>& __d2);
2086 * @brief Inserts a %normal_distribution random number distribution
2087 * @p __x into the output stream @p __os.
2089 * @param __os An output stream.
2090 * @param __x A %normal_distribution random number distribution.
2092 * @returns The output stream with the state of @p __x inserted or in
2093 * an error state.
2095 template<typename _RealType1, typename _CharT, typename _Traits>
2096 friend std::basic_ostream<_CharT, _Traits>&
2097 operator<<(std::basic_ostream<_CharT, _Traits>&,
2098 const std::normal_distribution<_RealType1>&);
2101 * @brief Extracts a %normal_distribution random number distribution
2102 * @p __x from the input stream @p __is.
2104 * @param __is An input stream.
2105 * @param __x A %normal_distribution random number generator engine.
2107 * @returns The input stream with @p __x extracted or in an error
2108 * state.
2110 template<typename _RealType1, typename _CharT, typename _Traits>
2111 friend std::basic_istream<_CharT, _Traits>&
2112 operator>>(std::basic_istream<_CharT, _Traits>&,
2113 std::normal_distribution<_RealType1>&);
2115 private:
2116 param_type _M_param;
2117 result_type _M_saved;
2118 bool _M_saved_available;
2122 * @brief Return true if two normal distributions are different.
2124 template<typename _RealType>
2125 inline bool
2126 operator!=(const std::normal_distribution<_RealType>& __d1,
2127 const std::normal_distribution<_RealType>& __d2)
2128 { return !(__d1 == __d2); }
2132 * @brief A lognormal_distribution random number distribution.
2134 * The formula for the normal probability mass function is
2135 * @f[
2136 * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2137 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2138 * @f]
2140 template<typename _RealType = double>
2141 class lognormal_distribution
2143 static_assert(std::is_floating_point<_RealType>::value,
2144 "template argument not a floating point type");
2146 public:
2147 /** The type of the range of the distribution. */
2148 typedef _RealType result_type;
2149 /** Parameter type. */
2150 struct param_type
2152 typedef lognormal_distribution<_RealType> distribution_type;
2154 explicit
2155 param_type(_RealType __m = _RealType(0),
2156 _RealType __s = _RealType(1))
2157 : _M_m(__m), _M_s(__s)
2160 _RealType
2161 m() const
2162 { return _M_m; }
2164 _RealType
2165 s() const
2166 { return _M_s; }
2168 friend bool
2169 operator==(const param_type& __p1, const param_type& __p2)
2170 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2172 private:
2173 _RealType _M_m;
2174 _RealType _M_s;
2177 explicit
2178 lognormal_distribution(_RealType __m = _RealType(0),
2179 _RealType __s = _RealType(1))
2180 : _M_param(__m, __s), _M_nd()
2183 explicit
2184 lognormal_distribution(const param_type& __p)
2185 : _M_param(__p), _M_nd()
2189 * Resets the distribution state.
2191 void
2192 reset()
2193 { _M_nd.reset(); }
2198 _RealType
2199 m() const
2200 { return _M_param.m(); }
2202 _RealType
2203 s() const
2204 { return _M_param.s(); }
2207 * @brief Returns the parameter set of the distribution.
2209 param_type
2210 param() const
2211 { return _M_param; }
2214 * @brief Sets the parameter set of the distribution.
2215 * @param __param The new parameter set of the distribution.
2217 void
2218 param(const param_type& __param)
2219 { _M_param = __param; }
2222 * @brief Returns the greatest lower bound value of the distribution.
2224 result_type
2225 min() const
2226 { return result_type(0); }
2229 * @brief Returns the least upper bound value of the distribution.
2231 result_type
2232 max() const
2233 { return std::numeric_limits<result_type>::max(); }
2236 * @brief Generating functions.
2238 template<typename _UniformRandomNumberGenerator>
2239 result_type
2240 operator()(_UniformRandomNumberGenerator& __urng)
2241 { return this->operator()(__urng, this->param()); }
2243 template<typename _UniformRandomNumberGenerator>
2244 result_type
2245 operator()(_UniformRandomNumberGenerator& __urng,
2246 const param_type& __p)
2247 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2250 * @brief Return true if two lognormal distributions have
2251 * the same parameters and the sequences that would
2252 * be generated are equal.
2254 template<typename _RealType1>
2255 friend bool
2256 operator==(const std::lognormal_distribution<_RealType1>& __d1,
2257 const std::lognormal_distribution<_RealType1>& __d2)
2258 { return (__d1.param() == __d2.param()
2259 && __d1._M_nd == __d2._M_nd); }
2262 * @brief Inserts a %lognormal_distribution random number distribution
2263 * @p __x into the output stream @p __os.
2265 * @param __os An output stream.
2266 * @param __x A %lognormal_distribution random number distribution.
2268 * @returns The output stream with the state of @p __x inserted or in
2269 * an error state.
2271 template<typename _RealType1, typename _CharT, typename _Traits>
2272 friend std::basic_ostream<_CharT, _Traits>&
2273 operator<<(std::basic_ostream<_CharT, _Traits>&,
2274 const std::lognormal_distribution<_RealType1>&);
2277 * @brief Extracts a %lognormal_distribution random number distribution
2278 * @p __x from the input stream @p __is.
2280 * @param __is An input stream.
2281 * @param __x A %lognormal_distribution random number
2282 * generator engine.
2284 * @returns The input stream with @p __x extracted or in an error state.
2286 template<typename _RealType1, typename _CharT, typename _Traits>
2287 friend std::basic_istream<_CharT, _Traits>&
2288 operator>>(std::basic_istream<_CharT, _Traits>&,
2289 std::lognormal_distribution<_RealType1>&);
2291 private:
2292 param_type _M_param;
2294 std::normal_distribution<result_type> _M_nd;
2298 * @brief Return true if two lognormal distributions are different.
2300 template<typename _RealType>
2301 inline bool
2302 operator!=(const std::lognormal_distribution<_RealType>& __d1,
2303 const std::lognormal_distribution<_RealType>& __d2)
2304 { return !(__d1 == __d2); }
2308 * @brief A gamma continuous distribution for random numbers.
2310 * The formula for the gamma probability density function is:
2311 * @f[
2312 * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2313 * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2314 * @f]
2316 template<typename _RealType = double>
2317 class gamma_distribution
2319 static_assert(std::is_floating_point<_RealType>::value,
2320 "template argument not a floating point type");
2322 public:
2323 /** The type of the range of the distribution. */
2324 typedef _RealType result_type;
2325 /** Parameter type. */
2326 struct param_type
2328 typedef gamma_distribution<_RealType> distribution_type;
2329 friend class gamma_distribution<_RealType>;
2331 explicit
2332 param_type(_RealType __alpha_val = _RealType(1),
2333 _RealType __beta_val = _RealType(1))
2334 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2336 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2337 _M_initialize();
2340 _RealType
2341 alpha() const
2342 { return _M_alpha; }
2344 _RealType
2345 beta() const
2346 { return _M_beta; }
2348 friend bool
2349 operator==(const param_type& __p1, const param_type& __p2)
2350 { return (__p1._M_alpha == __p2._M_alpha
2351 && __p1._M_beta == __p2._M_beta); }
2353 private:
2354 void
2355 _M_initialize();
2357 _RealType _M_alpha;
2358 _RealType _M_beta;
2360 _RealType _M_malpha, _M_a2;
2363 public:
2365 * @brief Constructs a gamma distribution with parameters
2366 * @f$\alpha@f$ and @f$\beta@f$.
2368 explicit
2369 gamma_distribution(_RealType __alpha_val = _RealType(1),
2370 _RealType __beta_val = _RealType(1))
2371 : _M_param(__alpha_val, __beta_val), _M_nd()
2374 explicit
2375 gamma_distribution(const param_type& __p)
2376 : _M_param(__p), _M_nd()
2380 * @brief Resets the distribution state.
2382 void
2383 reset()
2384 { _M_nd.reset(); }
2387 * @brief Returns the @f$\alpha@f$ of the distribution.
2389 _RealType
2390 alpha() const
2391 { return _M_param.alpha(); }
2394 * @brief Returns the @f$\beta@f$ of the distribution.
2396 _RealType
2397 beta() const
2398 { return _M_param.beta(); }
2401 * @brief Returns the parameter set of the distribution.
2403 param_type
2404 param() const
2405 { return _M_param; }
2408 * @brief Sets the parameter set of the distribution.
2409 * @param __param The new parameter set of the distribution.
2411 void
2412 param(const param_type& __param)
2413 { _M_param = __param; }
2416 * @brief Returns the greatest lower bound value of the distribution.
2418 result_type
2419 min() const
2420 { return result_type(0); }
2423 * @brief Returns the least upper bound value of the distribution.
2425 result_type
2426 max() const
2427 { return std::numeric_limits<result_type>::max(); }
2430 * @brief Generating functions.
2432 template<typename _UniformRandomNumberGenerator>
2433 result_type
2434 operator()(_UniformRandomNumberGenerator& __urng)
2435 { return this->operator()(__urng, this->param()); }
2437 template<typename _UniformRandomNumberGenerator>
2438 result_type
2439 operator()(_UniformRandomNumberGenerator& __urng,
2440 const param_type& __p);
2443 * @brief Return true if two gamma distributions have the same
2444 * parameters and the sequences that would be generated
2445 * are equal.
2447 template<typename _RealType1>
2448 friend bool
2449 operator==(const std::gamma_distribution<_RealType1>& __d1,
2450 const std::gamma_distribution<_RealType1>& __d2)
2451 { return (__d1.param() == __d2.param()
2452 && __d1._M_nd == __d2._M_nd); }
2455 * @brief Inserts a %gamma_distribution random number distribution
2456 * @p __x into the output stream @p __os.
2458 * @param __os An output stream.
2459 * @param __x A %gamma_distribution random number distribution.
2461 * @returns The output stream with the state of @p __x inserted or in
2462 * an error state.
2464 template<typename _RealType1, typename _CharT, typename _Traits>
2465 friend std::basic_ostream<_CharT, _Traits>&
2466 operator<<(std::basic_ostream<_CharT, _Traits>&,
2467 const std::gamma_distribution<_RealType1>&);
2470 * @brief Extracts a %gamma_distribution random number distribution
2471 * @p __x from the input stream @p __is.
2473 * @param __is An input stream.
2474 * @param __x A %gamma_distribution random number generator engine.
2476 * @returns The input stream with @p __x extracted or in an error state.
2478 template<typename _RealType1, typename _CharT, typename _Traits>
2479 friend std::basic_istream<_CharT, _Traits>&
2480 operator>>(std::basic_istream<_CharT, _Traits>&,
2481 std::gamma_distribution<_RealType1>&);
2483 private:
2484 param_type _M_param;
2486 std::normal_distribution<result_type> _M_nd;
2490 * @brief Return true if two gamma distributions are different.
2492 template<typename _RealType>
2493 inline bool
2494 operator!=(const std::gamma_distribution<_RealType>& __d1,
2495 const std::gamma_distribution<_RealType>& __d2)
2496 { return !(__d1 == __d2); }
2500 * @brief A chi_squared_distribution random number distribution.
2502 * The formula for the normal probability mass function is
2503 * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2505 template<typename _RealType = double>
2506 class chi_squared_distribution
2508 static_assert(std::is_floating_point<_RealType>::value,
2509 "template argument not a floating point type");
2511 public:
2512 /** The type of the range of the distribution. */
2513 typedef _RealType result_type;
2514 /** Parameter type. */
2515 struct param_type
2517 typedef chi_squared_distribution<_RealType> distribution_type;
2519 explicit
2520 param_type(_RealType __n = _RealType(1))
2521 : _M_n(__n)
2524 _RealType
2525 n() const
2526 { return _M_n; }
2528 friend bool
2529 operator==(const param_type& __p1, const param_type& __p2)
2530 { return __p1._M_n == __p2._M_n; }
2532 private:
2533 _RealType _M_n;
2536 explicit
2537 chi_squared_distribution(_RealType __n = _RealType(1))
2538 : _M_param(__n), _M_gd(__n / 2)
2541 explicit
2542 chi_squared_distribution(const param_type& __p)
2543 : _M_param(__p), _M_gd(__p.n() / 2)
2547 * @brief Resets the distribution state.
2549 void
2550 reset()
2551 { _M_gd.reset(); }
2556 _RealType
2557 n() const
2558 { return _M_param.n(); }
2561 * @brief Returns the parameter set of the distribution.
2563 param_type
2564 param() const
2565 { return _M_param; }
2568 * @brief Sets the parameter set of the distribution.
2569 * @param __param The new parameter set of the distribution.
2571 void
2572 param(const param_type& __param)
2573 { _M_param = __param; }
2576 * @brief Returns the greatest lower bound value of the distribution.
2578 result_type
2579 min() const
2580 { return result_type(0); }
2583 * @brief Returns the least upper bound value of the distribution.
2585 result_type
2586 max() const
2587 { return std::numeric_limits<result_type>::max(); }
2590 * @brief Generating functions.
2592 template<typename _UniformRandomNumberGenerator>
2593 result_type
2594 operator()(_UniformRandomNumberGenerator& __urng)
2595 { return 2 * _M_gd(__urng); }
2597 template<typename _UniformRandomNumberGenerator>
2598 result_type
2599 operator()(_UniformRandomNumberGenerator& __urng,
2600 const param_type& __p)
2602 typedef typename std::gamma_distribution<result_type>::param_type
2603 param_type;
2604 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2608 * @brief Return true if two Chi-squared distributions have
2609 * the same parameters and the sequences that would be
2610 * generated are equal.
2612 template<typename _RealType1>
2613 friend bool
2614 operator==(const std::chi_squared_distribution<_RealType1>& __d1,
2615 const std::chi_squared_distribution<_RealType1>& __d2)
2616 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2619 * @brief Inserts a %chi_squared_distribution random number distribution
2620 * @p __x into the output stream @p __os.
2622 * @param __os An output stream.
2623 * @param __x A %chi_squared_distribution random number distribution.
2625 * @returns The output stream with the state of @p __x inserted or in
2626 * an error state.
2628 template<typename _RealType1, typename _CharT, typename _Traits>
2629 friend std::basic_ostream<_CharT, _Traits>&
2630 operator<<(std::basic_ostream<_CharT, _Traits>&,
2631 const std::chi_squared_distribution<_RealType1>&);
2634 * @brief Extracts a %chi_squared_distribution random number distribution
2635 * @p __x from the input stream @p __is.
2637 * @param __is An input stream.
2638 * @param __x A %chi_squared_distribution random number
2639 * generator engine.
2641 * @returns The input stream with @p __x extracted or in an error state.
2643 template<typename _RealType1, typename _CharT, typename _Traits>
2644 friend std::basic_istream<_CharT, _Traits>&
2645 operator>>(std::basic_istream<_CharT, _Traits>&,
2646 std::chi_squared_distribution<_RealType1>&);
2648 private:
2649 param_type _M_param;
2651 std::gamma_distribution<result_type> _M_gd;
2655 * @brief Return true if two Chi-squared distributions are different.
2657 template<typename _RealType>
2658 inline bool
2659 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
2660 const std::chi_squared_distribution<_RealType>& __d2)
2661 { return !(__d1 == __d2); }
2665 * @brief A cauchy_distribution random number distribution.
2667 * The formula for the normal probability mass function is
2668 * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2670 template<typename _RealType = double>
2671 class cauchy_distribution
2673 static_assert(std::is_floating_point<_RealType>::value,
2674 "template argument not a floating point type");
2676 public:
2677 /** The type of the range of the distribution. */
2678 typedef _RealType result_type;
2679 /** Parameter type. */
2680 struct param_type
2682 typedef cauchy_distribution<_RealType> distribution_type;
2684 explicit
2685 param_type(_RealType __a = _RealType(0),
2686 _RealType __b = _RealType(1))
2687 : _M_a(__a), _M_b(__b)
2690 _RealType
2691 a() const
2692 { return _M_a; }
2694 _RealType
2695 b() const
2696 { return _M_b; }
2698 friend bool
2699 operator==(const param_type& __p1, const param_type& __p2)
2700 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2702 private:
2703 _RealType _M_a;
2704 _RealType _M_b;
2707 explicit
2708 cauchy_distribution(_RealType __a = _RealType(0),
2709 _RealType __b = _RealType(1))
2710 : _M_param(__a, __b)
2713 explicit
2714 cauchy_distribution(const param_type& __p)
2715 : _M_param(__p)
2719 * @brief Resets the distribution state.
2721 void
2722 reset()
2728 _RealType
2729 a() const
2730 { return _M_param.a(); }
2732 _RealType
2733 b() const
2734 { return _M_param.b(); }
2737 * @brief Returns the parameter set of the distribution.
2739 param_type
2740 param() const
2741 { return _M_param; }
2744 * @brief Sets the parameter set of the distribution.
2745 * @param __param The new parameter set of the distribution.
2747 void
2748 param(const param_type& __param)
2749 { _M_param = __param; }
2752 * @brief Returns the greatest lower bound value of the distribution.
2754 result_type
2755 min() const
2756 { return std::numeric_limits<result_type>::min(); }
2759 * @brief Returns the least upper bound value of the distribution.
2761 result_type
2762 max() const
2763 { return std::numeric_limits<result_type>::max(); }
2766 * @brief Generating functions.
2768 template<typename _UniformRandomNumberGenerator>
2769 result_type
2770 operator()(_UniformRandomNumberGenerator& __urng)
2771 { return this->operator()(__urng, this->param()); }
2773 template<typename _UniformRandomNumberGenerator>
2774 result_type
2775 operator()(_UniformRandomNumberGenerator& __urng,
2776 const param_type& __p);
2778 private:
2779 param_type _M_param;
2783 * @brief Return true if two Cauchy distributions have
2784 * the same parameters.
2786 template<typename _RealType>
2787 inline bool
2788 operator==(const std::cauchy_distribution<_RealType>& __d1,
2789 const std::cauchy_distribution<_RealType>& __d2)
2790 { return __d1.param() == __d2.param(); }
2793 * @brief Return true if two Cauchy distributions have
2794 * different parameters.
2796 template<typename _RealType>
2797 inline bool
2798 operator!=(const std::cauchy_distribution<_RealType>& __d1,
2799 const std::cauchy_distribution<_RealType>& __d2)
2800 { return !(__d1 == __d2); }
2803 * @brief Inserts a %cauchy_distribution random number distribution
2804 * @p __x into the output stream @p __os.
2806 * @param __os An output stream.
2807 * @param __x A %cauchy_distribution random number distribution.
2809 * @returns The output stream with the state of @p __x inserted or in
2810 * an error state.
2812 template<typename _RealType, typename _CharT, typename _Traits>
2813 std::basic_ostream<_CharT, _Traits>&
2814 operator<<(std::basic_ostream<_CharT, _Traits>&,
2815 const std::cauchy_distribution<_RealType>&);
2818 * @brief Extracts a %cauchy_distribution random number distribution
2819 * @p __x from the input stream @p __is.
2821 * @param __is An input stream.
2822 * @param __x A %cauchy_distribution random number
2823 * generator engine.
2825 * @returns The input stream with @p __x extracted or in an error state.
2827 template<typename _RealType, typename _CharT, typename _Traits>
2828 std::basic_istream<_CharT, _Traits>&
2829 operator>>(std::basic_istream<_CharT, _Traits>&,
2830 std::cauchy_distribution<_RealType>&);
2834 * @brief A fisher_f_distribution random number distribution.
2836 * The formula for the normal probability mass function is
2837 * @f[
2838 * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2839 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2840 * (1 + \frac{mx}{n})^{-(m+n)/2}
2841 * @f]
2843 template<typename _RealType = double>
2844 class fisher_f_distribution
2846 static_assert(std::is_floating_point<_RealType>::value,
2847 "template argument not a floating point type");
2849 public:
2850 /** The type of the range of the distribution. */
2851 typedef _RealType result_type;
2852 /** Parameter type. */
2853 struct param_type
2855 typedef fisher_f_distribution<_RealType> distribution_type;
2857 explicit
2858 param_type(_RealType __m = _RealType(1),
2859 _RealType __n = _RealType(1))
2860 : _M_m(__m), _M_n(__n)
2863 _RealType
2864 m() const
2865 { return _M_m; }
2867 _RealType
2868 n() const
2869 { return _M_n; }
2871 friend bool
2872 operator==(const param_type& __p1, const param_type& __p2)
2873 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2875 private:
2876 _RealType _M_m;
2877 _RealType _M_n;
2880 explicit
2881 fisher_f_distribution(_RealType __m = _RealType(1),
2882 _RealType __n = _RealType(1))
2883 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2886 explicit
2887 fisher_f_distribution(const param_type& __p)
2888 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2892 * @brief Resets the distribution state.
2894 void
2895 reset()
2897 _M_gd_x.reset();
2898 _M_gd_y.reset();
2904 _RealType
2905 m() const
2906 { return _M_param.m(); }
2908 _RealType
2909 n() const
2910 { return _M_param.n(); }
2913 * @brief Returns the parameter set of the distribution.
2915 param_type
2916 param() const
2917 { return _M_param; }
2920 * @brief Sets the parameter set of the distribution.
2921 * @param __param The new parameter set of the distribution.
2923 void
2924 param(const param_type& __param)
2925 { _M_param = __param; }
2928 * @brief Returns the greatest lower bound value of the distribution.
2930 result_type
2931 min() const
2932 { return result_type(0); }
2935 * @brief Returns the least upper bound value of the distribution.
2937 result_type
2938 max() const
2939 { return std::numeric_limits<result_type>::max(); }
2942 * @brief Generating functions.
2944 template<typename _UniformRandomNumberGenerator>
2945 result_type
2946 operator()(_UniformRandomNumberGenerator& __urng)
2947 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2949 template<typename _UniformRandomNumberGenerator>
2950 result_type
2951 operator()(_UniformRandomNumberGenerator& __urng,
2952 const param_type& __p)
2954 typedef typename std::gamma_distribution<result_type>::param_type
2955 param_type;
2956 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2957 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2961 * @brief Return true if two Fisher f distributions have
2962 * the same parameters and the sequences that would
2963 * be generated are equal.
2965 template<typename _RealType1>
2966 friend bool
2967 operator==(const std::fisher_f_distribution<_RealType1>& __d1,
2968 const std::fisher_f_distribution<_RealType1>& __d2)
2969 { return (__d1.param() == __d2.param()
2970 && __d1._M_gd_x == __d2._M_gd_x
2971 && __d1._M_gd_y == __d2._M_gd_y); }
2974 * @brief Inserts a %fisher_f_distribution random number distribution
2975 * @p __x into the output stream @p __os.
2977 * @param __os An output stream.
2978 * @param __x A %fisher_f_distribution random number distribution.
2980 * @returns The output stream with the state of @p __x inserted or in
2981 * an error state.
2983 template<typename _RealType1, typename _CharT, typename _Traits>
2984 friend std::basic_ostream<_CharT, _Traits>&
2985 operator<<(std::basic_ostream<_CharT, _Traits>&,
2986 const std::fisher_f_distribution<_RealType1>&);
2989 * @brief Extracts a %fisher_f_distribution random number distribution
2990 * @p __x from the input stream @p __is.
2992 * @param __is An input stream.
2993 * @param __x A %fisher_f_distribution random number
2994 * generator engine.
2996 * @returns The input stream with @p __x extracted or in an error state.
2998 template<typename _RealType1, typename _CharT, typename _Traits>
2999 friend std::basic_istream<_CharT, _Traits>&
3000 operator>>(std::basic_istream<_CharT, _Traits>&,
3001 std::fisher_f_distribution<_RealType1>&);
3003 private:
3004 param_type _M_param;
3006 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3010 * @brief Return true if two Fisher f distributions are diferent.
3012 template<typename _RealType>
3013 inline bool
3014 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
3015 const std::fisher_f_distribution<_RealType>& __d2)
3016 { return !(__d1 == __d2); }
3019 * @brief A student_t_distribution random number distribution.
3021 * The formula for the normal probability mass function is:
3022 * @f[
3023 * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3024 * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3025 * @f]
3027 template<typename _RealType = double>
3028 class student_t_distribution
3030 static_assert(std::is_floating_point<_RealType>::value,
3031 "template argument not a floating point type");
3033 public:
3034 /** The type of the range of the distribution. */
3035 typedef _RealType result_type;
3036 /** Parameter type. */
3037 struct param_type
3039 typedef student_t_distribution<_RealType> distribution_type;
3041 explicit
3042 param_type(_RealType __n = _RealType(1))
3043 : _M_n(__n)
3046 _RealType
3047 n() const
3048 { return _M_n; }
3050 friend bool
3051 operator==(const param_type& __p1, const param_type& __p2)
3052 { return __p1._M_n == __p2._M_n; }
3054 private:
3055 _RealType _M_n;
3058 explicit
3059 student_t_distribution(_RealType __n = _RealType(1))
3060 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3063 explicit
3064 student_t_distribution(const param_type& __p)
3065 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3069 * @brief Resets the distribution state.
3071 void
3072 reset()
3074 _M_nd.reset();
3075 _M_gd.reset();
3081 _RealType
3082 n() const
3083 { return _M_param.n(); }
3086 * @brief Returns the parameter set of the distribution.
3088 param_type
3089 param() const
3090 { return _M_param; }
3093 * @brief Sets the parameter set of the distribution.
3094 * @param __param The new parameter set of the distribution.
3096 void
3097 param(const param_type& __param)
3098 { _M_param = __param; }
3101 * @brief Returns the greatest lower bound value of the distribution.
3103 result_type
3104 min() const
3105 { return std::numeric_limits<result_type>::min(); }
3108 * @brief Returns the least upper bound value of the distribution.
3110 result_type
3111 max() const
3112 { return std::numeric_limits<result_type>::max(); }
3115 * @brief Generating functions.
3117 template<typename _UniformRandomNumberGenerator>
3118 result_type
3119 operator()(_UniformRandomNumberGenerator& __urng)
3120 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3122 template<typename _UniformRandomNumberGenerator>
3123 result_type
3124 operator()(_UniformRandomNumberGenerator& __urng,
3125 const param_type& __p)
3127 typedef typename std::gamma_distribution<result_type>::param_type
3128 param_type;
3130 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3131 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3135 * @brief Return true if two Student t distributions have
3136 * the same parameters and the sequences that would
3137 * be generated are equal.
3139 template<typename _RealType1>
3140 friend bool
3141 operator==(const std::student_t_distribution<_RealType1>& __d1,
3142 const std::student_t_distribution<_RealType1>& __d2)
3143 { return (__d1.param() == __d2.param()
3144 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3147 * @brief Inserts a %student_t_distribution random number distribution
3148 * @p __x into the output stream @p __os.
3150 * @param __os An output stream.
3151 * @param __x A %student_t_distribution random number distribution.
3153 * @returns The output stream with the state of @p __x inserted or in
3154 * an error state.
3156 template<typename _RealType1, typename _CharT, typename _Traits>
3157 friend std::basic_ostream<_CharT, _Traits>&
3158 operator<<(std::basic_ostream<_CharT, _Traits>&,
3159 const std::student_t_distribution<_RealType1>&);
3162 * @brief Extracts a %student_t_distribution random number distribution
3163 * @p __x from the input stream @p __is.
3165 * @param __is An input stream.
3166 * @param __x A %student_t_distribution random number
3167 * generator engine.
3169 * @returns The input stream with @p __x extracted or in an error state.
3171 template<typename _RealType1, typename _CharT, typename _Traits>
3172 friend std::basic_istream<_CharT, _Traits>&
3173 operator>>(std::basic_istream<_CharT, _Traits>&,
3174 std::student_t_distribution<_RealType1>&);
3176 private:
3177 param_type _M_param;
3179 std::normal_distribution<result_type> _M_nd;
3180 std::gamma_distribution<result_type> _M_gd;
3184 * @brief Return true if two Student t distributions are different.
3186 template<typename _RealType>
3187 inline bool
3188 operator!=(const std::student_t_distribution<_RealType>& __d1,
3189 const std::student_t_distribution<_RealType>& __d2)
3190 { return !(__d1 == __d2); }
3193 /* @} */ // group random_distributions_normal
3196 * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3197 * @ingroup random_distributions
3198 * @{
3202 * @brief A Bernoulli random number distribution.
3204 * Generates a sequence of true and false values with likelihood @f$p@f$
3205 * that true will come up and @f$(1 - p)@f$ that false will appear.
3207 class bernoulli_distribution
3209 public:
3210 /** The type of the range of the distribution. */
3211 typedef bool result_type;
3212 /** Parameter type. */
3213 struct param_type
3215 typedef bernoulli_distribution distribution_type;
3217 explicit
3218 param_type(double __p = 0.5)
3219 : _M_p(__p)
3221 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3224 double
3225 p() const
3226 { return _M_p; }
3228 friend bool
3229 operator==(const param_type& __p1, const param_type& __p2)
3230 { return __p1._M_p == __p2._M_p; }
3232 private:
3233 double _M_p;
3236 public:
3238 * @brief Constructs a Bernoulli distribution with likelihood @p p.
3240 * @param __p [IN] The likelihood of a true result being returned.
3241 * Must be in the interval @f$[0, 1]@f$.
3243 explicit
3244 bernoulli_distribution(double __p = 0.5)
3245 : _M_param(__p)
3248 explicit
3249 bernoulli_distribution(const param_type& __p)
3250 : _M_param(__p)
3254 * @brief Resets the distribution state.
3256 * Does nothing for a Bernoulli distribution.
3258 void
3259 reset() { }
3262 * @brief Returns the @p p parameter of the distribution.
3264 double
3265 p() const
3266 { return _M_param.p(); }
3269 * @brief Returns the parameter set of the distribution.
3271 param_type
3272 param() const
3273 { return _M_param; }
3276 * @brief Sets the parameter set of the distribution.
3277 * @param __param The new parameter set of the distribution.
3279 void
3280 param(const param_type& __param)
3281 { _M_param = __param; }
3284 * @brief Returns the greatest lower bound value of the distribution.
3286 result_type
3287 min() const
3288 { return std::numeric_limits<result_type>::min(); }
3291 * @brief Returns the least upper bound value of the distribution.
3293 result_type
3294 max() const
3295 { return std::numeric_limits<result_type>::max(); }
3298 * @brief Generating functions.
3300 template<typename _UniformRandomNumberGenerator>
3301 result_type
3302 operator()(_UniformRandomNumberGenerator& __urng)
3303 { return this->operator()(__urng, this->param()); }
3305 template<typename _UniformRandomNumberGenerator>
3306 result_type
3307 operator()(_UniformRandomNumberGenerator& __urng,
3308 const param_type& __p)
3310 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3311 __aurng(__urng);
3312 if ((__aurng() - __aurng.min())
3313 < __p.p() * (__aurng.max() - __aurng.min()))
3314 return true;
3315 return false;
3318 private:
3319 param_type _M_param;
3323 * @brief Return true if two Bernoulli distributions have
3324 * the same parameters.
3326 inline bool
3327 operator==(const std::bernoulli_distribution& __d1,
3328 const std::bernoulli_distribution& __d2)
3329 { return __d1.param() == __d2.param(); }
3332 * @brief Return true if two Bernoulli distributions have
3333 * different parameters.
3335 inline bool
3336 operator!=(const std::bernoulli_distribution& __d1,
3337 const std::bernoulli_distribution& __d2)
3338 { return !(__d1 == __d2); }
3341 * @brief Inserts a %bernoulli_distribution random number distribution
3342 * @p __x into the output stream @p __os.
3344 * @param __os An output stream.
3345 * @param __x A %bernoulli_distribution random number distribution.
3347 * @returns The output stream with the state of @p __x inserted or in
3348 * an error state.
3350 template<typename _CharT, typename _Traits>
3351 std::basic_ostream<_CharT, _Traits>&
3352 operator<<(std::basic_ostream<_CharT, _Traits>&,
3353 const std::bernoulli_distribution&);
3356 * @brief Extracts a %bernoulli_distribution random number distribution
3357 * @p __x from the input stream @p __is.
3359 * @param __is An input stream.
3360 * @param __x A %bernoulli_distribution random number generator engine.
3362 * @returns The input stream with @p __x extracted or in an error state.
3364 template<typename _CharT, typename _Traits>
3365 std::basic_istream<_CharT, _Traits>&
3366 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3367 std::bernoulli_distribution& __x)
3369 double __p;
3370 __is >> __p;
3371 __x.param(bernoulli_distribution::param_type(__p));
3372 return __is;
3377 * @brief A discrete binomial random number distribution.
3379 * The formula for the binomial probability density function is
3380 * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3381 * and @f$p@f$ are the parameters of the distribution.
3383 template<typename _IntType = int>
3384 class binomial_distribution
3386 static_assert(std::is_integral<_IntType>::value,
3387 "template argument not an integral type");
3389 public:
3390 /** The type of the range of the distribution. */
3391 typedef _IntType result_type;
3392 /** Parameter type. */
3393 struct param_type
3395 typedef binomial_distribution<_IntType> distribution_type;
3396 friend class binomial_distribution<_IntType>;
3398 explicit
3399 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3400 : _M_t(__t), _M_p(__p)
3402 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3403 && (_M_p >= 0.0)
3404 && (_M_p <= 1.0));
3405 _M_initialize();
3408 _IntType
3409 t() const
3410 { return _M_t; }
3412 double
3413 p() const
3414 { return _M_p; }
3416 friend bool
3417 operator==(const param_type& __p1, const param_type& __p2)
3418 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3420 private:
3421 void
3422 _M_initialize();
3424 _IntType _M_t;
3425 double _M_p;
3427 double _M_q;
3428 #if _GLIBCXX_USE_C99_MATH_TR1
3429 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3430 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3431 #endif
3432 bool _M_easy;
3435 // constructors and member function
3436 explicit
3437 binomial_distribution(_IntType __t = _IntType(1),
3438 double __p = 0.5)
3439 : _M_param(__t, __p), _M_nd()
3442 explicit
3443 binomial_distribution(const param_type& __p)
3444 : _M_param(__p), _M_nd()
3448 * @brief Resets the distribution state.
3450 void
3451 reset()
3452 { _M_nd.reset(); }
3455 * @brief Returns the distribution @p t parameter.
3457 _IntType
3458 t() const
3459 { return _M_param.t(); }
3462 * @brief Returns the distribution @p p parameter.
3464 double
3465 p() const
3466 { return _M_param.p(); }
3469 * @brief Returns the parameter set of the distribution.
3471 param_type
3472 param() const
3473 { return _M_param; }
3476 * @brief Sets the parameter set of the distribution.
3477 * @param __param The new parameter set of the distribution.
3479 void
3480 param(const param_type& __param)
3481 { _M_param = __param; }
3484 * @brief Returns the greatest lower bound value of the distribution.
3486 result_type
3487 min() const
3488 { return 0; }
3491 * @brief Returns the least upper bound value of the distribution.
3493 result_type
3494 max() const
3495 { return _M_param.t(); }
3498 * @brief Generating functions.
3500 template<typename _UniformRandomNumberGenerator>
3501 result_type
3502 operator()(_UniformRandomNumberGenerator& __urng)
3503 { return this->operator()(__urng, this->param()); }
3505 template<typename _UniformRandomNumberGenerator>
3506 result_type
3507 operator()(_UniformRandomNumberGenerator& __urng,
3508 const param_type& __p);
3511 * @brief Return true if two binomial distributions have
3512 * the same parameters and the sequences that would
3513 * be generated are equal.
3515 template<typename _IntType1>
3516 friend bool
3517 operator==(const std::binomial_distribution<_IntType1>& __d1,
3518 const std::binomial_distribution<_IntType1>& __d2)
3519 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3520 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3521 #else
3522 { return __d1.param() == __d2.param(); }
3523 #endif
3526 * @brief Inserts a %binomial_distribution random number distribution
3527 * @p __x into the output stream @p __os.
3529 * @param __os An output stream.
3530 * @param __x A %binomial_distribution random number distribution.
3532 * @returns The output stream with the state of @p __x inserted or in
3533 * an error state.
3535 template<typename _IntType1,
3536 typename _CharT, typename _Traits>
3537 friend std::basic_ostream<_CharT, _Traits>&
3538 operator<<(std::basic_ostream<_CharT, _Traits>&,
3539 const std::binomial_distribution<_IntType1>&);
3542 * @brief Extracts a %binomial_distribution random number distribution
3543 * @p __x from the input stream @p __is.
3545 * @param __is An input stream.
3546 * @param __x A %binomial_distribution random number generator engine.
3548 * @returns The input stream with @p __x extracted or in an error
3549 * state.
3551 template<typename _IntType1,
3552 typename _CharT, typename _Traits>
3553 friend std::basic_istream<_CharT, _Traits>&
3554 operator>>(std::basic_istream<_CharT, _Traits>&,
3555 std::binomial_distribution<_IntType1>&);
3557 private:
3558 template<typename _UniformRandomNumberGenerator>
3559 result_type
3560 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3562 param_type _M_param;
3564 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3565 std::normal_distribution<double> _M_nd;
3569 * @brief Return true if two binomial distributions are different.
3571 template<typename _IntType>
3572 inline bool
3573 operator!=(const std::binomial_distribution<_IntType>& __d1,
3574 const std::binomial_distribution<_IntType>& __d2)
3575 { return !(__d1 == __d2); }
3579 * @brief A discrete geometric random number distribution.
3581 * The formula for the geometric probability density function is
3582 * @f$p(i|p) = (1 - p)p^{i-1}@f$ where @f$p@f$ is the parameter of the
3583 * distribution.
3585 template<typename _IntType = int>
3586 class geometric_distribution
3588 static_assert(std::is_integral<_IntType>::value,
3589 "template argument not an integral type");
3591 public:
3592 /** The type of the range of the distribution. */
3593 typedef _IntType result_type;
3594 /** Parameter type. */
3595 struct param_type
3597 typedef geometric_distribution<_IntType> distribution_type;
3598 friend class geometric_distribution<_IntType>;
3600 explicit
3601 param_type(double __p = 0.5)
3602 : _M_p(__p)
3604 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
3605 && (_M_p <= 1.0));
3606 _M_initialize();
3609 double
3610 p() const
3611 { return _M_p; }
3613 friend bool
3614 operator==(const param_type& __p1, const param_type& __p2)
3615 { return __p1._M_p == __p2._M_p; }
3617 private:
3618 void
3619 _M_initialize()
3620 { _M_log_p = std::log(_M_p); }
3622 double _M_p;
3624 double _M_log_p;
3627 // constructors and member function
3628 explicit
3629 geometric_distribution(double __p = 0.5)
3630 : _M_param(__p)
3633 explicit
3634 geometric_distribution(const param_type& __p)
3635 : _M_param(__p)
3639 * @brief Resets the distribution state.
3641 * Does nothing for the geometric distribution.
3643 void
3644 reset() { }
3647 * @brief Returns the distribution parameter @p p.
3649 double
3650 p() const
3651 { return _M_param.p(); }
3654 * @brief Returns the parameter set of the distribution.
3656 param_type
3657 param() const
3658 { return _M_param; }
3661 * @brief Sets the parameter set of the distribution.
3662 * @param __param The new parameter set of the distribution.
3664 void
3665 param(const param_type& __param)
3666 { _M_param = __param; }
3669 * @brief Returns the greatest lower bound value of the distribution.
3671 result_type
3672 min() const
3673 { return 0; }
3676 * @brief Returns the least upper bound value of the distribution.
3678 result_type
3679 max() const
3680 { return std::numeric_limits<result_type>::max(); }
3683 * @brief Generating functions.
3685 template<typename _UniformRandomNumberGenerator>
3686 result_type
3687 operator()(_UniformRandomNumberGenerator& __urng)
3688 { return this->operator()(__urng, this->param()); }
3690 template<typename _UniformRandomNumberGenerator>
3691 result_type
3692 operator()(_UniformRandomNumberGenerator& __urng,
3693 const param_type& __p);
3695 private:
3696 param_type _M_param;
3700 * @brief Return true if two geometric distributions have
3701 * the same parameters.
3703 template<typename _IntType>
3704 inline bool
3705 operator==(const std::geometric_distribution<_IntType>& __d1,
3706 const std::geometric_distribution<_IntType>& __d2)
3707 { return __d1.param() == __d2.param(); }
3710 * @brief Return true if two geometric distributions have
3711 * different parameters.
3713 template<typename _IntType>
3714 inline bool
3715 operator!=(const std::geometric_distribution<_IntType>& __d1,
3716 const std::geometric_distribution<_IntType>& __d2)
3717 { return !(__d1 == __d2); }
3720 * @brief Inserts a %geometric_distribution random number distribution
3721 * @p __x into the output stream @p __os.
3723 * @param __os An output stream.
3724 * @param __x A %geometric_distribution random number distribution.
3726 * @returns The output stream with the state of @p __x inserted or in
3727 * an error state.
3729 template<typename _IntType,
3730 typename _CharT, typename _Traits>
3731 std::basic_ostream<_CharT, _Traits>&
3732 operator<<(std::basic_ostream<_CharT, _Traits>&,
3733 const std::geometric_distribution<_IntType>&);
3736 * @brief Extracts a %geometric_distribution random number distribution
3737 * @p __x from the input stream @p __is.
3739 * @param __is An input stream.
3740 * @param __x A %geometric_distribution random number generator engine.
3742 * @returns The input stream with @p __x extracted or in an error state.
3744 template<typename _IntType,
3745 typename _CharT, typename _Traits>
3746 std::basic_istream<_CharT, _Traits>&
3747 operator>>(std::basic_istream<_CharT, _Traits>&,
3748 std::geometric_distribution<_IntType>&);
3752 * @brief A negative_binomial_distribution random number distribution.
3754 * The formula for the negative binomial probability mass function is
3755 * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3756 * and @f$p@f$ are the parameters of the distribution.
3758 template<typename _IntType = int>
3759 class negative_binomial_distribution
3761 static_assert(std::is_integral<_IntType>::value,
3762 "template argument not an integral type");
3764 public:
3765 /** The type of the range of the distribution. */
3766 typedef _IntType result_type;
3767 /** Parameter type. */
3768 struct param_type
3770 typedef negative_binomial_distribution<_IntType> distribution_type;
3772 explicit
3773 param_type(_IntType __k = 1, double __p = 0.5)
3774 : _M_k(__k), _M_p(__p)
3777 _IntType
3778 k() const
3779 { return _M_k; }
3781 double
3782 p() const
3783 { return _M_p; }
3785 friend bool
3786 operator==(const param_type& __p1, const param_type& __p2)
3787 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3789 private:
3790 _IntType _M_k;
3791 double _M_p;
3794 explicit
3795 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3796 : _M_param(__k, __p), _M_gd(__k, __p / (1.0 - __p))
3799 explicit
3800 negative_binomial_distribution(const param_type& __p)
3801 : _M_param(__p), _M_gd(__p.k(), __p.p() / (1.0 - __p.p()))
3805 * @brief Resets the distribution state.
3807 void
3808 reset()
3809 { _M_gd.reset(); }
3812 * @brief Return the @f$k@f$ parameter of the distribution.
3814 _IntType
3815 k() const
3816 { return _M_param.k(); }
3819 * @brief Return the @f$p@f$ parameter of the distribution.
3821 double
3822 p() const
3823 { return _M_param.p(); }
3826 * @brief Returns the parameter set of the distribution.
3828 param_type
3829 param() const
3830 { return _M_param; }
3833 * @brief Sets the parameter set of the distribution.
3834 * @param __param The new parameter set of the distribution.
3836 void
3837 param(const param_type& __param)
3838 { _M_param = __param; }
3841 * @brief Returns the greatest lower bound value of the distribution.
3843 result_type
3844 min() const
3845 { return result_type(0); }
3848 * @brief Returns the least upper bound value of the distribution.
3850 result_type
3851 max() const
3852 { return std::numeric_limits<result_type>::max(); }
3855 * @brief Generating functions.
3857 template<typename _UniformRandomNumberGenerator>
3858 result_type
3859 operator()(_UniformRandomNumberGenerator& __urng);
3861 template<typename _UniformRandomNumberGenerator>
3862 result_type
3863 operator()(_UniformRandomNumberGenerator& __urng,
3864 const param_type& __p);
3867 * @brief Return true if two negative binomial distributions have
3868 * the same parameters and the sequences that would be
3869 * generated are equal.
3871 template<typename _IntType1>
3872 friend bool
3873 operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
3874 const std::negative_binomial_distribution<_IntType1>& __d2)
3875 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3878 * @brief Inserts a %negative_binomial_distribution random
3879 * number distribution @p __x into the output stream @p __os.
3881 * @param __os An output stream.
3882 * @param __x A %negative_binomial_distribution random number
3883 * distribution.
3885 * @returns The output stream with the state of @p __x inserted or in
3886 * an error state.
3888 template<typename _IntType1, typename _CharT, typename _Traits>
3889 friend std::basic_ostream<_CharT, _Traits>&
3890 operator<<(std::basic_ostream<_CharT, _Traits>&,
3891 const std::negative_binomial_distribution<_IntType1>&);
3894 * @brief Extracts a %negative_binomial_distribution random number
3895 * distribution @p __x from the input stream @p __is.
3897 * @param __is An input stream.
3898 * @param __x A %negative_binomial_distribution random number
3899 * generator engine.
3901 * @returns The input stream with @p __x extracted or in an error state.
3903 template<typename _IntType1, typename _CharT, typename _Traits>
3904 friend std::basic_istream<_CharT, _Traits>&
3905 operator>>(std::basic_istream<_CharT, _Traits>&,
3906 std::negative_binomial_distribution<_IntType1>&);
3908 private:
3909 param_type _M_param;
3911 std::gamma_distribution<double> _M_gd;
3915 * @brief Return true if two negative binomial distributions are different.
3917 template<typename _IntType>
3918 inline bool
3919 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
3920 const std::negative_binomial_distribution<_IntType>& __d2)
3921 { return !(__d1 == __d2); }
3924 /* @} */ // group random_distributions_bernoulli
3927 * @addtogroup random_distributions_poisson Poisson Distributions
3928 * @ingroup random_distributions
3929 * @{
3933 * @brief A discrete Poisson random number distribution.
3935 * The formula for the Poisson probability density function is
3936 * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3937 * parameter of the distribution.
3939 template<typename _IntType = int>
3940 class poisson_distribution
3942 static_assert(std::is_integral<_IntType>::value,
3943 "template argument not an integral type");
3945 public:
3946 /** The type of the range of the distribution. */
3947 typedef _IntType result_type;
3948 /** Parameter type. */
3949 struct param_type
3951 typedef poisson_distribution<_IntType> distribution_type;
3952 friend class poisson_distribution<_IntType>;
3954 explicit
3955 param_type(double __mean = 1.0)
3956 : _M_mean(__mean)
3958 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3959 _M_initialize();
3962 double
3963 mean() const
3964 { return _M_mean; }
3966 friend bool
3967 operator==(const param_type& __p1, const param_type& __p2)
3968 { return __p1._M_mean == __p2._M_mean; }
3970 private:
3971 // Hosts either log(mean) or the threshold of the simple method.
3972 void
3973 _M_initialize();
3975 double _M_mean;
3977 double _M_lm_thr;
3978 #if _GLIBCXX_USE_C99_MATH_TR1
3979 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3980 #endif
3983 // constructors and member function
3984 explicit
3985 poisson_distribution(double __mean = 1.0)
3986 : _M_param(__mean), _M_nd()
3989 explicit
3990 poisson_distribution(const param_type& __p)
3991 : _M_param(__p), _M_nd()
3995 * @brief Resets the distribution state.
3997 void
3998 reset()
3999 { _M_nd.reset(); }
4002 * @brief Returns the distribution parameter @p mean.
4004 double
4005 mean() const
4006 { return _M_param.mean(); }
4009 * @brief Returns the parameter set of the distribution.
4011 param_type
4012 param() const
4013 { return _M_param; }
4016 * @brief Sets the parameter set of the distribution.
4017 * @param __param The new parameter set of the distribution.
4019 void
4020 param(const param_type& __param)
4021 { _M_param = __param; }
4024 * @brief Returns the greatest lower bound value of the distribution.
4026 result_type
4027 min() const
4028 { return 0; }
4031 * @brief Returns the least upper bound value of the distribution.
4033 result_type
4034 max() const
4035 { return std::numeric_limits<result_type>::max(); }
4038 * @brief Generating functions.
4040 template<typename _UniformRandomNumberGenerator>
4041 result_type
4042 operator()(_UniformRandomNumberGenerator& __urng)
4043 { return this->operator()(__urng, this->param()); }
4045 template<typename _UniformRandomNumberGenerator>
4046 result_type
4047 operator()(_UniformRandomNumberGenerator& __urng,
4048 const param_type& __p);
4051 * @brief Return true if two Poisson distributions have the same
4052 * parameters and the sequences that would be generated
4053 * are equal.
4055 template<typename _IntType1>
4056 friend bool
4057 operator==(const std::poisson_distribution<_IntType1>& __d1,
4058 const std::poisson_distribution<_IntType1>& __d2)
4059 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4060 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4061 #else
4062 { return __d1.param() == __d2.param(); }
4063 #endif
4066 * @brief Inserts a %poisson_distribution random number distribution
4067 * @p __x into the output stream @p __os.
4069 * @param __os An output stream.
4070 * @param __x A %poisson_distribution random number distribution.
4072 * @returns The output stream with the state of @p __x inserted or in
4073 * an error state.
4075 template<typename _IntType1, typename _CharT, typename _Traits>
4076 friend std::basic_ostream<_CharT, _Traits>&
4077 operator<<(std::basic_ostream<_CharT, _Traits>&,
4078 const std::poisson_distribution<_IntType1>&);
4081 * @brief Extracts a %poisson_distribution random number distribution
4082 * @p __x from the input stream @p __is.
4084 * @param __is An input stream.
4085 * @param __x A %poisson_distribution random number generator engine.
4087 * @returns The input stream with @p __x extracted or in an error
4088 * state.
4090 template<typename _IntType1, typename _CharT, typename _Traits>
4091 friend std::basic_istream<_CharT, _Traits>&
4092 operator>>(std::basic_istream<_CharT, _Traits>&,
4093 std::poisson_distribution<_IntType1>&);
4095 private:
4096 param_type _M_param;
4098 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4099 std::normal_distribution<double> _M_nd;
4103 * @brief Return true if two Poisson distributions are different.
4105 template<typename _IntType>
4106 inline bool
4107 operator!=(const std::poisson_distribution<_IntType>& __d1,
4108 const std::poisson_distribution<_IntType>& __d2)
4109 { return !(__d1 == __d2); }
4113 * @brief An exponential continuous distribution for random numbers.
4115 * The formula for the exponential probability density function is
4116 * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4118 * <table border=1 cellpadding=10 cellspacing=0>
4119 * <caption align=top>Distribution Statistics</caption>
4120 * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4121 * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4122 * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4123 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4124 * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4125 * </table>
4127 template<typename _RealType = double>
4128 class exponential_distribution
4130 static_assert(std::is_floating_point<_RealType>::value,
4131 "template argument not a floating point type");
4133 public:
4134 /** The type of the range of the distribution. */
4135 typedef _RealType result_type;
4136 /** Parameter type. */
4137 struct param_type
4139 typedef exponential_distribution<_RealType> distribution_type;
4141 explicit
4142 param_type(_RealType __lambda = _RealType(1))
4143 : _M_lambda(__lambda)
4145 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4148 _RealType
4149 lambda() const
4150 { return _M_lambda; }
4152 friend bool
4153 operator==(const param_type& __p1, const param_type& __p2)
4154 { return __p1._M_lambda == __p2._M_lambda; }
4156 private:
4157 _RealType _M_lambda;
4160 public:
4162 * @brief Constructs an exponential distribution with inverse scale
4163 * parameter @f$\lambda@f$.
4165 explicit
4166 exponential_distribution(const result_type& __lambda = result_type(1))
4167 : _M_param(__lambda)
4170 explicit
4171 exponential_distribution(const param_type& __p)
4172 : _M_param(__p)
4176 * @brief Resets the distribution state.
4178 * Has no effect on exponential distributions.
4180 void
4181 reset() { }
4184 * @brief Returns the inverse scale parameter of the distribution.
4186 _RealType
4187 lambda() const
4188 { return _M_param.lambda(); }
4191 * @brief Returns the parameter set of the distribution.
4193 param_type
4194 param() const
4195 { return _M_param; }
4198 * @brief Sets the parameter set of the distribution.
4199 * @param __param The new parameter set of the distribution.
4201 void
4202 param(const param_type& __param)
4203 { _M_param = __param; }
4206 * @brief Returns the greatest lower bound value of the distribution.
4208 result_type
4209 min() const
4210 { return result_type(0); }
4213 * @brief Returns the least upper bound value of the distribution.
4215 result_type
4216 max() const
4217 { return std::numeric_limits<result_type>::max(); }
4220 * @brief Generating functions.
4222 template<typename _UniformRandomNumberGenerator>
4223 result_type
4224 operator()(_UniformRandomNumberGenerator& __urng)
4225 { return this->operator()(__urng, this->param()); }
4227 template<typename _UniformRandomNumberGenerator>
4228 result_type
4229 operator()(_UniformRandomNumberGenerator& __urng,
4230 const param_type& __p)
4232 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4233 __aurng(__urng);
4234 return -std::log(__aurng()) / __p.lambda();
4237 private:
4238 param_type _M_param;
4242 * @brief Return true if two exponential distributions have the same
4243 * parameters.
4245 template<typename _RealType>
4246 inline bool
4247 operator==(const std::exponential_distribution<_RealType>& __d1,
4248 const std::exponential_distribution<_RealType>& __d2)
4249 { return __d1.param() == __d2.param(); }
4252 * @brief Return true if two exponential distributions have different
4253 * parameters.
4255 template<typename _RealType>
4256 inline bool
4257 operator!=(const std::exponential_distribution<_RealType>& __d1,
4258 const std::exponential_distribution<_RealType>& __d2)
4259 { return !(__d1 == __d2); }
4262 * @brief Inserts a %exponential_distribution random number distribution
4263 * @p __x into the output stream @p __os.
4265 * @param __os An output stream.
4266 * @param __x A %exponential_distribution random number distribution.
4268 * @returns The output stream with the state of @p __x inserted or in
4269 * an error state.
4271 template<typename _RealType, typename _CharT, typename _Traits>
4272 std::basic_ostream<_CharT, _Traits>&
4273 operator<<(std::basic_ostream<_CharT, _Traits>&,
4274 const std::exponential_distribution<_RealType>&);
4277 * @brief Extracts a %exponential_distribution random number distribution
4278 * @p __x from the input stream @p __is.
4280 * @param __is An input stream.
4281 * @param __x A %exponential_distribution random number
4282 * generator engine.
4284 * @returns The input stream with @p __x extracted or in an error state.
4286 template<typename _RealType, typename _CharT, typename _Traits>
4287 std::basic_istream<_CharT, _Traits>&
4288 operator>>(std::basic_istream<_CharT, _Traits>&,
4289 std::exponential_distribution<_RealType>&);
4293 * @brief A weibull_distribution random number distribution.
4295 * The formula for the normal probability density function is:
4296 * @f[
4297 * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4298 * \exp{(-(\frac{x}{\beta})^\alpha)}
4299 * @f]
4301 template<typename _RealType = double>
4302 class weibull_distribution
4304 static_assert(std::is_floating_point<_RealType>::value,
4305 "template argument not a floating point type");
4307 public:
4308 /** The type of the range of the distribution. */
4309 typedef _RealType result_type;
4310 /** Parameter type. */
4311 struct param_type
4313 typedef weibull_distribution<_RealType> distribution_type;
4315 explicit
4316 param_type(_RealType __a = _RealType(1),
4317 _RealType __b = _RealType(1))
4318 : _M_a(__a), _M_b(__b)
4321 _RealType
4322 a() const
4323 { return _M_a; }
4325 _RealType
4326 b() const
4327 { return _M_b; }
4329 friend bool
4330 operator==(const param_type& __p1, const param_type& __p2)
4331 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4333 private:
4334 _RealType _M_a;
4335 _RealType _M_b;
4338 explicit
4339 weibull_distribution(_RealType __a = _RealType(1),
4340 _RealType __b = _RealType(1))
4341 : _M_param(__a, __b)
4344 explicit
4345 weibull_distribution(const param_type& __p)
4346 : _M_param(__p)
4350 * @brief Resets the distribution state.
4352 void
4353 reset()
4357 * @brief Return the @f$a@f$ parameter of the distribution.
4359 _RealType
4360 a() const
4361 { return _M_param.a(); }
4364 * @brief Return the @f$b@f$ parameter of the distribution.
4366 _RealType
4367 b() const
4368 { return _M_param.b(); }
4371 * @brief Returns the parameter set of the distribution.
4373 param_type
4374 param() const
4375 { return _M_param; }
4378 * @brief Sets the parameter set of the distribution.
4379 * @param __param The new parameter set of the distribution.
4381 void
4382 param(const param_type& __param)
4383 { _M_param = __param; }
4386 * @brief Returns the greatest lower bound value of the distribution.
4388 result_type
4389 min() const
4390 { return result_type(0); }
4393 * @brief Returns the least upper bound value of the distribution.
4395 result_type
4396 max() const
4397 { return std::numeric_limits<result_type>::max(); }
4400 * @brief Generating functions.
4402 template<typename _UniformRandomNumberGenerator>
4403 result_type
4404 operator()(_UniformRandomNumberGenerator& __urng)
4405 { return this->operator()(__urng, this->param()); }
4407 template<typename _UniformRandomNumberGenerator>
4408 result_type
4409 operator()(_UniformRandomNumberGenerator& __urng,
4410 const param_type& __p);
4412 private:
4413 param_type _M_param;
4417 * @brief Return true if two Weibull distributions have the same
4418 * parameters.
4420 template<typename _RealType>
4421 inline bool
4422 operator==(const std::weibull_distribution<_RealType>& __d1,
4423 const std::weibull_distribution<_RealType>& __d2)
4424 { return __d1.param() == __d2.param(); }
4427 * @brief Return true if two Weibull distributions have different
4428 * parameters.
4430 template<typename _RealType>
4431 inline bool
4432 operator!=(const std::weibull_distribution<_RealType>& __d1,
4433 const std::weibull_distribution<_RealType>& __d2)
4434 { return !(__d1 == __d2); }
4437 * @brief Inserts a %weibull_distribution random number distribution
4438 * @p __x into the output stream @p __os.
4440 * @param __os An output stream.
4441 * @param __x A %weibull_distribution random number distribution.
4443 * @returns The output stream with the state of @p __x inserted or in
4444 * an error state.
4446 template<typename _RealType, typename _CharT, typename _Traits>
4447 std::basic_ostream<_CharT, _Traits>&
4448 operator<<(std::basic_ostream<_CharT, _Traits>&,
4449 const std::weibull_distribution<_RealType>&);
4452 * @brief Extracts a %weibull_distribution random number distribution
4453 * @p __x from the input stream @p __is.
4455 * @param __is An input stream.
4456 * @param __x A %weibull_distribution random number
4457 * generator engine.
4459 * @returns The input stream with @p __x extracted or in an error state.
4461 template<typename _RealType, typename _CharT, typename _Traits>
4462 std::basic_istream<_CharT, _Traits>&
4463 operator>>(std::basic_istream<_CharT, _Traits>&,
4464 std::weibull_distribution<_RealType>&);
4468 * @brief A extreme_value_distribution random number distribution.
4470 * The formula for the normal probability mass function is
4471 * @f[
4472 * p(x|a,b) = \frac{1}{b}
4473 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4474 * @f]
4476 template<typename _RealType = double>
4477 class extreme_value_distribution
4479 static_assert(std::is_floating_point<_RealType>::value,
4480 "template argument not a floating point type");
4482 public:
4483 /** The type of the range of the distribution. */
4484 typedef _RealType result_type;
4485 /** Parameter type. */
4486 struct param_type
4488 typedef extreme_value_distribution<_RealType> distribution_type;
4490 explicit
4491 param_type(_RealType __a = _RealType(0),
4492 _RealType __b = _RealType(1))
4493 : _M_a(__a), _M_b(__b)
4496 _RealType
4497 a() const
4498 { return _M_a; }
4500 _RealType
4501 b() const
4502 { return _M_b; }
4504 friend bool
4505 operator==(const param_type& __p1, const param_type& __p2)
4506 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4508 private:
4509 _RealType _M_a;
4510 _RealType _M_b;
4513 explicit
4514 extreme_value_distribution(_RealType __a = _RealType(0),
4515 _RealType __b = _RealType(1))
4516 : _M_param(__a, __b)
4519 explicit
4520 extreme_value_distribution(const param_type& __p)
4521 : _M_param(__p)
4525 * @brief Resets the distribution state.
4527 void
4528 reset()
4532 * @brief Return the @f$a@f$ parameter of the distribution.
4534 _RealType
4535 a() const
4536 { return _M_param.a(); }
4539 * @brief Return the @f$b@f$ parameter of the distribution.
4541 _RealType
4542 b() const
4543 { return _M_param.b(); }
4546 * @brief Returns the parameter set of the distribution.
4548 param_type
4549 param() const
4550 { return _M_param; }
4553 * @brief Sets the parameter set of the distribution.
4554 * @param __param The new parameter set of the distribution.
4556 void
4557 param(const param_type& __param)
4558 { _M_param = __param; }
4561 * @brief Returns the greatest lower bound value of the distribution.
4563 result_type
4564 min() const
4565 { return std::numeric_limits<result_type>::min(); }
4568 * @brief Returns the least upper bound value of the distribution.
4570 result_type
4571 max() const
4572 { return std::numeric_limits<result_type>::max(); }
4575 * @brief Generating functions.
4577 template<typename _UniformRandomNumberGenerator>
4578 result_type
4579 operator()(_UniformRandomNumberGenerator& __urng)
4580 { return this->operator()(__urng, this->param()); }
4582 template<typename _UniformRandomNumberGenerator>
4583 result_type
4584 operator()(_UniformRandomNumberGenerator& __urng,
4585 const param_type& __p);
4587 private:
4588 param_type _M_param;
4592 * @brief Return true if two extreme value distributions have the same
4593 * parameters.
4595 template<typename _RealType>
4596 inline bool
4597 operator==(const std::extreme_value_distribution<_RealType>& __d1,
4598 const std::extreme_value_distribution<_RealType>& __d2)
4599 { return __d1.param() == __d2.param(); }
4602 * @brief Return true if two extreme value distributions have different
4603 * parameters.
4605 template<typename _RealType>
4606 inline bool
4607 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
4608 const std::extreme_value_distribution<_RealType>& __d2)
4609 { return !(__d1 == __d2); }
4612 * @brief Inserts a %extreme_value_distribution random number distribution
4613 * @p __x into the output stream @p __os.
4615 * @param __os An output stream.
4616 * @param __x A %extreme_value_distribution random number distribution.
4618 * @returns The output stream with the state of @p __x inserted or in
4619 * an error state.
4621 template<typename _RealType, typename _CharT, typename _Traits>
4622 std::basic_ostream<_CharT, _Traits>&
4623 operator<<(std::basic_ostream<_CharT, _Traits>&,
4624 const std::extreme_value_distribution<_RealType>&);
4627 * @brief Extracts a %extreme_value_distribution random number
4628 * distribution @p __x from the input stream @p __is.
4630 * @param __is An input stream.
4631 * @param __x A %extreme_value_distribution random number
4632 * generator engine.
4634 * @returns The input stream with @p __x extracted or in an error state.
4636 template<typename _RealType, typename _CharT, typename _Traits>
4637 std::basic_istream<_CharT, _Traits>&
4638 operator>>(std::basic_istream<_CharT, _Traits>&,
4639 std::extreme_value_distribution<_RealType>&);
4643 * @brief A discrete_distribution random number distribution.
4645 * The formula for the discrete probability mass function is
4648 template<typename _IntType = int>
4649 class discrete_distribution
4651 static_assert(std::is_integral<_IntType>::value,
4652 "template argument not an integral type");
4654 public:
4655 /** The type of the range of the distribution. */
4656 typedef _IntType result_type;
4657 /** Parameter type. */
4658 struct param_type
4660 typedef discrete_distribution<_IntType> distribution_type;
4661 friend class discrete_distribution<_IntType>;
4663 param_type()
4664 : _M_prob(), _M_cp()
4667 template<typename _InputIterator>
4668 param_type(_InputIterator __wbegin,
4669 _InputIterator __wend)
4670 : _M_prob(__wbegin, __wend), _M_cp()
4671 { _M_initialize(); }
4673 param_type(initializer_list<double> __wil)
4674 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4675 { _M_initialize(); }
4677 template<typename _Func>
4678 param_type(size_t __nw, double __xmin, double __xmax,
4679 _Func __fw);
4681 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4682 param_type(const param_type&) = default;
4683 param_type& operator=(const param_type&) = default;
4685 std::vector<double>
4686 probabilities() const
4687 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4689 friend bool
4690 operator==(const param_type& __p1, const param_type& __p2)
4691 { return __p1._M_prob == __p2._M_prob; }
4693 private:
4694 void
4695 _M_initialize();
4697 std::vector<double> _M_prob;
4698 std::vector<double> _M_cp;
4701 discrete_distribution()
4702 : _M_param()
4705 template<typename _InputIterator>
4706 discrete_distribution(_InputIterator __wbegin,
4707 _InputIterator __wend)
4708 : _M_param(__wbegin, __wend)
4711 discrete_distribution(initializer_list<double> __wl)
4712 : _M_param(__wl)
4715 template<typename _Func>
4716 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4717 _Func __fw)
4718 : _M_param(__nw, __xmin, __xmax, __fw)
4721 explicit
4722 discrete_distribution(const param_type& __p)
4723 : _M_param(__p)
4727 * @brief Resets the distribution state.
4729 void
4730 reset()
4734 * @brief Returns the probabilities of the distribution.
4736 std::vector<double>
4737 probabilities() const
4739 return _M_param._M_prob.empty()
4740 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4744 * @brief Returns the parameter set of the distribution.
4746 param_type
4747 param() const
4748 { return _M_param; }
4751 * @brief Sets the parameter set of the distribution.
4752 * @param __param The new parameter set of the distribution.
4754 void
4755 param(const param_type& __param)
4756 { _M_param = __param; }
4759 * @brief Returns the greatest lower bound value of the distribution.
4761 result_type
4762 min() const
4763 { return result_type(0); }
4766 * @brief Returns the least upper bound value of the distribution.
4768 result_type
4769 max() const
4771 return _M_param._M_prob.empty()
4772 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4776 * @brief Generating functions.
4778 template<typename _UniformRandomNumberGenerator>
4779 result_type
4780 operator()(_UniformRandomNumberGenerator& __urng)
4781 { return this->operator()(__urng, this->param()); }
4783 template<typename _UniformRandomNumberGenerator>
4784 result_type
4785 operator()(_UniformRandomNumberGenerator& __urng,
4786 const param_type& __p);
4789 * @brief Inserts a %discrete_distribution random number distribution
4790 * @p __x into the output stream @p __os.
4792 * @param __os An output stream.
4793 * @param __x A %discrete_distribution random number distribution.
4795 * @returns The output stream with the state of @p __x inserted or in
4796 * an error state.
4798 template<typename _IntType1, typename _CharT, typename _Traits>
4799 friend std::basic_ostream<_CharT, _Traits>&
4800 operator<<(std::basic_ostream<_CharT, _Traits>&,
4801 const std::discrete_distribution<_IntType1>&);
4804 * @brief Extracts a %discrete_distribution random number distribution
4805 * @p __x from the input stream @p __is.
4807 * @param __is An input stream.
4808 * @param __x A %discrete_distribution random number
4809 * generator engine.
4811 * @returns The input stream with @p __x extracted or in an error
4812 * state.
4814 template<typename _IntType1, typename _CharT, typename _Traits>
4815 friend std::basic_istream<_CharT, _Traits>&
4816 operator>>(std::basic_istream<_CharT, _Traits>&,
4817 std::discrete_distribution<_IntType1>&);
4819 private:
4820 param_type _M_param;
4824 * @brief Return true if two discrete distributions have the same
4825 * parameters.
4827 template<typename _IntType>
4828 inline bool
4829 operator==(const std::discrete_distribution<_IntType>& __d1,
4830 const std::discrete_distribution<_IntType>& __d2)
4831 { return __d1.param() == __d2.param(); }
4834 * @brief Return true if two discrete distributions have different
4835 * parameters.
4837 template<typename _IntType>
4838 inline bool
4839 operator!=(const std::discrete_distribution<_IntType>& __d1,
4840 const std::discrete_distribution<_IntType>& __d2)
4841 { return !(__d1 == __d2); }
4845 * @brief A piecewise_constant_distribution random number distribution.
4847 * The formula for the piecewise constant probability mass function is
4850 template<typename _RealType = double>
4851 class piecewise_constant_distribution
4853 static_assert(std::is_floating_point<_RealType>::value,
4854 "template argument not a floating point type");
4856 public:
4857 /** The type of the range of the distribution. */
4858 typedef _RealType result_type;
4859 /** Parameter type. */
4860 struct param_type
4862 typedef piecewise_constant_distribution<_RealType> distribution_type;
4863 friend class piecewise_constant_distribution<_RealType>;
4865 param_type()
4866 : _M_int(), _M_den(), _M_cp()
4869 template<typename _InputIteratorB, typename _InputIteratorW>
4870 param_type(_InputIteratorB __bfirst,
4871 _InputIteratorB __bend,
4872 _InputIteratorW __wbegin);
4874 template<typename _Func>
4875 param_type(initializer_list<_RealType> __bi, _Func __fw);
4877 template<typename _Func>
4878 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4879 _Func __fw);
4881 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4882 param_type(const param_type&) = default;
4883 param_type& operator=(const param_type&) = default;
4885 std::vector<_RealType>
4886 intervals() const
4888 if (_M_int.empty())
4890 std::vector<_RealType> __tmp(2);
4891 __tmp[1] = _RealType(1);
4892 return __tmp;
4894 else
4895 return _M_int;
4898 std::vector<double>
4899 densities() const
4900 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4902 friend bool
4903 operator==(const param_type& __p1, const param_type& __p2)
4904 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4906 private:
4907 void
4908 _M_initialize();
4910 std::vector<_RealType> _M_int;
4911 std::vector<double> _M_den;
4912 std::vector<double> _M_cp;
4915 explicit
4916 piecewise_constant_distribution()
4917 : _M_param()
4920 template<typename _InputIteratorB, typename _InputIteratorW>
4921 piecewise_constant_distribution(_InputIteratorB __bfirst,
4922 _InputIteratorB __bend,
4923 _InputIteratorW __wbegin)
4924 : _M_param(__bfirst, __bend, __wbegin)
4927 template<typename _Func>
4928 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4929 _Func __fw)
4930 : _M_param(__bl, __fw)
4933 template<typename _Func>
4934 piecewise_constant_distribution(size_t __nw,
4935 _RealType __xmin, _RealType __xmax,
4936 _Func __fw)
4937 : _M_param(__nw, __xmin, __xmax, __fw)
4940 explicit
4941 piecewise_constant_distribution(const param_type& __p)
4942 : _M_param(__p)
4946 * @brief Resets the distribution state.
4948 void
4949 reset()
4953 * @brief Returns a vector of the intervals.
4955 std::vector<_RealType>
4956 intervals() const
4958 if (_M_param._M_int.empty())
4960 std::vector<_RealType> __tmp(2);
4961 __tmp[1] = _RealType(1);
4962 return __tmp;
4964 else
4965 return _M_param._M_int;
4969 * @brief Returns a vector of the probability densities.
4971 std::vector<double>
4972 densities() const
4974 return _M_param._M_den.empty()
4975 ? std::vector<double>(1, 1.0) : _M_param._M_den;
4979 * @brief Returns the parameter set of the distribution.
4981 param_type
4982 param() const
4983 { return _M_param; }
4986 * @brief Sets the parameter set of the distribution.
4987 * @param __param The new parameter set of the distribution.
4989 void
4990 param(const param_type& __param)
4991 { _M_param = __param; }
4994 * @brief Returns the greatest lower bound value of the distribution.
4996 result_type
4997 min() const
4999 return _M_param._M_int.empty()
5000 ? result_type(0) : _M_param._M_int.front();
5004 * @brief Returns the least upper bound value of the distribution.
5006 result_type
5007 max() const
5009 return _M_param._M_int.empty()
5010 ? result_type(1) : _M_param._M_int.back();
5014 * @brief Generating functions.
5016 template<typename _UniformRandomNumberGenerator>
5017 result_type
5018 operator()(_UniformRandomNumberGenerator& __urng)
5019 { return this->operator()(__urng, this->param()); }
5021 template<typename _UniformRandomNumberGenerator>
5022 result_type
5023 operator()(_UniformRandomNumberGenerator& __urng,
5024 const param_type& __p);
5027 * @brief Inserts a %piecewise_constan_distribution random
5028 * number distribution @p __x into the output stream @p __os.
5030 * @param __os An output stream.
5031 * @param __x A %piecewise_constan_distribution random number
5032 * distribution.
5034 * @returns The output stream with the state of @p __x inserted or in
5035 * an error state.
5037 template<typename _RealType1, typename _CharT, typename _Traits>
5038 friend std::basic_ostream<_CharT, _Traits>&
5039 operator<<(std::basic_ostream<_CharT, _Traits>&,
5040 const std::piecewise_constant_distribution<_RealType1>&);
5043 * @brief Extracts a %piecewise_constan_distribution random
5044 * number distribution @p __x from the input stream @p __is.
5046 * @param __is An input stream.
5047 * @param __x A %piecewise_constan_distribution random number
5048 * generator engine.
5050 * @returns The input stream with @p __x extracted or in an error
5051 * state.
5053 template<typename _RealType1, typename _CharT, typename _Traits>
5054 friend std::basic_istream<_CharT, _Traits>&
5055 operator>>(std::basic_istream<_CharT, _Traits>&,
5056 std::piecewise_constant_distribution<_RealType1>&);
5058 private:
5059 param_type _M_param;
5063 * @brief Return true if two piecewise constant distributions have the
5064 * same parameters.
5066 template<typename _RealType>
5067 inline bool
5068 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
5069 const std::piecewise_constant_distribution<_RealType>& __d2)
5070 { return __d1.param() == __d2.param(); }
5073 * @brief Return true if two piecewise constant distributions have
5074 * different parameters.
5076 template<typename _RealType>
5077 inline bool
5078 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
5079 const std::piecewise_constant_distribution<_RealType>& __d2)
5080 { return !(__d1 == __d2); }
5084 * @brief A piecewise_linear_distribution random number distribution.
5086 * The formula for the piecewise linear probability mass function is
5089 template<typename _RealType = double>
5090 class piecewise_linear_distribution
5092 static_assert(std::is_floating_point<_RealType>::value,
5093 "template argument not a floating point type");
5095 public:
5096 /** The type of the range of the distribution. */
5097 typedef _RealType result_type;
5098 /** Parameter type. */
5099 struct param_type
5101 typedef piecewise_linear_distribution<_RealType> distribution_type;
5102 friend class piecewise_linear_distribution<_RealType>;
5104 param_type()
5105 : _M_int(), _M_den(), _M_cp(), _M_m()
5108 template<typename _InputIteratorB, typename _InputIteratorW>
5109 param_type(_InputIteratorB __bfirst,
5110 _InputIteratorB __bend,
5111 _InputIteratorW __wbegin);
5113 template<typename _Func>
5114 param_type(initializer_list<_RealType> __bl, _Func __fw);
5116 template<typename _Func>
5117 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5118 _Func __fw);
5120 // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5121 param_type(const param_type&) = default;
5122 param_type& operator=(const param_type&) = default;
5124 std::vector<_RealType>
5125 intervals() const
5127 if (_M_int.empty())
5129 std::vector<_RealType> __tmp(2);
5130 __tmp[1] = _RealType(1);
5131 return __tmp;
5133 else
5134 return _M_int;
5137 std::vector<double>
5138 densities() const
5139 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5141 friend bool
5142 operator==(const param_type& __p1, const param_type& __p2)
5143 { return (__p1._M_int == __p2._M_int
5144 && __p1._M_den == __p2._M_den); }
5146 private:
5147 void
5148 _M_initialize();
5150 std::vector<_RealType> _M_int;
5151 std::vector<double> _M_den;
5152 std::vector<double> _M_cp;
5153 std::vector<double> _M_m;
5156 explicit
5157 piecewise_linear_distribution()
5158 : _M_param()
5161 template<typename _InputIteratorB, typename _InputIteratorW>
5162 piecewise_linear_distribution(_InputIteratorB __bfirst,
5163 _InputIteratorB __bend,
5164 _InputIteratorW __wbegin)
5165 : _M_param(__bfirst, __bend, __wbegin)
5168 template<typename _Func>
5169 piecewise_linear_distribution(initializer_list<_RealType> __bl,
5170 _Func __fw)
5171 : _M_param(__bl, __fw)
5174 template<typename _Func>
5175 piecewise_linear_distribution(size_t __nw,
5176 _RealType __xmin, _RealType __xmax,
5177 _Func __fw)
5178 : _M_param(__nw, __xmin, __xmax, __fw)
5181 explicit
5182 piecewise_linear_distribution(const param_type& __p)
5183 : _M_param(__p)
5187 * Resets the distribution state.
5189 void
5190 reset()
5194 * @brief Return the intervals of the distribution.
5196 std::vector<_RealType>
5197 intervals() const
5199 if (_M_param._M_int.empty())
5201 std::vector<_RealType> __tmp(2);
5202 __tmp[1] = _RealType(1);
5203 return __tmp;
5205 else
5206 return _M_param._M_int;
5210 * @brief Return a vector of the probability densities of the
5211 * distribution.
5213 std::vector<double>
5214 densities() const
5216 return _M_param._M_den.empty()
5217 ? std::vector<double>(2, 1.0) : _M_param._M_den;
5221 * @brief Returns the parameter set of the distribution.
5223 param_type
5224 param() const
5225 { return _M_param; }
5228 * @brief Sets the parameter set of the distribution.
5229 * @param __param The new parameter set of the distribution.
5231 void
5232 param(const param_type& __param)
5233 { _M_param = __param; }
5236 * @brief Returns the greatest lower bound value of the distribution.
5238 result_type
5239 min() const
5241 return _M_param._M_int.empty()
5242 ? result_type(0) : _M_param._M_int.front();
5246 * @brief Returns the least upper bound value of the distribution.
5248 result_type
5249 max() const
5251 return _M_param._M_int.empty()
5252 ? result_type(1) : _M_param._M_int.back();
5256 * @brief Generating functions.
5258 template<typename _UniformRandomNumberGenerator>
5259 result_type
5260 operator()(_UniformRandomNumberGenerator& __urng)
5261 { return this->operator()(__urng, this->param()); }
5263 template<typename _UniformRandomNumberGenerator>
5264 result_type
5265 operator()(_UniformRandomNumberGenerator& __urng,
5266 const param_type& __p);
5269 * @brief Inserts a %piecewise_linear_distribution random number
5270 * distribution @p __x into the output stream @p __os.
5272 * @param __os An output stream.
5273 * @param __x A %piecewise_linear_distribution random number
5274 * distribution.
5276 * @returns The output stream with the state of @p __x inserted or in
5277 * an error state.
5279 template<typename _RealType1, typename _CharT, typename _Traits>
5280 friend std::basic_ostream<_CharT, _Traits>&
5281 operator<<(std::basic_ostream<_CharT, _Traits>&,
5282 const std::piecewise_linear_distribution<_RealType1>&);
5285 * @brief Extracts a %piecewise_linear_distribution random number
5286 * distribution @p __x from the input stream @p __is.
5288 * @param __is An input stream.
5289 * @param __x A %piecewise_linear_distribution random number
5290 * generator engine.
5292 * @returns The input stream with @p __x extracted or in an error
5293 * state.
5295 template<typename _RealType1, typename _CharT, typename _Traits>
5296 friend std::basic_istream<_CharT, _Traits>&
5297 operator>>(std::basic_istream<_CharT, _Traits>&,
5298 std::piecewise_linear_distribution<_RealType1>&);
5300 private:
5301 param_type _M_param;
5305 * @brief Return true if two piecewise linear distributions have the
5306 * same parameters.
5308 template<typename _RealType>
5309 inline bool
5310 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
5311 const std::piecewise_linear_distribution<_RealType>& __d2)
5312 { return __d1.param() == __d2.param(); }
5315 * @brief Return true if two piecewise linear distributions have
5316 * different parameters.
5318 template<typename _RealType>
5319 inline bool
5320 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
5321 const std::piecewise_linear_distribution<_RealType>& __d2)
5322 { return !(__d1 == __d2); }
5325 /* @} */ // group random_distributions_poisson
5327 /* @} */ // group random_distributions
5330 * @addtogroup random_utilities Random Number Utilities
5331 * @ingroup random
5332 * @{
5336 * @brief The seed_seq class generates sequences of seeds for random
5337 * number generators.
5339 class seed_seq
5342 public:
5343 /** The type of the seed vales. */
5344 typedef uint_least32_t result_type;
5346 /** Default constructor. */
5347 seed_seq()
5348 : _M_v()
5351 template<typename _IntType>
5352 seed_seq(std::initializer_list<_IntType> il);
5354 template<typename _InputIterator>
5355 seed_seq(_InputIterator __begin, _InputIterator __end);
5357 // generating functions
5358 template<typename _RandomAccessIterator>
5359 void
5360 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5362 // property functions
5363 size_t size() const
5364 { return _M_v.size(); }
5366 template<typename OutputIterator>
5367 void
5368 param(OutputIterator __dest) const
5369 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5371 private:
5373 std::vector<result_type> _M_v;
5376 /* @} */ // group random_utilities
5378 /* @} */ // group random
5379 _GLIBCXX_END_NAMESPACE
5381 #endif