2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / libstdc++-v3 / include / bits / random.h
blob528a04a091185e73aab243ca72c630be3361800c
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 * You should not attempt to use it directly.
31 #include <vector>
33 namespace std
35 // [26.4] Random number generation
37 /**
38 * @addtogroup std_random Random Number Generation
39 * A facility for generating random numbers on selected distributions.
40 * @{
43 /**
44 * @brief A function template for converting the output of a (integral)
45 * uniform random number generator to a floatng point result in the range
46 * [0-1).
48 template<typename _RealType, size_t __bits,
49 typename _UniformRandomNumberGenerator>
50 _RealType
51 generate_canonical(_UniformRandomNumberGenerator& __g);
54 * Implementation-space details.
56 namespace __detail
58 template<typename _UIntType, size_t __w,
59 bool = __w < static_cast<size_t>
60 (std::numeric_limits<_UIntType>::digits)>
61 struct _Shift
62 { static const _UIntType __value = 0; };
64 template<typename _UIntType, size_t __w>
65 struct _Shift<_UIntType, __w, true>
66 { static const _UIntType __value = _UIntType(1) << __w; };
68 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
69 struct _Mod;
71 // Dispatch based on modulus value to prevent divide-by-zero compile-time
72 // errors when m == 0.
73 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
74 inline _Tp
75 __mod(_Tp __x)
76 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
79 * An adaptor class for converting the output of any Generator into
80 * the input for a specific Distribution.
82 template<typename _Engine, typename _DInputType>
83 struct _Adaptor
86 public:
87 _Adaptor(_Engine& __g)
88 : _M_g(__g) { }
90 _DInputType
91 min() const
92 { return _DInputType(0); }
94 _DInputType
95 max() const
96 { return _DInputType(1); }
99 * Converts a value generated by the adapted random number generator
100 * into a value in the input domain for the dependent random number
101 * distribution.
103 _DInputType
104 operator()()
106 return std::generate_canonical<_DInputType,
107 std::numeric_limits<_DInputType>::digits,
108 _Engine>(_M_g);
111 private:
112 _Engine& _M_g;
114 } // namespace __detail
117 * @addtogroup std_random_generators Random Number Generators
118 * @ingroup std_random
120 * These classes define objects which provide random or pseudorandom
121 * numbers, either from a discrete or a continuous interval. The
122 * random number generator supplied as a part of this library are
123 * all uniform random number generators which provide a sequence of
124 * random number uniformly distributed over their range.
126 * A number generator is a function object with an operator() that
127 * takes zero arguments and returns a number.
129 * A compliant random number generator must satisfy the following
130 * requirements. <table border=1 cellpadding=10 cellspacing=0>
131 * <caption align=top>Random Number Generator Requirements</caption>
132 * <tr><td>To be documented.</td></tr> </table>
134 * @{
138 * @brief A model of a linear congruential random number generator.
140 * A random number generator that produces pseudorandom numbers using the
141 * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
143 * The template parameter @p _UIntType must be an unsigned integral type
144 * large enough to store values up to (__m-1). If the template parameter
145 * @p __m is 0, the modulus @p __m used is
146 * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
147 * parameters @p __a and @p __c must be less than @p __m.
149 * The size of the state is @f$ 1 @f$.
151 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
152 class linear_congruential_engine
154 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
155 "substituting _UIntType not an unsigned integral type");
156 static_assert(__m == 0u || (__a < __m && __c < __m),
157 "template argument substituting __m out of bounds");
159 public:
160 /** The type of the generated random value. */
161 typedef _UIntType result_type;
163 /** The multiplier. */
164 static const result_type multiplier = __a;
165 /** An increment. */
166 static const result_type increment = __c;
167 /** The modulus. */
168 static const result_type modulus = __m;
169 static const result_type default_seed = 1u;
172 * @brief Constructs a %linear_congruential_engine random number
173 * generator engine with seed @p __s. The default seed value
174 * is 1.
176 * @param __s The initial seed value.
178 explicit
179 linear_congruential_engine(result_type __s = default_seed)
180 { seed(__s); }
183 * @brief Constructs a %linear_congruential_engine random number
184 * generator engine seeded from the seed sequence @p __q.
186 * @param __q the seed sequence.
188 template<typename _Sseq, typename
189 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
190 explicit
191 linear_congruential_engine(_Sseq& __q)
192 { seed<_Sseq>(__q); }
195 * @brief Reseeds the %linear_congruential_engine random number generator
196 * engine sequence to the seed @p __s.
198 * @param __s The new seed.
200 void
201 seed(result_type __s = default_seed);
204 * @brief Reseeds the %linear_congruential_engine random number generator
205 * engine
206 * sequence using values from the seed sequence @p __q.
208 * @param __q the seed sequence.
210 template<typename _Sseq, typename
211 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
212 void
213 seed(_Sseq& __q);
216 * @brief Gets the smallest possible value in the output range.
218 * The minimum depends on the @p __c parameter: if it is zero, the
219 * minimum generated must be > 0, otherwise 0 is allowed.
221 * @todo This should be constexpr.
223 result_type
224 min() const
225 { return __c == 0u ? 1u : 0u; }
228 * @brief Gets the largest possible value in the output range.
230 * @todo This should be constexpr.
232 result_type
233 max() const
234 { return __m - 1u; }
237 * @brief Discard a sequence of random numbers.
239 * @todo Look for a faster way to do discard.
241 void
242 discard(unsigned long long __z)
244 for (; __z != 0ULL; --__z)
245 (*this)();
249 * @brief Gets the next random number in the sequence.
251 result_type
252 operator()()
254 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
255 return _M_x;
259 * @brief Compares two linear congruential random number generator
260 * objects of the same type for equality.
262 * @param __lhs A linear congruential random number generator object.
263 * @param __rhs Another linear congruential random number generator
264 * object.
266 * @returns true if the two objects are equal, false otherwise.
268 friend bool
269 operator==(const linear_congruential_engine& __lhs,
270 const linear_congruential_engine& __rhs)
271 { return __lhs._M_x == __rhs._M_x; }
274 * @brief Writes the textual representation of the state x(i) of x to
275 * @p __os.
277 * @param __os The output stream.
278 * @param __lcr A % linear_congruential_engine random number generator.
279 * @returns __os.
281 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
282 _UIntType1 __m1, typename _CharT, typename _Traits>
283 friend std::basic_ostream<_CharT, _Traits>&
284 operator<<(std::basic_ostream<_CharT, _Traits>&,
285 const std::linear_congruential_engine<_UIntType1,
286 __a1, __c1, __m1>&);
289 * @brief Sets the state of the engine by reading its textual
290 * representation from @p __is.
292 * The textual representation must have been previously written using
293 * an output stream whose imbued locale and whose type's template
294 * specialization arguments _CharT and _Traits were the same as those
295 * of @p __is.
297 * @param __is The input stream.
298 * @param __lcr A % linear_congruential_engine random number generator.
299 * @returns __is.
301 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
302 _UIntType1 __m1, typename _CharT, typename _Traits>
303 friend std::basic_istream<_CharT, _Traits>&
304 operator>>(std::basic_istream<_CharT, _Traits>&,
305 std::linear_congruential_engine<_UIntType1, __a1,
306 __c1, __m1>&);
308 private:
309 _UIntType _M_x;
314 * A generalized feedback shift register discrete random number generator.
316 * This algorithm avoids multiplication and division and is designed to be
317 * friendly to a pipelined architecture. If the parameters are chosen
318 * correctly, this generator will produce numbers with a very long period and
319 * fairly good apparent entropy, although still not cryptographically strong.
321 * The best way to use this generator is with the predefined mt19937 class.
323 * This algorithm was originally invented by Makoto Matsumoto and
324 * Takuji Nishimura.
326 * @var word_size The number of bits in each element of the state vector.
327 * @var state_size The degree of recursion.
328 * @var shift_size The period parameter.
329 * @var mask_bits The separation point bit index.
330 * @var parameter_a The last row of the twist matrix.
331 * @var output_u The first right-shift tempering matrix parameter.
332 * @var output_s The first left-shift tempering matrix parameter.
333 * @var output_b The first left-shift tempering matrix mask.
334 * @var output_t The second left-shift tempering matrix parameter.
335 * @var output_c The second left-shift tempering matrix mask.
336 * @var output_l The second right-shift tempering matrix parameter.
338 template<typename _UIntType, size_t __w,
339 size_t __n, size_t __m, size_t __r,
340 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
341 _UIntType __b, size_t __t,
342 _UIntType __c, size_t __l, _UIntType __f>
343 class mersenne_twister_engine
345 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
346 "substituting _UIntType not an unsigned integral type");
347 static_assert(1u <= __m && __m <= __n,
348 "template argument substituting __m out of bounds");
349 static_assert(__r <= __w, "template argument substituting "
350 "__r out of bound");
351 static_assert(__u <= __w, "template argument substituting "
352 "__u out of bound");
353 static_assert(__s <= __w, "template argument substituting "
354 "__s out of bound");
355 static_assert(__t <= __w, "template argument substituting "
356 "__t out of bound");
357 static_assert(__l <= __w, "template argument substituting "
358 "__l out of bound");
359 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
360 "template argument substituting __w out of bound");
361 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
362 "template argument substituting __a out of bound");
363 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
364 "template argument substituting __b out of bound");
365 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
366 "template argument substituting __c out of bound");
367 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
368 "template argument substituting __d out of bound");
369 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
370 "template argument substituting __f out of bound");
372 public:
373 /** The type of the generated random value. */
374 typedef _UIntType result_type;
376 // parameter values
377 static const size_t word_size = __w;
378 static const size_t state_size = __n;
379 static const size_t shift_size = __m;
380 static const size_t mask_bits = __r;
381 static const result_type xor_mask = __a;
382 static const size_t tempering_u = __u;
383 static const result_type tempering_d = __d;
384 static const size_t tempering_s = __s;
385 static const result_type tempering_b = __b;
386 static const size_t tempering_t = __t;
387 static const result_type tempering_c = __c;
388 static const size_t tempering_l = __l;
389 static const result_type initialization_multiplier = __f;
390 static const result_type default_seed = 5489u;
392 // constructors and member function
393 explicit
394 mersenne_twister_engine(result_type __sd = default_seed)
395 { seed(__sd); }
398 * @brief Constructs a %mersenne_twister_engine random number generator
399 * engine seeded from the seed sequence @p __q.
401 * @param __q the seed sequence.
403 template<typename _Sseq, typename
404 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
405 explicit
406 mersenne_twister_engine(_Sseq& __q)
407 { seed<_Sseq>(__q); }
409 void
410 seed(result_type __sd = default_seed);
412 template<typename _Sseq, typename
413 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
414 void
415 seed(_Sseq& __q);
418 * @brief Gets the smallest possible value in the output range.
420 * @todo This should be constexpr.
422 result_type
423 min() const
424 { return 0; };
427 * @brief Gets the largest possible value in the output range.
429 * @todo This should be constexpr.
431 result_type
432 max() const
433 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
436 * @brief Discard a sequence of random numbers.
438 * @todo Look for a faster way to do discard.
440 void
441 discard(unsigned long long __z)
443 for (; __z != 0ULL; --__z)
444 (*this)();
447 result_type
448 operator()();
451 * @brief Compares two % mersenne_twister_engine random number generator
452 * objects of the same type for equality.
454 * @param __lhs A % mersenne_twister_engine random number generator
455 * object.
456 * @param __rhs Another % mersenne_twister_engine random number
457 * generator object.
459 * @returns true if the two objects are equal, false otherwise.
461 friend bool
462 operator==(const mersenne_twister_engine& __lhs,
463 const mersenne_twister_engine& __rhs)
464 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
467 * @brief Inserts the current state of a % mersenne_twister_engine
468 * random number generator engine @p __x into the output stream
469 * @p __os.
471 * @param __os An output stream.
472 * @param __x A % mersenne_twister_engine random number generator
473 * engine.
475 * @returns The output stream with the state of @p __x inserted or in
476 * an error state.
478 template<typename _UIntType1,
479 size_t __w1, size_t __n1,
480 size_t __m1, size_t __r1,
481 _UIntType1 __a1, size_t __u1,
482 _UIntType1 __d1, size_t __s1,
483 _UIntType1 __b1, size_t __t1,
484 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
485 typename _CharT, typename _Traits>
486 friend std::basic_ostream<_CharT, _Traits>&
487 operator<<(std::basic_ostream<_CharT, _Traits>&,
488 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
489 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
490 __l1, __f1>&);
493 * @brief Extracts the current state of a % mersenne_twister_engine
494 * random number generator engine @p __x from the input stream
495 * @p __is.
497 * @param __is An input stream.
498 * @param __x A % mersenne_twister_engine random number generator
499 * engine.
501 * @returns The input stream with the state of @p __x extracted or in
502 * an error state.
504 template<typename _UIntType1,
505 size_t __w1, size_t __n1,
506 size_t __m1, size_t __r1,
507 _UIntType1 __a1, size_t __u1,
508 _UIntType1 __d1, size_t __s1,
509 _UIntType1 __b1, size_t __t1,
510 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
511 typename _CharT, typename _Traits>
512 friend std::basic_istream<_CharT, _Traits>&
513 operator>>(std::basic_istream<_CharT, _Traits>&,
514 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
515 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
516 __l1, __f1>&);
518 private:
519 _UIntType _M_x[state_size];
520 size_t _M_p;
524 * @brief The Marsaglia-Zaman generator.
526 * This is a model of a Generalized Fibonacci discrete random number
527 * generator, sometimes referred to as the SWC generator.
529 * A discrete random number generator that produces pseudorandom
530 * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} -
531 * carry_{i-1}) \bmod m @f$.
533 * The size of the state is @f$ r @f$
534 * and the maximum period of the generator is @f$ m^r - m^s - 1 @f$.
536 * @var _M_x The state of the generator. This is a ring buffer.
537 * @var _M_carry The carry.
538 * @var _M_p Current index of x(i - r).
540 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
541 class subtract_with_carry_engine
543 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
544 "substituting _UIntType not an unsigned integral type");
545 static_assert(0u < __s && __s < __r,
546 "template argument substituting __s out of bounds");
547 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
548 "template argument substituting __w out of bounds");
550 public:
551 /** The type of the generated random value. */
552 typedef _UIntType result_type;
554 // parameter values
555 static const size_t word_size = __w;
556 static const size_t short_lag = __s;
557 static const size_t long_lag = __r;
558 static const result_type default_seed = 19780503u;
561 * @brief Constructs an explicitly seeded % subtract_with_carry_engine
562 * random number generator.
564 explicit
565 subtract_with_carry_engine(result_type __sd = default_seed)
566 { seed(__sd); }
569 * @brief Constructs a %subtract_with_carry_engine random number engine
570 * seeded from the seed sequence @p __q.
572 * @param __q the seed sequence.
574 template<typename _Sseq, typename
575 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
576 explicit
577 subtract_with_carry_engine(_Sseq& __q)
578 { seed<_Sseq>(__q); }
581 * @brief Seeds the initial state @f$ x_0 @f$ of the random number
582 * generator.
584 * N1688[4.19] modifies this as follows. If @p __value == 0,
585 * sets value to 19780503. In any case, with a linear
586 * congruential generator lcg(i) having parameters @f$ m_{lcg} =
587 * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
588 * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
589 * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
590 * set carry to 1, otherwise sets carry to 0.
592 void
593 seed(result_type __sd = default_seed);
596 * @brief Seeds the initial state @f$ x_0 @f$ of the
597 * % subtract_with_carry_engine random number generator.
599 template<typename _Sseq, typename
600 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
601 void
602 seed(_Sseq& __q);
605 * @brief Gets the inclusive minimum value of the range of random
606 * integers returned by this generator.
608 * @todo This should be constexpr.
610 result_type
611 min() const
612 { return 0; }
615 * @brief Gets the inclusive maximum value of the range of random
616 * integers returned by this generator.
618 * @todo This should be constexpr.
620 result_type
621 max() const
622 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
625 * @brief Discard a sequence of random numbers.
627 * @todo Look for a faster way to do discard.
629 void
630 discard(unsigned long long __z)
632 for (; __z != 0ULL; --__z)
633 (*this)();
637 * @brief Gets the next random number in the sequence.
639 result_type
640 operator()();
643 * @brief Compares two % subtract_with_carry_engine random number
644 * generator objects of the same type for equality.
646 * @param __lhs A % subtract_with_carry_engine random number generator
647 * object.
648 * @param __rhs Another % subtract_with_carry_engine random number
649 * generator object.
651 * @returns true if the two objects are equal, false otherwise.
653 friend bool
654 operator==(const subtract_with_carry_engine& __lhs,
655 const subtract_with_carry_engine& __rhs)
656 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
659 * @brief Inserts the current state of a % subtract_with_carry_engine
660 * random number generator engine @p __x into the output stream
661 * @p __os.
663 * @param __os An output stream.
664 * @param __x A % subtract_with_carry_engine random number generator
665 * engine.
667 * @returns The output stream with the state of @p __x inserted or in
668 * an error state.
670 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
671 typename _CharT, typename _Traits>
672 friend std::basic_ostream<_CharT, _Traits>&
673 operator<<(std::basic_ostream<_CharT, _Traits>&,
674 const std::subtract_with_carry_engine<_UIntType1, __w1,
675 __s1, __r1>&);
678 * @brief Extracts the current state of a % subtract_with_carry_engine
679 * random number generator engine @p __x from the input stream
680 * @p __is.
682 * @param __is An input stream.
683 * @param __x A % subtract_with_carry_engine random number generator
684 * engine.
686 * @returns The input stream with the state of @p __x extracted or in
687 * an error state.
689 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
690 typename _CharT, typename _Traits>
691 friend std::basic_istream<_CharT, _Traits>&
692 operator>>(std::basic_istream<_CharT, _Traits>&,
693 std::subtract_with_carry_engine<_UIntType1, __w1,
694 __s1, __r1>&);
696 private:
697 _UIntType _M_x[long_lag];
698 _UIntType _M_carry;
699 size_t _M_p;
703 * Produces random numbers from some base engine by discarding blocks of
704 * data.
706 * 0 <= @p __r <= @p __p
708 template<typename _RandomNumberEngine, size_t __p, size_t __r>
709 class discard_block_engine
711 static_assert(1 <= __r && __r <= __p,
712 "template argument substituting __r out of bounds");
714 public:
715 /** The type of the generated random value. */
716 typedef typename _RandomNumberEngine::result_type result_type;
718 // parameter values
719 static const size_t block_size = __p;
720 static const size_t used_block = __r;
723 * @brief Constructs a default %discard_block_engine engine.
725 * The underlying engine is default constructed as well.
727 discard_block_engine()
728 : _M_b(), _M_n(0) { }
731 * @brief Copy constructs a %discard_block_engine engine.
733 * Copies an existing base class random number generator.
734 * @param rng An existing (base class) engine object.
736 explicit
737 discard_block_engine(const _RandomNumberEngine& __rne)
738 : _M_b(__rne), _M_n(0) { }
741 * @brief Move constructs a %discard_block_engine engine.
743 * Copies an existing base class random number generator.
744 * @param rng An existing (base class) engine object.
746 explicit
747 discard_block_engine(_RandomNumberEngine&& __rne)
748 : _M_b(std::move(__rne)), _M_n(0) { }
751 * @brief Seed constructs a %discard_block_engine engine.
753 * Constructs the underlying generator engine seeded with @p __s.
754 * @param __s A seed value for the base class engine.
756 explicit
757 discard_block_engine(result_type __s)
758 : _M_b(__s), _M_n(0) { }
761 * @brief Generator construct a %discard_block_engine engine.
763 * @param __q A seed sequence.
765 template<typename _Sseq, typename
766 = typename std::enable_if<std::is_class<_Sseq>::value
767 && !std::is_same<_Sseq, _RandomNumberEngine>
768 ::value>::type>
769 explicit
770 discard_block_engine(_Sseq& __q)
771 : _M_b(__q), _M_n(0)
775 * @brief Reseeds the %discard_block_engine object with the default
776 * seed for the underlying base class generator engine.
778 void
779 seed()
781 _M_b.seed();
782 _M_n = 0;
786 * @brief Reseeds the %discard_block_engine object with the default
787 * seed for the underlying base class generator engine.
789 void
790 seed(result_type __s)
792 _M_b.seed(__s);
793 _M_n = 0;
797 * @brief Reseeds the %discard_block_engine object with the given seed
798 * sequence.
799 * @param __q A seed generator function.
801 template<typename _Sseq, typename
802 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
803 void
804 seed(_Sseq& __q)
806 _M_b.seed<_Sseq>(__q);
807 _M_n = 0;
811 * @brief Gets a const reference to the underlying generator engine
812 * object.
814 const _RandomNumberEngine&
815 base() const
816 { return _M_b; }
819 * @brief Gets the minimum value in the generated random number range.
821 * @todo This should be constexpr.
823 result_type
824 min() const
825 { return _M_b.min(); }
828 * @brief Gets the maximum value in the generated random number range.
830 * @todo This should be constexpr.
832 result_type
833 max() const
834 { return _M_b.max(); }
837 * @brief Discard a sequence of random numbers.
839 * @todo Look for a faster way to do discard.
841 void
842 discard(unsigned long long __z)
844 for (; __z != 0ULL; --__z)
845 (*this)();
849 * @brief Gets the next value in the generated random number sequence.
851 result_type
852 operator()();
855 * @brief Compares two %discard_block_engine random number generator
856 * objects of the same type for equality.
858 * @param __lhs A %discard_block_engine random number generator object.
859 * @param __rhs Another %discard_block_engine random number generator
860 * object.
862 * @returns true if the two objects are equal, false otherwise.
864 friend bool
865 operator==(const discard_block_engine& __lhs,
866 const discard_block_engine& __rhs)
867 { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
870 * @brief Inserts the current state of a %discard_block_engine random
871 * number generator engine @p __x into the output stream
872 * @p __os.
874 * @param __os An output stream.
875 * @param __x A %discard_block_engine random number generator engine.
877 * @returns The output stream with the state of @p __x inserted or in
878 * an error state.
880 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
881 typename _CharT, typename _Traits>
882 friend std::basic_ostream<_CharT, _Traits>&
883 operator<<(std::basic_ostream<_CharT, _Traits>&,
884 const std::discard_block_engine<_RandomNumberEngine1,
885 __p1, __r1>&);
888 * @brief Extracts the current state of a % subtract_with_carry_engine
889 * random number generator engine @p __x from the input stream
890 * @p __is.
892 * @param __is An input stream.
893 * @param __x A %discard_block_engine random number generator engine.
895 * @returns The input stream with the state of @p __x extracted or in
896 * an error state.
898 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
899 typename _CharT, typename _Traits>
900 friend std::basic_istream<_CharT, _Traits>&
901 operator>>(std::basic_istream<_CharT, _Traits>&,
902 std::discard_block_engine<_RandomNumberEngine1,
903 __p1, __r1>&);
905 private:
906 _RandomNumberEngine _M_b;
907 size_t _M_n;
911 * Produces random numbers by combining random numbers from some base
912 * engine to produce random numbers with a specifies number of bits @p __w.
914 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
915 class independent_bits_engine
917 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
918 "substituting _UIntType not an unsigned integral type");
919 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
920 "template argument substituting __w out of bounds");
922 public:
923 /** The type of the generated random value. */
924 typedef _UIntType result_type;
927 * @brief Constructs a default %independent_bits_engine engine.
929 * The underlying engine is default constructed as well.
931 independent_bits_engine()
932 : _M_b() { }
935 * @brief Copy constructs a %independent_bits_engine engine.
937 * Copies an existing base class random number generator.
938 * @param rng An existing (base class) engine object.
940 explicit
941 independent_bits_engine(const _RandomNumberEngine& __rne)
942 : _M_b(__rne) { }
945 * @brief Move constructs a %independent_bits_engine engine.
947 * Copies an existing base class random number generator.
948 * @param rng An existing (base class) engine object.
950 explicit
951 independent_bits_engine(_RandomNumberEngine&& __rne)
952 : _M_b(std::move(__rne)) { }
955 * @brief Seed constructs a %independent_bits_engine engine.
957 * Constructs the underlying generator engine seeded with @p __s.
958 * @param __s A seed value for the base class engine.
960 explicit
961 independent_bits_engine(result_type __s)
962 : _M_b(__s) { }
965 * @brief Generator construct a %independent_bits_engine engine.
967 * @param __q A seed sequence.
969 template<typename _Sseq, typename
970 = typename std::enable_if<std::is_class<_Sseq>::value
971 && !std::is_same<_Sseq, _RandomNumberEngine>
972 ::value>::type>
973 explicit
974 independent_bits_engine(_Sseq& __q)
975 : _M_b(__q)
979 * @brief Reseeds the %independent_bits_engine object with the default
980 * seed for the underlying base class generator engine.
982 void
983 seed()
984 { _M_b.seed(); }
987 * @brief Reseeds the %independent_bits_engine object with the default
988 * seed for the underlying base class generator engine.
990 void
991 seed(result_type __s)
992 { _M_b.seed(__s); }
995 * @brief Reseeds the %independent_bits_engine object with the given
996 * seed sequence.
997 * @param __q A seed generator function.
999 template<typename _Sseq, typename
1000 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
1001 void
1002 seed(_Sseq& __q)
1003 { _M_b.seed<_Sseq>(__q); }
1006 * @brief Gets a const reference to the underlying generator engine
1007 * object.
1009 const _RandomNumberEngine&
1010 base() const
1011 { return _M_b; }
1014 * @brief Gets the minimum value in the generated random number range.
1016 * @todo This should be constexpr.
1018 result_type
1019 min() const
1020 { return 0U; }
1023 * @brief Gets the maximum value in the generated random number range.
1025 * @todo This should be constexpr.
1027 result_type
1028 max() const
1029 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1032 * @brief Discard a sequence of random numbers.
1034 * @todo Look for a faster way to do discard.
1036 void
1037 discard(unsigned long long __z)
1039 for (; __z != 0ULL; --__z)
1040 (*this)();
1044 * @brief Gets the next value in the generated random number sequence.
1046 result_type
1047 operator()();
1050 * @brief Compares two %independent_bits_engine random number generator
1051 * objects of the same type for equality.
1053 * @param __lhs A %independent_bits_engine random number generator
1054 * object.
1055 * @param __rhs Another %independent_bits_engine random number generator
1056 * object.
1058 * @returns true if the two objects are equal, false otherwise.
1060 friend bool
1061 operator==(const independent_bits_engine& __lhs,
1062 const independent_bits_engine& __rhs)
1063 { return __lhs._M_b == __rhs._M_b; }
1066 * @brief Extracts the current state of a % subtract_with_carry_engine
1067 * random number generator engine @p __x from the input stream
1068 * @p __is.
1070 * @param __is An input stream.
1071 * @param __x A %independent_bits_engine random number generator
1072 * engine.
1074 * @returns The input stream with the state of @p __x extracted or in
1075 * an error state.
1077 template<typename _CharT, typename _Traits>
1078 friend std::basic_istream<_CharT, _Traits>&
1079 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1080 std::independent_bits_engine<_RandomNumberEngine,
1081 __w, _UIntType>& __x)
1083 __is >> __x._M_b;
1084 return __is;
1087 private:
1088 _RandomNumberEngine _M_b;
1092 * @brief Inserts the current state of a %independent_bits_engine random
1093 * number generator engine @p __x into the output stream @p __os.
1095 * @param __os An output stream.
1096 * @param __x A %independent_bits_engine random number generator engine.
1098 * @returns The output stream with the state of @p __x inserted or in
1099 * an error state.
1101 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1102 typename _CharT, typename _Traits>
1103 std::basic_ostream<_CharT, _Traits>&
1104 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1105 const std::independent_bits_engine<_RandomNumberEngine,
1106 __w, _UIntType>& __x)
1108 __os << __x.base();
1109 return __os;
1113 * @brief Produces random numbers by combining random numbers from some
1114 * base engine to produce random numbers with a specifies number of bits
1115 * @p __w.
1117 template<typename _RandomNumberEngine, size_t __k>
1118 class shuffle_order_engine
1120 static_assert(1u <= __k, "template argument substituting "
1121 "__k out of bound");
1123 public:
1124 /** The type of the generated random value. */
1125 typedef typename _RandomNumberEngine::result_type result_type;
1127 static const size_t table_size = __k;
1130 * @brief Constructs a default %shuffle_order_engine engine.
1132 * The underlying engine is default constructed as well.
1134 shuffle_order_engine()
1135 : _M_b()
1136 { _M_initialize(); }
1139 * @brief Copy constructs a %shuffle_order_engine engine.
1141 * Copies an existing base class random number generator.
1142 * @param rng An existing (base class) engine object.
1144 explicit
1145 shuffle_order_engine(const _RandomNumberEngine& __rne)
1146 : _M_b(__rne)
1147 { _M_initialize(); }
1150 * @brief Move constructs a %shuffle_order_engine engine.
1152 * Copies an existing base class random number generator.
1153 * @param rng An existing (base class) engine object.
1155 explicit
1156 shuffle_order_engine(_RandomNumberEngine&& __rne)
1157 : _M_b(std::move(__rne))
1158 { _M_initialize(); }
1161 * @brief Seed constructs a %shuffle_order_engine engine.
1163 * Constructs the underlying generator engine seeded with @p __s.
1164 * @param __s A seed value for the base class engine.
1166 explicit
1167 shuffle_order_engine(result_type __s)
1168 : _M_b(__s)
1169 { _M_initialize(); }
1172 * @brief Generator construct a %shuffle_order_engine engine.
1174 * @param __q A seed sequence.
1176 template<typename _Sseq, typename
1177 = typename std::enable_if<std::is_class<_Sseq>::value
1178 && !std::is_same<_Sseq, _RandomNumberEngine>
1179 ::value>::type>
1180 explicit
1181 shuffle_order_engine(_Sseq& __q)
1182 : _M_b(__q)
1183 { _M_initialize(); }
1186 * @brief Reseeds the %shuffle_order_engine object with the default seed
1187 for the underlying base class generator engine.
1189 void
1190 seed()
1192 _M_b.seed();
1193 _M_initialize();
1197 * @brief Reseeds the %shuffle_order_engine object with the default seed
1198 * for the underlying base class generator engine.
1200 void
1201 seed(result_type __s)
1203 _M_b.seed(__s);
1204 _M_initialize();
1208 * @brief Reseeds the %shuffle_order_engine object with the given seed
1209 * sequence.
1210 * @param __q A seed generator function.
1212 template<typename _Sseq, typename
1213 = typename std::enable_if<std::is_class<_Sseq>::value>::type>
1214 void
1215 seed(_Sseq& __q)
1217 _M_b.seed<_Sseq>(__q);
1218 _M_initialize();
1222 * Gets a const reference to the underlying generator engine object.
1224 const _RandomNumberEngine&
1225 base() const
1226 { return _M_b; }
1229 * Gets the minimum value in the generated random number range.
1231 * @todo This should be constexpr.
1233 result_type
1234 min() const
1235 { return _M_b.min(); }
1238 * Gets the maximum value in the generated random number range.
1240 * @todo This should be constexpr.
1242 result_type
1243 max() const
1244 { return _M_b.max(); }
1247 * Discard a sequence of random numbers.
1249 * @todo Look for a faster way to do discard.
1251 void
1252 discard(unsigned long long __z)
1254 for (; __z != 0ULL; --__z)
1255 (*this)();
1259 * Gets the next value in the generated random number sequence.
1261 result_type
1262 operator()();
1265 * Compares two %shuffle_order_engine random number generator objects
1266 * of the same type for equality.
1268 * @param __lhs A %shuffle_order_engine random number generator object.
1269 * @param __rhs Another %shuffle_order_engine random number generator
1270 * object.
1272 * @returns true if the two objects are equal, false otherwise.
1274 friend bool
1275 operator==(const shuffle_order_engine& __lhs,
1276 const shuffle_order_engine& __rhs)
1277 { return __lhs._M_b == __rhs._M_b; }
1280 * @brief Inserts the current state of a %shuffle_order_engine random
1281 * number generator engine @p __x into the output stream
1282 @p __os.
1284 * @param __os An output stream.
1285 * @param __x A %shuffle_order_engine random number generator engine.
1287 * @returns The output stream with the state of @p __x inserted or in
1288 * an error state.
1290 template<typename _RandomNumberEngine1, size_t __k1,
1291 typename _CharT, typename _Traits>
1292 friend std::basic_ostream<_CharT, _Traits>&
1293 operator<<(std::basic_ostream<_CharT, _Traits>&,
1294 const std::shuffle_order_engine<_RandomNumberEngine1,
1295 __k1>&);
1298 * @brief Extracts the current state of a % subtract_with_carry_engine
1299 * random number generator engine @p __x from the input stream
1300 * @p __is.
1302 * @param __is An input stream.
1303 * @param __x A %shuffle_order_engine random number generator engine.
1305 * @returns The input stream with the state of @p __x extracted or in
1306 * an error state.
1308 template<typename _RandomNumberEngine1, size_t __k1,
1309 typename _CharT, typename _Traits>
1310 friend std::basic_istream<_CharT, _Traits>&
1311 operator>>(std::basic_istream<_CharT, _Traits>&,
1312 std::shuffle_order_engine<_RandomNumberEngine1, __k1>&);
1314 private:
1315 void _M_initialize()
1317 for (size_t __i = 0; __i < __k; ++__i)
1318 _M_v[__i] = _M_b();
1319 _M_y = _M_b();
1322 _RandomNumberEngine _M_b;
1323 result_type _M_v[__k];
1324 result_type _M_y;
1328 * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1330 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1331 minstd_rand0;
1334 * An alternative LCR (Lehmer Generator function) .
1336 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
1337 minstd_rand;
1340 * The classic Mersenne Twister.
1342 * Reference:
1343 * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
1344 * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
1345 * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1347 typedef mersenne_twister_engine<
1348 uint_fast32_t,
1349 32, 624, 397, 31,
1350 0x9908b0dfUL, 11,
1351 0xffffffffUL, 7,
1352 0x9d2c5680UL, 15,
1353 0xefc60000UL, 18, 1812433253UL> mt19937;
1356 * An alternative Mersenne Twister.
1358 typedef mersenne_twister_engine<
1359 uint_fast64_t,
1360 64, 312, 156, 31,
1361 0xb5026f5aa96619e9ULL, 29,
1362 0x5555555555555555ULL, 17,
1363 0x71d67fffeda60000ULL, 37,
1364 0xfff7eee000000000ULL, 43,
1365 6364136223846793005ULL> mt19937_64;
1370 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1371 ranlux24_base;
1373 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1374 ranlux48_base;
1376 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
1378 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
1383 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
1388 typedef minstd_rand0 default_random_engine;
1391 * A standard interface to a platform-specific non-deterministic
1392 * random number generator (if any are available).
1394 class random_device
1396 public:
1397 /** The type of the generated random value. */
1398 typedef unsigned int result_type;
1400 // constructors, destructors and member functions
1402 #ifdef _GLIBCXX_USE_RANDOM_TR1
1404 explicit
1405 random_device(const std::string& __token = "/dev/urandom")
1407 if ((__token != "/dev/urandom" && __token != "/dev/random")
1408 || !(_M_file = std::fopen(__token.c_str(), "rb")))
1409 std::__throw_runtime_error(__N("random_device::"
1410 "random_device(const std::string&)"));
1413 ~random_device()
1414 { std::fclose(_M_file); }
1416 #else
1418 explicit
1419 random_device(const std::string& __token = "mt19937")
1420 : _M_mt(_M_strtoul(__token)) { }
1422 private:
1423 static unsigned long
1424 _M_strtoul(const std::string& __str)
1426 unsigned long __ret = 5489UL;
1427 if (__str != "mt19937")
1429 const char* __nptr = __str.c_str();
1430 char* __endptr;
1431 __ret = std::strtoul(__nptr, &__endptr, 0);
1432 if (*__nptr == '\0' || *__endptr != '\0')
1433 std::__throw_runtime_error(__N("random_device::_M_strtoul"
1434 "(const std::string&)"));
1436 return __ret;
1439 public:
1441 #endif
1443 result_type
1444 min() const
1445 { return std::numeric_limits<result_type>::min(); }
1447 result_type
1448 max() const
1449 { return std::numeric_limits<result_type>::max(); }
1451 double
1452 entropy() const
1453 { return 0.0; }
1455 result_type
1456 operator()()
1458 #ifdef _GLIBCXX_USE_RANDOM_TR1
1459 result_type __ret;
1460 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1461 1, _M_file);
1462 return __ret;
1463 #else
1464 return _M_mt();
1465 #endif
1468 // No copy functions.
1469 random_device(const random_device&) = delete;
1470 void operator=(const random_device&) = delete;
1472 private:
1474 #ifdef _GLIBCXX_USE_RANDOM_TR1
1475 FILE* _M_file;
1476 #else
1477 mt19937 _M_mt;
1478 #endif
1481 /* @} */ // group std_random_generators
1484 * @addtogroup std_random_distributions Random Number Distributions
1485 * @ingroup std_random
1486 * @{
1490 * @addtogroup std_random_distributions_uniform Uniform Distributions
1491 * @ingroup std_random_distributions
1492 * @{
1496 * @brief Uniform discrete distribution for random numbers.
1497 * A discrete random distribution on the range @f$[min, max]@f$ with equal
1498 * probability throughout the range.
1500 template<typename _IntType = int>
1501 class uniform_int_distribution
1503 static_assert(std::is_integral<_IntType>::value,
1504 "template argument not an integral type");
1506 public:
1507 /** The type of the range of the distribution. */
1508 typedef _IntType result_type;
1509 /** Parameter type. */
1510 struct param_type
1512 typedef uniform_int_distribution<_IntType> distribution_type;
1514 explicit
1515 param_type(_IntType __a = 0,
1516 _IntType __b = std::numeric_limits<_IntType>::max())
1517 : _M_a(__a), _M_b(__b)
1519 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1522 result_type
1523 a() const
1524 { return _M_a; }
1526 result_type
1527 b() const
1528 { return _M_b; }
1530 private:
1531 _IntType _M_a;
1532 _IntType _M_b;
1535 public:
1537 * @brief Constructs a uniform distribution object.
1539 explicit
1540 uniform_int_distribution(_IntType __a = 0,
1541 _IntType __b = std::numeric_limits<_IntType>::max())
1542 : _M_param(__a, __b)
1545 explicit
1546 uniform_int_distribution(const param_type& __p)
1547 : _M_param(__p)
1551 * @brief Resets the distribution state.
1553 * Does nothing for the uniform integer distribution.
1555 void
1556 reset() { }
1558 result_type
1559 a() const
1560 { return _M_param.a(); }
1562 result_type
1563 b() const
1564 { return _M_param.b(); }
1567 * @brief Returns the inclusive lower bound of the distribution range.
1569 result_type
1570 min() const
1571 { return this->a(); }
1574 * @brief Returns the inclusive upper bound of the distribution range.
1576 result_type
1577 max() const
1578 { return this->b(); }
1581 * @brief Returns the parameter set of the distribution.
1583 param_type
1584 param() const
1585 { return _M_param; }
1588 * @brief Sets the parameter set of the distribution.
1589 * @param __param The new parameter set of the distribution.
1591 void
1592 param(const param_type& __param)
1593 { _M_param = __param; }
1596 * Gets a uniformly distributed random number in the range
1597 * @f$(min, max)@f$.
1599 template<typename _UniformRandomNumberGenerator>
1600 result_type
1601 operator()(_UniformRandomNumberGenerator& __urng)
1602 { return this->operator()(__urng, this->param()); }
1605 * Gets a uniform random number in the range @f$[0, n)@f$.
1607 * This function is aimed at use with std::random_shuffle.
1609 template<typename _UniformRandomNumberGenerator>
1610 result_type
1611 operator()(_UniformRandomNumberGenerator& __urng,
1612 const param_type& __p);
1614 param_type _M_param;
1618 * @brief Inserts a %uniform_int_distribution random number
1619 * distribution @p __x into the output stream @p os.
1621 * @param __os An output stream.
1622 * @param __x A %uniform_int_distribution random number distribution.
1624 * @returns The output stream with the state of @p __x inserted or in
1625 * an error state.
1627 template<typename _IntType, typename _CharT, typename _Traits>
1628 std::basic_ostream<_CharT, _Traits>&
1629 operator<<(std::basic_ostream<_CharT, _Traits>&,
1630 const std::uniform_int_distribution<_IntType>&);
1633 * @brief Extracts a %uniform_int_distribution random number distribution
1634 * @p __x from the input stream @p __is.
1636 * @param __is An input stream.
1637 * @param __x A %uniform_int_distribution random number generator engine.
1639 * @returns The input stream with @p __x extracted or in an error state.
1641 template<typename _IntType, typename _CharT, typename _Traits>
1642 std::basic_istream<_CharT, _Traits>&
1643 operator>>(std::basic_istream<_CharT, _Traits>&,
1644 std::uniform_int_distribution<_IntType>&);
1648 * @brief Uniform continuous distribution for random numbers.
1650 * A continuous random distribution on the range [min, max) with equal
1651 * probability throughout the range. The URNG should be real-valued and
1652 * deliver number in the range [0, 1).
1654 template<typename _RealType = double>
1655 class uniform_real_distribution
1657 static_assert(std::is_floating_point<_RealType>::value,
1658 "template argument not a floating point type");
1660 public:
1661 /** The type of the range of the distribution. */
1662 typedef _RealType result_type;
1663 /** Parameter type. */
1664 struct param_type
1666 typedef uniform_real_distribution<_RealType> distribution_type;
1668 explicit
1669 param_type(_RealType __a = _RealType(0),
1670 _RealType __b = _RealType(1))
1671 : _M_a(__a), _M_b(__b)
1673 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1676 result_type
1677 a() const
1678 { return _M_a; }
1680 result_type
1681 b() const
1682 { return _M_b; }
1684 private:
1685 _RealType _M_a;
1686 _RealType _M_b;
1689 public:
1691 * @brief Constructs a uniform_real_distribution object.
1693 * @param __min [IN] The lower bound of the distribution.
1694 * @param __max [IN] The upper bound of the distribution.
1696 explicit
1697 uniform_real_distribution(_RealType __a = _RealType(0),
1698 _RealType __b = _RealType(1))
1699 : _M_param(__a, __b)
1702 explicit
1703 uniform_real_distribution(const param_type& __p)
1704 : _M_param(__p)
1708 * @brief Resets the distribution state.
1710 * Does nothing for the uniform real distribution.
1712 void
1713 reset() { }
1715 result_type
1716 a() const
1717 { return _M_param.a(); }
1719 result_type
1720 b() const
1721 { return _M_param.b(); }
1724 * @brief Returns the inclusive lower bound of the distribution range.
1726 result_type
1727 min() const
1728 { return this->a(); }
1731 * @brief Returns the inclusive upper bound of the distribution range.
1733 result_type
1734 max() const
1735 { return this->b(); }
1738 * @brief Returns the parameter set of the distribution.
1740 param_type
1741 param() const
1742 { return _M_param; }
1745 * @brief Sets the parameter set of the distribution.
1746 * @param __param The new parameter set of the distribution.
1748 void
1749 param(const param_type& __param)
1750 { _M_param = __param; }
1752 template<typename _UniformRandomNumberGenerator>
1753 result_type
1754 operator()(_UniformRandomNumberGenerator& __urng)
1755 { return this->operator()(__urng, this->param()); }
1757 template<typename _UniformRandomNumberGenerator>
1758 result_type
1759 operator()(_UniformRandomNumberGenerator& __urng,
1760 const param_type& __p)
1762 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1763 __aurng(__urng);
1764 return (__aurng() * (__p.b() - __p.a())) + __p.a();
1767 private:
1768 param_type _M_param;
1772 * @brief Inserts a %uniform_real_distribution random number
1773 * distribution @p __x into the output stream @p __os.
1775 * @param __os An output stream.
1776 * @param __x A %uniform_real_distribution random number distribution.
1778 * @returns The output stream with the state of @p __x inserted or in
1779 * an error state.
1781 template<typename _RealType, typename _CharT, typename _Traits>
1782 std::basic_ostream<_CharT, _Traits>&
1783 operator<<(std::basic_ostream<_CharT, _Traits>&,
1784 const std::uniform_real_distribution<_RealType>&);
1787 * @brief Extracts a %uniform_real_distribution random number distribution
1788 * @p __x from the input stream @p __is.
1790 * @param __is An input stream.
1791 * @param __x A %uniform_real_distribution random number generator engine.
1793 * @returns The input stream with @p __x extracted or in an error state.
1795 template<typename _RealType, typename _CharT, typename _Traits>
1796 std::basic_istream<_CharT, _Traits>&
1797 operator>>(std::basic_istream<_CharT, _Traits>&,
1798 std::uniform_real_distribution<_RealType>&);
1800 /* @} */ // group std_random_distributions_uniform
1803 * @addtogroup std_random_distributions_normal Normal Distributions
1804 * @ingroup std_random_distributions
1805 * @{
1809 * @brief A normal continuous distribution for random numbers.
1811 * The formula for the normal probability density function is
1812 * @f$ p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1813 * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } @f$.
1815 template<typename _RealType = double>
1816 class normal_distribution
1818 static_assert(std::is_floating_point<_RealType>::value,
1819 "template argument not a floating point type");
1821 public:
1822 /** The type of the range of the distribution. */
1823 typedef _RealType result_type;
1824 /** Parameter type. */
1825 struct param_type
1827 typedef normal_distribution<_RealType> distribution_type;
1829 explicit
1830 param_type(_RealType __mean = _RealType(0),
1831 _RealType __stddev = _RealType(1))
1832 : _M_mean(__mean), _M_stddev(__stddev)
1834 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1837 _RealType
1838 mean() const
1839 { return _M_mean; }
1841 _RealType
1842 stddev() const
1843 { return _M_stddev; }
1845 private:
1846 _RealType _M_mean;
1847 _RealType _M_stddev;
1850 public:
1852 * Constructs a normal distribution with parameters @f$ mean @f$ and
1853 * standard deviation.
1855 explicit
1856 normal_distribution(result_type __mean = result_type(0),
1857 result_type __stddev = result_type(1))
1858 : _M_param(__mean, __stddev), _M_saved_available(false)
1861 explicit
1862 normal_distribution(const param_type& __p)
1863 : _M_param(__p), _M_saved_available(false)
1867 * @brief Resets the distribution state.
1869 void
1870 reset()
1871 { _M_saved_available = false; }
1874 * @brief Returns the mean of the distribution.
1876 _RealType
1877 mean() const
1878 { return _M_param.mean(); }
1881 * @brief Returns the standard deviation of the distribution.
1883 _RealType
1884 stddev() const
1885 { return _M_param.stddev(); }
1888 * @brief Returns the parameter set of the distribution.
1890 param_type
1891 param() const
1892 { return _M_param; }
1895 * @brief Sets the parameter set of the distribution.
1896 * @param __param The new parameter set of the distribution.
1898 void
1899 param(const param_type& __param)
1900 { _M_param = __param; }
1903 * @brief Returns the greatest lower bound value of the distribution.
1905 result_type
1906 min() const
1907 { return std::numeric_limits<result_type>::min(); }
1910 * @brief Returns the least upper bound value of the distribution.
1912 result_type
1913 max() const
1914 { return std::numeric_limits<result_type>::max(); }
1916 template<typename _UniformRandomNumberGenerator>
1917 result_type
1918 operator()(_UniformRandomNumberGenerator& __urng)
1919 { return this->operator()(__urng, this->param()); }
1921 template<typename _UniformRandomNumberGenerator>
1922 result_type
1923 operator()(_UniformRandomNumberGenerator& __urng,
1924 const param_type& __p);
1927 * @brief Inserts a %normal_distribution random number distribution
1928 * @p __x into the output stream @p __os.
1930 * @param __os An output stream.
1931 * @param __x A %normal_distribution random number distribution.
1933 * @returns The output stream with the state of @p __x inserted or in
1934 * an error state.
1936 template<typename _RealType1, typename _CharT, typename _Traits>
1937 friend std::basic_ostream<_CharT, _Traits>&
1938 operator<<(std::basic_ostream<_CharT, _Traits>&,
1939 const std::normal_distribution<_RealType1>&);
1942 * @brief Extracts a %normal_distribution random number distribution
1943 * @p __x from the input stream @p __is.
1945 * @param __is An input stream.
1946 * @param __x A %normal_distribution random number generator engine.
1948 * @returns The input stream with @p __x extracted or in an error
1949 * state.
1951 template<typename _RealType1, typename _CharT, typename _Traits>
1952 friend std::basic_istream<_CharT, _Traits>&
1953 operator>>(std::basic_istream<_CharT, _Traits>&,
1954 std::normal_distribution<_RealType1>&);
1956 private:
1957 param_type _M_param;
1958 result_type _M_saved;
1959 bool _M_saved_available;
1964 * @brief A lognormal_distribution random number distribution.
1966 * The formula for the normal probability mass function is
1967 * @f$ p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
1968 * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} @f$
1970 template<typename _RealType = double>
1971 class lognormal_distribution
1973 static_assert(std::is_floating_point<_RealType>::value,
1974 "template argument not a floating point type");
1976 public:
1977 /** The type of the range of the distribution. */
1978 typedef _RealType result_type;
1979 /** Parameter type. */
1980 struct param_type
1982 typedef lognormal_distribution<_RealType> distribution_type;
1984 explicit
1985 param_type(_RealType __m = _RealType(0),
1986 _RealType __s = _RealType(1))
1987 : _M_m(__m), _M_s(__s)
1990 _RealType
1991 m() const
1992 { return _M_m; }
1994 _RealType
1995 s() const
1996 { return _M_s; }
1998 private:
1999 _RealType _M_m;
2000 _RealType _M_s;
2003 explicit
2004 lognormal_distribution(_RealType __m = _RealType(0),
2005 _RealType __s = _RealType(1))
2006 : _M_param(__m, __s), _M_nd()
2009 explicit
2010 lognormal_distribution(const param_type& __p)
2011 : _M_param(__p), _M_nd()
2015 * Resets the distribution state.
2017 void
2018 reset()
2019 { _M_nd.reset(); }
2024 _RealType
2025 m() const
2026 { return _M_param.m(); }
2028 _RealType
2029 s() const
2030 { return _M_param.s(); }
2033 * @brief Returns the parameter set of the distribution.
2035 param_type
2036 param() const
2037 { return _M_param; }
2040 * @brief Sets the parameter set of the distribution.
2041 * @param __param The new parameter set of the distribution.
2043 void
2044 param(const param_type& __param)
2045 { _M_param = __param; }
2048 * @brief Returns the greatest lower bound value of the distribution.
2050 result_type
2051 min() const
2052 { return result_type(0); }
2055 * @brief Returns the least upper bound value of the distribution.
2057 result_type
2058 max() const
2059 { return std::numeric_limits<result_type>::max(); }
2061 template<typename _UniformRandomNumberGenerator>
2062 result_type
2063 operator()(_UniformRandomNumberGenerator& __urng)
2064 { return this->operator()(__urng, this->param()); }
2066 template<typename _UniformRandomNumberGenerator>
2067 result_type
2068 operator()(_UniformRandomNumberGenerator& __urng,
2069 const param_type& __p)
2070 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2073 * @brief Inserts a %lognormal_distribution random number distribution
2074 * @p __x into the output stream @p __os.
2076 * @param __os An output stream.
2077 * @param __x A %lognormal_distribution random number distribution.
2079 * @returns The output stream with the state of @p __x inserted or in
2080 * an error state.
2082 template<typename _RealType1, typename _CharT, typename _Traits>
2083 friend std::basic_ostream<_CharT, _Traits>&
2084 operator<<(std::basic_ostream<_CharT, _Traits>&,
2085 const std::lognormal_distribution<_RealType1>&);
2088 * @brief Extracts a %lognormal_distribution random number distribution
2089 * @p __x from the input stream @p __is.
2091 * @param __is An input stream.
2092 * @param __x A %lognormal_distribution random number
2093 * generator engine.
2095 * @returns The input stream with @p __x extracted or in an error state.
2097 template<typename _RealType1, typename _CharT, typename _Traits>
2098 friend std::basic_istream<_CharT, _Traits>&
2099 operator>>(std::basic_istream<_CharT, _Traits>&,
2100 std::lognormal_distribution<_RealType1>&);
2102 private:
2103 param_type _M_param;
2105 std::normal_distribution<result_type> _M_nd;
2110 * @brief A gamma continuous distribution for random numbers.
2112 * The formula for the gamma probability density function is
2113 * @f$ p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2114 * (x/\beta)^{\alpha - 1} e^{-x/\beta} @f$.
2116 template<typename _RealType = double>
2117 class gamma_distribution
2119 static_assert(std::is_floating_point<_RealType>::value,
2120 "template argument not a floating point type");
2122 public:
2123 /** The type of the range of the distribution. */
2124 typedef _RealType result_type;
2125 /** Parameter type. */
2126 struct param_type
2128 typedef gamma_distribution<_RealType> distribution_type;
2129 friend class gamma_distribution<_RealType>;
2131 explicit
2132 param_type(_RealType __alpha_val = _RealType(1),
2133 _RealType __beta_val = _RealType(1))
2134 : _M_alpha(__alpha_val), _M_beta(__beta_val)
2136 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2137 _M_initialize();
2140 _RealType
2141 alpha() const
2142 { return _M_alpha; }
2144 _RealType
2145 beta() const
2146 { return _M_beta; }
2148 private:
2149 void
2150 _M_initialize();
2152 _RealType _M_alpha;
2153 _RealType _M_beta;
2155 _RealType _M_malpha, _M_a2;
2158 public:
2160 * @brief Constructs a gamma distribution with parameters
2161 * @f$ \alpha @f$ and @f$ \beta @f$.
2163 explicit
2164 gamma_distribution(_RealType __alpha_val = _RealType(1),
2165 _RealType __beta_val = _RealType(1))
2166 : _M_param(__alpha_val, __beta_val), _M_nd()
2169 explicit
2170 gamma_distribution(const param_type& __p)
2171 : _M_param(__p), _M_nd()
2175 * @brief Resets the distribution state.
2177 void
2178 reset()
2179 { _M_nd.reset(); }
2182 * @brief Returns the @f$ \alpha @f$ of the distribution.
2184 _RealType
2185 alpha() const
2186 { return _M_param.alpha(); }
2189 * @brief Returns the @f$ \beta @f$ of the distribution.
2191 _RealType
2192 beta() const
2193 { return _M_param.beta(); }
2196 * @brief Returns the parameter set of the distribution.
2198 param_type
2199 param() const
2200 { return _M_param; }
2203 * @brief Sets the parameter set of the distribution.
2204 * @param __param The new parameter set of the distribution.
2206 void
2207 param(const param_type& __param)
2208 { _M_param = __param; }
2211 * @brief Returns the greatest lower bound value of the distribution.
2213 result_type
2214 min() const
2215 { return result_type(0); }
2218 * @brief Returns the least upper bound value of the distribution.
2220 result_type
2221 max() const
2222 { return std::numeric_limits<result_type>::max(); }
2224 template<typename _UniformRandomNumberGenerator>
2225 result_type
2226 operator()(_UniformRandomNumberGenerator& __urng)
2227 { return this->operator()(__urng, this->param()); }
2229 template<typename _UniformRandomNumberGenerator>
2230 result_type
2231 operator()(_UniformRandomNumberGenerator& __urng,
2232 const param_type& __p);
2235 * @brief Inserts a %gamma_distribution random number distribution
2236 * @p __x into the output stream @p __os.
2238 * @param __os An output stream.
2239 * @param __x A %gamma_distribution random number distribution.
2241 * @returns The output stream with the state of @p __x inserted or in
2242 * an error state.
2244 template<typename _RealType1, typename _CharT, typename _Traits>
2245 friend std::basic_ostream<_CharT, _Traits>&
2246 operator<<(std::basic_ostream<_CharT, _Traits>&,
2247 const std::gamma_distribution<_RealType1>&);
2250 * @brief Extracts a %gamma_distribution random number distribution
2251 * @p __x from the input stream @p __is.
2253 * @param __is An input stream.
2254 * @param __x A %gamma_distribution random number generator engine.
2256 * @returns The input stream with @p __x extracted or in an error state.
2258 template<typename _RealType1, typename _CharT, typename _Traits>
2259 friend std::basic_istream<_CharT, _Traits>&
2260 operator>>(std::basic_istream<_CharT, _Traits>&,
2261 std::gamma_distribution<_RealType1>&);
2263 private:
2264 param_type _M_param;
2266 std::normal_distribution<result_type> _M_nd;
2271 * @brief A chi_squared_distribution random number distribution.
2273 * The formula for the normal probability mass function is
2274 * @f$ p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}} @f$
2276 template<typename _RealType = double>
2277 class chi_squared_distribution
2279 static_assert(std::is_floating_point<_RealType>::value,
2280 "template argument not a floating point type");
2282 public:
2283 /** The type of the range of the distribution. */
2284 typedef _RealType result_type;
2285 /** Parameter type. */
2286 struct param_type
2288 typedef chi_squared_distribution<_RealType> distribution_type;
2290 explicit
2291 param_type(_RealType __n = _RealType(1))
2292 : _M_n(__n)
2295 _RealType
2296 n() const
2297 { return _M_n; }
2299 private:
2300 _RealType _M_n;
2303 explicit
2304 chi_squared_distribution(_RealType __n = _RealType(1))
2305 : _M_param(__n), _M_gd(__n / 2)
2308 explicit
2309 chi_squared_distribution(const param_type& __p)
2310 : _M_param(__p), _M_gd(__p.n() / 2)
2314 * @brief Resets the distribution state.
2316 void
2317 reset()
2318 { _M_gd.reset(); }
2323 _RealType
2324 n() const
2325 { return _M_param.n(); }
2328 * @brief Returns the parameter set of the distribution.
2330 param_type
2331 param() const
2332 { return _M_param; }
2335 * @brief Sets the parameter set of the distribution.
2336 * @param __param The new parameter set of the distribution.
2338 void
2339 param(const param_type& __param)
2340 { _M_param = __param; }
2343 * @brief Returns the greatest lower bound value of the distribution.
2345 result_type
2346 min() const
2347 { return result_type(0); }
2350 * @brief Returns the least upper bound value of the distribution.
2352 result_type
2353 max() const
2354 { return std::numeric_limits<result_type>::max(); }
2356 template<typename _UniformRandomNumberGenerator>
2357 result_type
2358 operator()(_UniformRandomNumberGenerator& __urng)
2359 { return 2 * _M_gd(__urng); }
2361 template<typename _UniformRandomNumberGenerator>
2362 result_type
2363 operator()(_UniformRandomNumberGenerator& __urng,
2364 const param_type& __p)
2366 typedef typename std::gamma_distribution<result_type>::param_type
2367 param_type;
2368 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2372 * @brief Inserts a %chi_squared_distribution random number distribution
2373 * @p __x into the output stream @p __os.
2375 * @param __os An output stream.
2376 * @param __x A %chi_squared_distribution random number distribution.
2378 * @returns The output stream with the state of @p __x inserted or in
2379 * an error state.
2381 template<typename _RealType1, typename _CharT, typename _Traits>
2382 friend std::basic_ostream<_CharT, _Traits>&
2383 operator<<(std::basic_ostream<_CharT, _Traits>&,
2384 const std::chi_squared_distribution<_RealType1>&);
2387 * @brief Extracts a %chi_squared_distribution random number distribution
2388 * @p __x from the input stream @p __is.
2390 * @param __is An input stream.
2391 * @param __x A %chi_squared_distribution random number
2392 * generator engine.
2394 * @returns The input stream with @p __x extracted or in an error state.
2396 template<typename _RealType1, typename _CharT, typename _Traits>
2397 friend std::basic_istream<_CharT, _Traits>&
2398 operator>>(std::basic_istream<_CharT, _Traits>&,
2399 std::chi_squared_distribution<_RealType1>&);
2401 private:
2402 param_type _M_param;
2404 std::gamma_distribution<result_type> _M_gd;
2409 * @brief A cauchy_distribution random number distribution.
2411 * The formula for the normal probability mass function is
2412 * @f$ p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1} @f$
2414 template<typename _RealType = double>
2415 class cauchy_distribution
2417 static_assert(std::is_floating_point<_RealType>::value,
2418 "template argument not a floating point type");
2420 public:
2421 /** The type of the range of the distribution. */
2422 typedef _RealType result_type;
2423 /** Parameter type. */
2424 struct param_type
2426 typedef cauchy_distribution<_RealType> distribution_type;
2428 explicit
2429 param_type(_RealType __a = _RealType(0),
2430 _RealType __b = _RealType(1))
2431 : _M_a(__a), _M_b(__b)
2434 _RealType
2435 a() const
2436 { return _M_a; }
2438 _RealType
2439 b() const
2440 { return _M_b; }
2442 private:
2443 _RealType _M_a;
2444 _RealType _M_b;
2447 explicit
2448 cauchy_distribution(_RealType __a = _RealType(0),
2449 _RealType __b = _RealType(1))
2450 : _M_param(__a, __b)
2453 explicit
2454 cauchy_distribution(const param_type& __p)
2455 : _M_param(__p)
2459 * @brief Resets the distribution state.
2461 void
2462 reset()
2468 _RealType
2469 a() const
2470 { return _M_param.a(); }
2472 _RealType
2473 b() const
2474 { return _M_param.b(); }
2477 * @brief Returns the parameter set of the distribution.
2479 param_type
2480 param() const
2481 { return _M_param; }
2484 * @brief Sets the parameter set of the distribution.
2485 * @param __param The new parameter set of the distribution.
2487 void
2488 param(const param_type& __param)
2489 { _M_param = __param; }
2492 * @brief Returns the greatest lower bound value of the distribution.
2494 result_type
2495 min() const
2496 { return std::numeric_limits<result_type>::min(); }
2499 * @brief Returns the least upper bound value of the distribution.
2501 result_type
2502 max() const
2503 { return std::numeric_limits<result_type>::max(); }
2505 template<typename _UniformRandomNumberGenerator>
2506 result_type
2507 operator()(_UniformRandomNumberGenerator& __urng)
2508 { return this->operator()(__urng, this->param()); }
2510 template<typename _UniformRandomNumberGenerator>
2511 result_type
2512 operator()(_UniformRandomNumberGenerator& __urng,
2513 const param_type& __p);
2515 private:
2516 param_type _M_param;
2520 * @brief Inserts a %cauchy_distribution random number distribution
2521 * @p __x into the output stream @p __os.
2523 * @param __os An output stream.
2524 * @param __x A %cauchy_distribution random number distribution.
2526 * @returns The output stream with the state of @p __x inserted or in
2527 * an error state.
2529 template<typename _RealType, typename _CharT, typename _Traits>
2530 std::basic_ostream<_CharT, _Traits>&
2531 operator<<(std::basic_ostream<_CharT, _Traits>&,
2532 const std::cauchy_distribution<_RealType>&);
2535 * @brief Extracts a %cauchy_distribution random number distribution
2536 * @p __x from the input stream @p __is.
2538 * @param __is An input stream.
2539 * @param __x A %cauchy_distribution random number
2540 * generator engine.
2542 * @returns The input stream with @p __x extracted or in an error state.
2544 template<typename _RealType, typename _CharT, typename _Traits>
2545 std::basic_istream<_CharT, _Traits>&
2546 operator>>(std::basic_istream<_CharT, _Traits>&,
2547 std::cauchy_distribution<_RealType>&);
2551 * @brief A fisher_f_distribution random number distribution.
2553 * The formula for the normal probability mass function is
2554 * @f$ p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2555 * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2556 * (1 + \frac{mx}{n})^{-(m+n)/2} @f$
2558 template<typename _RealType = double>
2559 class fisher_f_distribution
2561 static_assert(std::is_floating_point<_RealType>::value,
2562 "template argument not a floating point type");
2564 public:
2565 /** The type of the range of the distribution. */
2566 typedef _RealType result_type;
2567 /** Parameter type. */
2568 struct param_type
2570 typedef fisher_f_distribution<_RealType> distribution_type;
2572 explicit
2573 param_type(_RealType __m = _RealType(1),
2574 _RealType __n = _RealType(1))
2575 : _M_m(__m), _M_n(__n)
2578 _RealType
2579 m() const
2580 { return _M_m; }
2582 _RealType
2583 n() const
2584 { return _M_n; }
2586 private:
2587 _RealType _M_m;
2588 _RealType _M_n;
2591 explicit
2592 fisher_f_distribution(_RealType __m = _RealType(1),
2593 _RealType __n = _RealType(1))
2594 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2597 explicit
2598 fisher_f_distribution(const param_type& __p)
2599 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2603 * @brief Resets the distribution state.
2605 void
2606 reset()
2608 _M_gd_x.reset();
2609 _M_gd_y.reset();
2615 _RealType
2616 m() const
2617 { return _M_param.m(); }
2619 _RealType
2620 n() const
2621 { return _M_param.n(); }
2624 * @brief Returns the parameter set of the distribution.
2626 param_type
2627 param() const
2628 { return _M_param; }
2631 * @brief Sets the parameter set of the distribution.
2632 * @param __param The new parameter set of the distribution.
2634 void
2635 param(const param_type& __param)
2636 { _M_param = __param; }
2639 * @brief Returns the greatest lower bound value of the distribution.
2641 result_type
2642 min() const
2643 { return result_type(0); }
2646 * @brief Returns the least upper bound value of the distribution.
2648 result_type
2649 max() const
2650 { return std::numeric_limits<result_type>::max(); }
2652 template<typename _UniformRandomNumberGenerator>
2653 result_type
2654 operator()(_UniformRandomNumberGenerator& __urng)
2655 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2657 template<typename _UniformRandomNumberGenerator>
2658 result_type
2659 operator()(_UniformRandomNumberGenerator& __urng,
2660 const param_type& __p)
2662 typedef typename std::gamma_distribution<result_type>::param_type
2663 param_type;
2664 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2665 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2669 * @brief Inserts a %fisher_f_distribution random number distribution
2670 * @p __x into the output stream @p __os.
2672 * @param __os An output stream.
2673 * @param __x A %fisher_f_distribution random number distribution.
2675 * @returns The output stream with the state of @p __x inserted or in
2676 * an error state.
2678 template<typename _RealType1, typename _CharT, typename _Traits>
2679 friend std::basic_ostream<_CharT, _Traits>&
2680 operator<<(std::basic_ostream<_CharT, _Traits>&,
2681 const std::fisher_f_distribution<_RealType1>&);
2684 * @brief Extracts a %fisher_f_distribution random number distribution
2685 * @p __x from the input stream @p __is.
2687 * @param __is An input stream.
2688 * @param __x A %fisher_f_distribution random number
2689 * generator engine.
2691 * @returns The input stream with @p __x extracted or in an error state.
2693 template<typename _RealType1, typename _CharT, typename _Traits>
2694 friend std::basic_istream<_CharT, _Traits>&
2695 operator>>(std::basic_istream<_CharT, _Traits>&,
2696 std::fisher_f_distribution<_RealType1>&);
2698 private:
2699 param_type _M_param;
2701 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
2706 * @brief A student_t_distribution random number distribution.
2708 * The formula for the normal probability mass function is
2709 * @f$ p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
2710 * (1 + \frac{x^2}{n}) ^{-(n+1)/2} @f$
2712 template<typename _RealType = double>
2713 class student_t_distribution
2715 static_assert(std::is_floating_point<_RealType>::value,
2716 "template argument not a floating point type");
2718 public:
2719 /** The type of the range of the distribution. */
2720 typedef _RealType result_type;
2721 /** Parameter type. */
2722 struct param_type
2724 typedef student_t_distribution<_RealType> distribution_type;
2726 explicit
2727 param_type(_RealType __n = _RealType(1))
2728 : _M_n(__n)
2731 _RealType
2732 n() const
2733 { return _M_n; }
2735 private:
2736 _RealType _M_n;
2739 explicit
2740 student_t_distribution(_RealType __n = _RealType(1))
2741 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
2744 explicit
2745 student_t_distribution(const param_type& __p)
2746 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
2750 * @brief Resets the distribution state.
2752 void
2753 reset()
2755 _M_nd.reset();
2756 _M_gd.reset();
2762 _RealType
2763 n() const
2764 { return _M_param.n(); }
2767 * @brief Returns the parameter set of the distribution.
2769 param_type
2770 param() const
2771 { return _M_param; }
2774 * @brief Sets the parameter set of the distribution.
2775 * @param __param The new parameter set of the distribution.
2777 void
2778 param(const param_type& __param)
2779 { _M_param = __param; }
2782 * @brief Returns the greatest lower bound value of the distribution.
2784 result_type
2785 min() const
2786 { return std::numeric_limits<result_type>::min(); }
2789 * @brief Returns the least upper bound value of the distribution.
2791 result_type
2792 max() const
2793 { return std::numeric_limits<result_type>::max(); }
2795 template<typename _UniformRandomNumberGenerator>
2796 result_type
2797 operator()(_UniformRandomNumberGenerator& __urng)
2798 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
2800 template<typename _UniformRandomNumberGenerator>
2801 result_type
2802 operator()(_UniformRandomNumberGenerator& __urng,
2803 const param_type& __p)
2805 typedef typename std::gamma_distribution<result_type>::param_type
2806 param_type;
2808 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
2809 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
2813 * @brief Inserts a %student_t_distribution random number distribution
2814 * @p __x into the output stream @p __os.
2816 * @param __os An output stream.
2817 * @param __x A %student_t_distribution random number distribution.
2819 * @returns The output stream with the state of @p __x inserted or in
2820 * an error state.
2822 template<typename _RealType1, typename _CharT, typename _Traits>
2823 friend std::basic_ostream<_CharT, _Traits>&
2824 operator<<(std::basic_ostream<_CharT, _Traits>&,
2825 const std::student_t_distribution<_RealType1>&);
2828 * @brief Extracts a %student_t_distribution random number distribution
2829 * @p __x from the input stream @p __is.
2831 * @param __is An input stream.
2832 * @param __x A %student_t_distribution random number
2833 * generator engine.
2835 * @returns The input stream with @p __x extracted or in an error state.
2837 template<typename _RealType1, typename _CharT, typename _Traits>
2838 friend std::basic_istream<_CharT, _Traits>&
2839 operator>>(std::basic_istream<_CharT, _Traits>&,
2840 std::student_t_distribution<_RealType1>&);
2842 private:
2843 param_type _M_param;
2845 std::normal_distribution<result_type> _M_nd;
2846 std::gamma_distribution<result_type> _M_gd;
2849 /* @} */ // group std_random_distributions_normal
2852 * @addtogroup std_random_distributions_bernoulli Bernoulli Distributions
2853 * @ingroup std_random_distributions
2854 * @{
2858 * @brief A Bernoulli random number distribution.
2860 * Generates a sequence of true and false values with likelihood @f$ p @f$
2861 * that true will come up and @f$ (1 - p) @f$ that false will appear.
2863 class bernoulli_distribution
2865 public:
2866 /** The type of the range of the distribution. */
2867 typedef bool result_type;
2868 /** Parameter type. */
2869 struct param_type
2871 typedef bernoulli_distribution distribution_type;
2873 explicit
2874 param_type(double __p = 0.5)
2875 : _M_p(__p)
2877 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
2880 double
2881 p() const
2882 { return _M_p; }
2884 private:
2885 double _M_p;
2888 public:
2890 * @brief Constructs a Bernoulli distribution with likelihood @p p.
2892 * @param __p [IN] The likelihood of a true result being returned.
2893 * Must be in the interval @f$ [0, 1] @f$.
2895 explicit
2896 bernoulli_distribution(double __p = 0.5)
2897 : _M_param(__p)
2900 explicit
2901 bernoulli_distribution(const param_type& __p)
2902 : _M_param(__p)
2906 * @brief Resets the distribution state.
2908 * Does nothing for a Bernoulli distribution.
2910 void
2911 reset() { }
2914 * @brief Returns the @p p parameter of the distribution.
2916 double
2917 p() const
2918 { return _M_param.p(); }
2921 * @brief Returns the parameter set of the distribution.
2923 param_type
2924 param() const
2925 { return _M_param; }
2928 * @brief Sets the parameter set of the distribution.
2929 * @param __param The new parameter set of the distribution.
2931 void
2932 param(const param_type& __param)
2933 { _M_param = __param; }
2936 * @brief Returns the greatest lower bound value of the distribution.
2938 result_type
2939 min() const
2940 { return std::numeric_limits<result_type>::min(); }
2943 * @brief Returns the least upper bound value of the distribution.
2945 result_type
2946 max() const
2947 { return std::numeric_limits<result_type>::max(); }
2950 * @brief Returns the next value in the Bernoullian sequence.
2952 template<typename _UniformRandomNumberGenerator>
2953 result_type
2954 operator()(_UniformRandomNumberGenerator& __urng)
2955 { return this->operator()(__urng, this->param()); }
2957 template<typename _UniformRandomNumberGenerator>
2958 result_type
2959 operator()(_UniformRandomNumberGenerator& __urng,
2960 const param_type& __p)
2962 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2963 __aurng(__urng);
2964 if ((__aurng() - __aurng.min())
2965 < __p.p() * (__aurng.max() - __aurng.min()))
2966 return true;
2967 return false;
2970 private:
2971 param_type _M_param;
2975 * @brief Inserts a %bernoulli_distribution random number distribution
2976 * @p __x into the output stream @p __os.
2978 * @param __os An output stream.
2979 * @param __x A %bernoulli_distribution random number distribution.
2981 * @returns The output stream with the state of @p __x inserted or in
2982 * an error state.
2984 template<typename _CharT, typename _Traits>
2985 std::basic_ostream<_CharT, _Traits>&
2986 operator<<(std::basic_ostream<_CharT, _Traits>&,
2987 const std::bernoulli_distribution&);
2990 * @brief Extracts a %bernoulli_distribution random number distribution
2991 * @p __x from the input stream @p __is.
2993 * @param __is An input stream.
2994 * @param __x A %bernoulli_distribution random number generator engine.
2996 * @returns The input stream with @p __x extracted or in an error state.
2998 template<typename _CharT, typename _Traits>
2999 std::basic_istream<_CharT, _Traits>&
3000 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3001 std::bernoulli_distribution& __x)
3003 double __p;
3004 __is >> __p;
3005 __x.param(bernoulli_distribution::param_type(__p));
3006 return __is;
3011 * @brief A discrete binomial random number distribution.
3013 * The formula for the binomial probability density function is
3014 * @f$ p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
3015 * and @f$ p @f$ are the parameters of the distribution.
3017 template<typename _IntType = int>
3018 class binomial_distribution
3020 static_assert(std::is_integral<_IntType>::value,
3021 "template argument not an integral type");
3023 public:
3024 /** The type of the range of the distribution. */
3025 typedef _IntType result_type;
3026 /** Parameter type. */
3027 struct param_type
3029 typedef binomial_distribution<_IntType> distribution_type;
3030 friend class binomial_distribution<_IntType>;
3032 explicit
3033 param_type(_IntType __t = _IntType(1), double __p = 0.5)
3034 : _M_t(__t), _M_p(__p)
3036 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3037 && (_M_p >= 0.0)
3038 && (_M_p <= 1.0));
3039 _M_initialize();
3042 _IntType
3043 t() const
3044 { return _M_t; }
3046 double
3047 p() const
3048 { return _M_p; }
3050 private:
3051 void
3052 _M_initialize();
3054 _IntType _M_t;
3055 double _M_p;
3057 double _M_q;
3058 #if _GLIBCXX_USE_C99_MATH_TR1
3059 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3060 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3061 #endif
3062 bool _M_easy;
3065 // constructors and member function
3066 explicit
3067 binomial_distribution(_IntType __t = _IntType(1),
3068 double __p = 0.5)
3069 : _M_param(__t, __p), _M_nd()
3072 explicit
3073 binomial_distribution(const param_type& __p)
3074 : _M_param(__p), _M_nd()
3078 * @brief Resets the distribution state.
3080 void
3081 reset()
3082 { _M_nd.reset(); }
3085 * @brief Returns the distribution @p t parameter.
3087 _IntType
3088 t() const
3089 { return _M_param.t(); }
3092 * @brief Returns the distribution @p p parameter.
3094 double
3095 p() const
3096 { return _M_param.p(); }
3099 * @brief Returns the parameter set of the distribution.
3101 param_type
3102 param() const
3103 { return _M_param; }
3106 * @brief Sets the parameter set of the distribution.
3107 * @param __param The new parameter set of the distribution.
3109 void
3110 param(const param_type& __param)
3111 { _M_param = __param; }
3114 * @brief Returns the greatest lower bound value of the distribution.
3116 result_type
3117 min() const
3118 { return 0; }
3121 * @brief Returns the least upper bound value of the distribution.
3123 result_type
3124 max() const
3125 { return _M_param.t(); }
3127 template<typename _UniformRandomNumberGenerator>
3128 result_type
3129 operator()(_UniformRandomNumberGenerator& __urng)
3130 { return this->operator()(__urng, this->param()); }
3132 template<typename _UniformRandomNumberGenerator>
3133 result_type
3134 operator()(_UniformRandomNumberGenerator& __urng,
3135 const param_type& __p);
3138 * @brief Inserts a %binomial_distribution random number distribution
3139 * @p __x into the output stream @p __os.
3141 * @param __os An output stream.
3142 * @param __x A %binomial_distribution random number distribution.
3144 * @returns The output stream with the state of @p __x inserted or in
3145 * an error state.
3147 template<typename _IntType1,
3148 typename _CharT, typename _Traits>
3149 friend std::basic_ostream<_CharT, _Traits>&
3150 operator<<(std::basic_ostream<_CharT, _Traits>&,
3151 const std::binomial_distribution<_IntType1>&);
3154 * @brief Extracts a %binomial_distribution random number distribution
3155 * @p __x from the input stream @p __is.
3157 * @param __is An input stream.
3158 * @param __x A %binomial_distribution random number generator engine.
3160 * @returns The input stream with @p __x extracted or in an error
3161 * state.
3163 template<typename _IntType1,
3164 typename _CharT, typename _Traits>
3165 friend std::basic_istream<_CharT, _Traits>&
3166 operator>>(std::basic_istream<_CharT, _Traits>&,
3167 std::binomial_distribution<_IntType1>&);
3169 private:
3170 template<typename _UniformRandomNumberGenerator>
3171 result_type
3172 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3174 param_type _M_param;
3176 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3177 std::normal_distribution<double> _M_nd;
3182 * @brief A discrete geometric random number distribution.
3184 * The formula for the geometric probability density function is
3185 * @f$ p(i|p) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the
3186 * distribution.
3188 template<typename _IntType = int>
3189 class geometric_distribution
3191 static_assert(std::is_integral<_IntType>::value,
3192 "template argument not an integral type");
3194 public:
3195 /** The type of the range of the distribution. */
3196 typedef _IntType result_type;
3197 /** Parameter type. */
3198 struct param_type
3200 typedef geometric_distribution<_IntType> distribution_type;
3201 friend class geometric_distribution<_IntType>;
3203 explicit
3204 param_type(double __p = 0.5)
3205 : _M_p(__p)
3207 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
3208 && (_M_p <= 1.0));
3209 _M_initialize();
3212 double
3213 p() const
3214 { return _M_p; }
3216 private:
3217 void
3218 _M_initialize()
3219 { _M_log_p = std::log(_M_p); }
3221 double _M_p;
3223 double _M_log_p;
3226 // constructors and member function
3227 explicit
3228 geometric_distribution(double __p = 0.5)
3229 : _M_param(__p)
3232 explicit
3233 geometric_distribution(const param_type& __p)
3234 : _M_param(__p)
3238 * @brief Resets the distribution state.
3240 * Does nothing for the geometric distribution.
3242 void
3243 reset() { }
3246 * @brief Returns the distribution parameter @p p.
3248 double
3249 p() const
3250 { return _M_param.p(); }
3253 * @brief Returns the parameter set of the distribution.
3255 param_type
3256 param() const
3257 { return _M_param; }
3260 * @brief Sets the parameter set of the distribution.
3261 * @param __param The new parameter set of the distribution.
3263 void
3264 param(const param_type& __param)
3265 { _M_param = __param; }
3268 * @brief Returns the greatest lower bound value of the distribution.
3270 result_type
3271 min() const
3272 { return 0; }
3275 * @brief Returns the least upper bound value of the distribution.
3277 result_type
3278 max() const
3279 { return std::numeric_limits<result_type>::max(); }
3281 template<typename _UniformRandomNumberGenerator>
3282 result_type
3283 operator()(_UniformRandomNumberGenerator& __urng)
3284 { return this->operator()(__urng, this->param()); }
3286 template<typename _UniformRandomNumberGenerator>
3287 result_type
3288 operator()(_UniformRandomNumberGenerator& __urng,
3289 const param_type& __p);
3291 private:
3292 param_type _M_param;
3296 * @brief Inserts a %geometric_distribution random number distribution
3297 * @p __x into the output stream @p __os.
3299 * @param __os An output stream.
3300 * @param __x A %geometric_distribution random number distribution.
3302 * @returns The output stream with the state of @p __x inserted or in
3303 * an error state.
3305 template<typename _IntType,
3306 typename _CharT, typename _Traits>
3307 std::basic_ostream<_CharT, _Traits>&
3308 operator<<(std::basic_ostream<_CharT, _Traits>&,
3309 const std::geometric_distribution<_IntType>&);
3312 * @brief Extracts a %geometric_distribution random number distribution
3313 * @p __x from the input stream @p __is.
3315 * @param __is An input stream.
3316 * @param __x A %geometric_distribution random number generator engine.
3318 * @returns The input stream with @p __x extracted or in an error state.
3320 template<typename _IntType,
3321 typename _CharT, typename _Traits>
3322 std::basic_istream<_CharT, _Traits>&
3323 operator>>(std::basic_istream<_CharT, _Traits>&,
3324 std::geometric_distribution<_IntType>&);
3328 * @brief A negative_binomial_distribution random number distribution.
3330 * The formula for the negative binomial probability mass function is
3331 * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$
3332 * and @f$ p @f$ are the parameters of the distribution.
3334 template<typename _IntType = int>
3335 class negative_binomial_distribution
3337 static_assert(std::is_integral<_IntType>::value,
3338 "template argument not an integral type");
3340 public:
3341 /** The type of the range of the distribution. */
3342 typedef _IntType result_type;
3343 /** Parameter type. */
3344 struct param_type
3346 typedef negative_binomial_distribution<_IntType> distribution_type;
3348 explicit
3349 param_type(_IntType __k = 1, double __p = 0.5)
3350 : _M_k(__k), _M_p(__p)
3353 _IntType
3354 k() const
3355 { return _M_k; }
3357 double
3358 p() const
3359 { return _M_p; }
3361 private:
3362 _IntType _M_k;
3363 double _M_p;
3366 explicit
3367 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3368 : _M_param(__k, __p), _M_gd(__k, __p / (1.0 - __p))
3371 explicit
3372 negative_binomial_distribution(const param_type& __p)
3373 : _M_param(__p), _M_gd(__p.k(), __p.p() / (1.0 - __p.p()))
3377 * @brief Resets the distribution state.
3379 void
3380 reset()
3381 { _M_gd.reset(); }
3384 * @brief Return the @f$ k @f$ parameter of the distribution.
3386 _IntType
3387 k() const
3388 { return _M_param.k(); }
3391 * @brief Return the @f$ p @f$ parameter of the distribution.
3393 double
3394 p() const
3395 { return _M_param.p(); }
3398 * @brief Returns the parameter set of the distribution.
3400 param_type
3401 param() const
3402 { return _M_param; }
3405 * @brief Sets the parameter set of the distribution.
3406 * @param __param The new parameter set of the distribution.
3408 void
3409 param(const param_type& __param)
3410 { _M_param = __param; }
3413 * @brief Returns the greatest lower bound value of the distribution.
3415 result_type
3416 min() const
3417 { return result_type(0); }
3420 * @brief Returns the least upper bound value of the distribution.
3422 result_type
3423 max() const
3424 { return std::numeric_limits<result_type>::max(); }
3426 template<typename _UniformRandomNumberGenerator>
3427 result_type
3428 operator()(_UniformRandomNumberGenerator& __urng);
3430 template<typename _UniformRandomNumberGenerator>
3431 result_type
3432 operator()(_UniformRandomNumberGenerator& __urng,
3433 const param_type& __p);
3436 * @brief Inserts a %negative_binomial_distribution random
3437 * number distribution @p __x into the output stream @p __os.
3439 * @param __os An output stream.
3440 * @param __x A %negative_binomial_distribution random number
3441 * distribution.
3443 * @returns The output stream with the state of @p __x inserted or in
3444 * an error state.
3446 template<typename _IntType1, typename _CharT, typename _Traits>
3447 friend std::basic_ostream<_CharT, _Traits>&
3448 operator<<(std::basic_ostream<_CharT, _Traits>&,
3449 const std::negative_binomial_distribution<_IntType1>&);
3452 * @brief Extracts a %negative_binomial_distribution random number
3453 * distribution @p __x from the input stream @p __is.
3455 * @param __is An input stream.
3456 * @param __x A %negative_binomial_distribution random number
3457 * generator engine.
3459 * @returns The input stream with @p __x extracted or in an error state.
3461 template<typename _IntType1, typename _CharT, typename _Traits>
3462 friend std::basic_istream<_CharT, _Traits>&
3463 operator>>(std::basic_istream<_CharT, _Traits>&,
3464 std::negative_binomial_distribution<_IntType1>&);
3466 private:
3467 param_type _M_param;
3469 std::gamma_distribution<double> _M_gd;
3472 /* @} */ // group std_random_distributions_bernoulli
3475 * @addtogroup std_random_distributions_poisson Poisson Distributions
3476 * @ingroup std_random_distributions
3477 * @{
3481 * @brief A discrete Poisson random number distribution.
3483 * The formula for the Poisson probability density function is
3484 * @f$ p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu} @f$ where @f$ \mu @f$ is the
3485 * parameter of the distribution.
3487 template<typename _IntType = int>
3488 class poisson_distribution
3490 static_assert(std::is_integral<_IntType>::value,
3491 "template argument not an integral type");
3493 public:
3494 /** The type of the range of the distribution. */
3495 typedef _IntType result_type;
3496 /** Parameter type. */
3497 struct param_type
3499 typedef poisson_distribution<_IntType> distribution_type;
3500 friend class poisson_distribution<_IntType>;
3502 explicit
3503 param_type(double __mean = 1.0)
3504 : _M_mean(__mean)
3506 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3507 _M_initialize();
3510 double
3511 mean() const
3512 { return _M_mean; }
3514 private:
3515 // Hosts either log(mean) or the threshold of the simple method.
3516 void
3517 _M_initialize();
3519 double _M_mean;
3521 double _M_lm_thr;
3522 #if _GLIBCXX_USE_C99_MATH_TR1
3523 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3524 #endif
3527 // constructors and member function
3528 explicit
3529 poisson_distribution(double __mean = 1.0)
3530 : _M_param(__mean), _M_nd()
3533 explicit
3534 poisson_distribution(const param_type& __p)
3535 : _M_param(__p), _M_nd()
3539 * @brief Resets the distribution state.
3541 void
3542 reset()
3543 { _M_nd.reset(); }
3546 * @brief Returns the distribution parameter @p mean.
3548 double
3549 mean() const
3550 { return _M_param.mean(); }
3553 * @brief Returns the parameter set of the distribution.
3555 param_type
3556 param() const
3557 { return _M_param; }
3560 * @brief Sets the parameter set of the distribution.
3561 * @param __param The new parameter set of the distribution.
3563 void
3564 param(const param_type& __param)
3565 { _M_param = __param; }
3568 * @brief Returns the greatest lower bound value of the distribution.
3570 result_type
3571 min() const
3572 { return 0; }
3575 * @brief Returns the least upper bound value of the distribution.
3577 result_type
3578 max() const
3579 { return std::numeric_limits<result_type>::max(); }
3581 template<typename _UniformRandomNumberGenerator>
3582 result_type
3583 operator()(_UniformRandomNumberGenerator& __urng)
3584 { return this->operator()(__urng, this->param()); }
3586 template<typename _UniformRandomNumberGenerator>
3587 result_type
3588 operator()(_UniformRandomNumberGenerator& __urng,
3589 const param_type& __p);
3592 * @brief Inserts a %poisson_distribution random number distribution
3593 * @p __x into the output stream @p __os.
3595 * @param __os An output stream.
3596 * @param __x A %poisson_distribution random number distribution.
3598 * @returns The output stream with the state of @p __x inserted or in
3599 * an error state.
3601 template<typename _IntType1, typename _CharT, typename _Traits>
3602 friend std::basic_ostream<_CharT, _Traits>&
3603 operator<<(std::basic_ostream<_CharT, _Traits>&,
3604 const std::poisson_distribution<_IntType1>&);
3607 * @brief Extracts a %poisson_distribution random number distribution
3608 * @p __x from the input stream @p __is.
3610 * @param __is An input stream.
3611 * @param __x A %poisson_distribution random number generator engine.
3613 * @returns The input stream with @p __x extracted or in an error
3614 * state.
3616 template<typename _IntType1, typename _CharT, typename _Traits>
3617 friend std::basic_istream<_CharT, _Traits>&
3618 operator>>(std::basic_istream<_CharT, _Traits>&,
3619 std::poisson_distribution<_IntType1>&);
3621 private:
3622 param_type _M_param;
3624 // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3625 std::normal_distribution<double> _M_nd;
3629 * @brief An exponential continuous distribution for random numbers.
3631 * The formula for the exponential probability density function is
3632 * @f$ p(x|\lambda) = \lambda e^{-\lambda x} @f$.
3634 * <table border=1 cellpadding=10 cellspacing=0>
3635 * <caption align=top>Distribution Statistics</caption>
3636 * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3637 * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr>
3638 * <tr><td>Mode</td><td>@f$ zero @f$</td></tr>
3639 * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
3640 * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr>
3641 * </table>
3643 template<typename _RealType = double>
3644 class exponential_distribution
3646 static_assert(std::is_floating_point<_RealType>::value,
3647 "template argument not a floating point type");
3649 public:
3650 /** The type of the range of the distribution. */
3651 typedef _RealType result_type;
3652 /** Parameter type. */
3653 struct param_type
3655 typedef exponential_distribution<_RealType> distribution_type;
3657 explicit
3658 param_type(_RealType __lambda = _RealType(1))
3659 : _M_lambda(__lambda)
3661 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
3664 _RealType
3665 lambda() const
3666 { return _M_lambda; }
3668 private:
3669 _RealType _M_lambda;
3672 public:
3674 * @brief Constructs an exponential distribution with inverse scale
3675 * parameter @f$ \lambda @f$.
3677 explicit
3678 exponential_distribution(const result_type& __lambda = result_type(1))
3679 : _M_param(__lambda)
3682 explicit
3683 exponential_distribution(const param_type& __p)
3684 : _M_param(__p)
3688 * @brief Resets the distribution state.
3690 * Has no effect on exponential distributions.
3692 void
3693 reset() { }
3696 * @brief Returns the inverse scale parameter of the distribution.
3698 _RealType
3699 lambda() const
3700 { return _M_param.lambda(); }
3703 * @brief Returns the parameter set of the distribution.
3705 param_type
3706 param() const
3707 { return _M_param; }
3710 * @brief Sets the parameter set of the distribution.
3711 * @param __param The new parameter set of the distribution.
3713 void
3714 param(const param_type& __param)
3715 { _M_param = __param; }
3718 * @brief Returns the greatest lower bound value of the distribution.
3720 result_type
3721 min() const
3722 { return result_type(0); }
3725 * @brief Returns the least upper bound value of the distribution.
3727 result_type
3728 max() const
3729 { return std::numeric_limits<result_type>::max(); }
3731 template<typename _UniformRandomNumberGenerator>
3732 result_type
3733 operator()(_UniformRandomNumberGenerator& __urng)
3734 { return this->operator()(__urng, this->param()); }
3736 template<typename _UniformRandomNumberGenerator>
3737 result_type
3738 operator()(_UniformRandomNumberGenerator& __urng,
3739 const param_type& __p)
3741 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
3742 __aurng(__urng);
3743 return -std::log(__aurng()) / __p.lambda();
3746 private:
3747 param_type _M_param;
3751 * @brief Inserts a %exponential_distribution random number distribution
3752 * @p __x into the output stream @p __os.
3754 * @param __os An output stream.
3755 * @param __x A %exponential_distribution random number distribution.
3757 * @returns The output stream with the state of @p __x inserted or in
3758 * an error state.
3760 template<typename _RealType, typename _CharT, typename _Traits>
3761 std::basic_ostream<_CharT, _Traits>&
3762 operator<<(std::basic_ostream<_CharT, _Traits>&,
3763 const std::exponential_distribution<_RealType>&);
3766 * @brief Extracts a %exponential_distribution random number distribution
3767 * @p __x from the input stream @p __is.
3769 * @param __is An input stream.
3770 * @param __x A %exponential_distribution random number
3771 * generator engine.
3773 * @returns The input stream with @p __x extracted or in an error state.
3775 template<typename _RealType, typename _CharT, typename _Traits>
3776 std::basic_istream<_CharT, _Traits>&
3777 operator>>(std::basic_istream<_CharT, _Traits>&,
3778 std::exponential_distribution<_RealType>&);
3782 * @brief A weibull_distribution random number distribution.
3784 * The formula for the normal probability density function is
3785 * @f$ p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
3786 * \exp{(-(\frac{x}{\beta})^\alpha)} @f$.
3788 template<typename _RealType = double>
3789 class weibull_distribution
3791 static_assert(std::is_floating_point<_RealType>::value,
3792 "template argument not a floating point type");
3794 public:
3795 /** The type of the range of the distribution. */
3796 typedef _RealType result_type;
3797 /** Parameter type. */
3798 struct param_type
3800 typedef weibull_distribution<_RealType> distribution_type;
3802 explicit
3803 param_type(_RealType __a = _RealType(1),
3804 _RealType __b = _RealType(1))
3805 : _M_a(__a), _M_b(__b)
3808 _RealType
3809 a() const
3810 { return _M_a; }
3812 _RealType
3813 b() const
3814 { return _M_b; }
3816 private:
3817 _RealType _M_a;
3818 _RealType _M_b;
3821 explicit
3822 weibull_distribution(_RealType __a = _RealType(1),
3823 _RealType __b = _RealType(1))
3824 : _M_param(__a, __b)
3827 explicit
3828 weibull_distribution(const param_type& __p)
3829 : _M_param(__p)
3833 * @brief Resets the distribution state.
3835 void
3836 reset()
3840 * @brief Return the @f$ a @f$ parameter of the distribution.
3842 _RealType
3843 a() const
3844 { return _M_param.a(); }
3847 * @brief Return the @f$ b @f$ parameter of the distribution.
3849 _RealType
3850 b() const
3851 { return _M_param.b(); }
3854 * @brief Returns the parameter set of the distribution.
3856 param_type
3857 param() const
3858 { return _M_param; }
3861 * @brief Sets the parameter set of the distribution.
3862 * @param __param The new parameter set of the distribution.
3864 void
3865 param(const param_type& __param)
3866 { _M_param = __param; }
3869 * @brief Returns the greatest lower bound value of the distribution.
3871 result_type
3872 min() const
3873 { return result_type(0); }
3876 * @brief Returns the least upper bound value of the distribution.
3878 result_type
3879 max() const
3880 { return std::numeric_limits<result_type>::max(); }
3882 template<typename _UniformRandomNumberGenerator>
3883 result_type
3884 operator()(_UniformRandomNumberGenerator& __urng)
3885 { return this->operator()(__urng, this->param()); }
3887 template<typename _UniformRandomNumberGenerator>
3888 result_type
3889 operator()(_UniformRandomNumberGenerator& __urng,
3890 const param_type& __p);
3892 private:
3893 param_type _M_param;
3897 * @brief Inserts a %weibull_distribution random number distribution
3898 * @p __x into the output stream @p __os.
3900 * @param __os An output stream.
3901 * @param __x A %weibull_distribution random number distribution.
3903 * @returns The output stream with the state of @p __x inserted or in
3904 * an error state.
3906 template<typename _RealType, typename _CharT, typename _Traits>
3907 std::basic_ostream<_CharT, _Traits>&
3908 operator<<(std::basic_ostream<_CharT, _Traits>&,
3909 const std::weibull_distribution<_RealType>&);
3912 * @brief Extracts a %weibull_distribution random number distribution
3913 * @p __x from the input stream @p __is.
3915 * @param __is An input stream.
3916 * @param __x A %weibull_distribution random number
3917 * generator engine.
3919 * @returns The input stream with @p __x extracted or in an error state.
3921 template<typename _RealType, typename _CharT, typename _Traits>
3922 std::basic_istream<_CharT, _Traits>&
3923 operator>>(std::basic_istream<_CharT, _Traits>&,
3924 std::weibull_distribution<_RealType>&);
3928 * @brief A extreme_value_distribution random number distribution.
3930 * The formula for the normal probability mass function is
3931 * @f$ p(x|a,b) = \frac{1}{b}
3932 * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) @f$
3934 template<typename _RealType = double>
3935 class extreme_value_distribution
3937 static_assert(std::is_floating_point<_RealType>::value,
3938 "template argument not a floating point type");
3940 public:
3941 /** The type of the range of the distribution. */
3942 typedef _RealType result_type;
3943 /** Parameter type. */
3944 struct param_type
3946 typedef extreme_value_distribution<_RealType> distribution_type;
3948 explicit
3949 param_type(_RealType __a = _RealType(0),
3950 _RealType __b = _RealType(1))
3951 : _M_a(__a), _M_b(__b)
3954 _RealType
3955 a() const
3956 { return _M_a; }
3958 _RealType
3959 b() const
3960 { return _M_b; }
3962 private:
3963 _RealType _M_a;
3964 _RealType _M_b;
3967 explicit
3968 extreme_value_distribution(_RealType __a = _RealType(0),
3969 _RealType __b = _RealType(1))
3970 : _M_param(__a, __b)
3973 explicit
3974 extreme_value_distribution(const param_type& __p)
3975 : _M_param(__p)
3979 * @brief Resets the distribution state.
3981 void
3982 reset()
3986 * @brief Return the @f$ a @f$ parameter of the distribution.
3988 _RealType
3989 a() const
3990 { return _M_param.a(); }
3993 * @brief Return the @f$ b @f$ parameter of the distribution.
3995 _RealType
3996 b() const
3997 { return _M_param.b(); }
4000 * @brief Returns the parameter set of the distribution.
4002 param_type
4003 param() const
4004 { return _M_param; }
4007 * @brief Sets the parameter set of the distribution.
4008 * @param __param The new parameter set of the distribution.
4010 void
4011 param(const param_type& __param)
4012 { _M_param = __param; }
4015 * @brief Returns the greatest lower bound value of the distribution.
4017 result_type
4018 min() const
4019 { return std::numeric_limits<result_type>::min(); }
4022 * @brief Returns the least upper bound value of the distribution.
4024 result_type
4025 max() const
4026 { return std::numeric_limits<result_type>::max(); }
4028 template<typename _UniformRandomNumberGenerator>
4029 result_type
4030 operator()(_UniformRandomNumberGenerator& __urng)
4031 { return this->operator()(__urng, this->param()); }
4033 template<typename _UniformRandomNumberGenerator>
4034 result_type
4035 operator()(_UniformRandomNumberGenerator& __urng,
4036 const param_type& __p);
4038 private:
4039 param_type _M_param;
4043 * @brief Inserts a %extreme_value_distribution random number distribution
4044 * @p __x into the output stream @p __os.
4046 * @param __os An output stream.
4047 * @param __x A %extreme_value_distribution random number distribution.
4049 * @returns The output stream with the state of @p __x inserted or in
4050 * an error state.
4052 template<typename _RealType, typename _CharT, typename _Traits>
4053 std::basic_ostream<_CharT, _Traits>&
4054 operator<<(std::basic_ostream<_CharT, _Traits>&,
4055 const std::extreme_value_distribution<_RealType>&);
4058 * @brief Extracts a %extreme_value_distribution random number
4059 * distribution @p __x from the input stream @p __is.
4061 * @param __is An input stream.
4062 * @param __x A %extreme_value_distribution random number
4063 * generator engine.
4065 * @returns The input stream with @p __x extracted or in an error state.
4067 template<typename _RealType, typename _CharT, typename _Traits>
4068 std::basic_istream<_CharT, _Traits>&
4069 operator>>(std::basic_istream<_CharT, _Traits>&,
4070 std::extreme_value_distribution<_RealType>&);
4074 * @brief A discrete_distribution random number distribution.
4076 * The formula for the discrete probability mass function is
4079 template<typename _IntType = int>
4080 class discrete_distribution
4082 static_assert(std::is_integral<_IntType>::value,
4083 "template argument not an integral type");
4085 public:
4086 /** The type of the range of the distribution. */
4087 typedef _IntType result_type;
4088 /** Parameter type. */
4089 struct param_type
4091 typedef discrete_distribution<_IntType> distribution_type;
4092 friend class discrete_distribution<_IntType>;
4094 param_type()
4095 : _M_prob(), _M_cp()
4096 { _M_initialize(); }
4098 template<typename _InputIterator>
4099 param_type(_InputIterator __wbegin,
4100 _InputIterator __wend)
4101 : _M_prob(__wbegin, __wend), _M_cp()
4102 { _M_initialize(); }
4104 param_type(initializer_list<double> __wil)
4105 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4106 { _M_initialize(); }
4108 template<typename _Func>
4109 param_type(size_t __nw, double __xmin, double __xmax,
4110 _Func __fw);
4112 std::vector<double>
4113 probabilities() const
4114 { return _M_prob; }
4116 private:
4117 void
4118 _M_initialize();
4120 std::vector<double> _M_prob;
4121 std::vector<double> _M_cp;
4124 discrete_distribution()
4125 : _M_param()
4128 template<typename _InputIterator>
4129 discrete_distribution(_InputIterator __wbegin,
4130 _InputIterator __wend)
4131 : _M_param(__wbegin, __wend)
4134 discrete_distribution(initializer_list<double> __wl)
4135 : _M_param(__wl)
4138 template<typename _Func>
4139 discrete_distribution(size_t __nw, double __xmin, double __xmax,
4140 _Func __fw)
4141 : _M_param(__nw, __xmin, __xmax, __fw)
4144 explicit
4145 discrete_distribution(const param_type& __p)
4146 : _M_param(__p)
4150 * @brief Resets the distribution state.
4152 void
4153 reset()
4157 * @brief Returns the probabilities of the distribution.
4159 std::vector<double>
4160 probabilities() const
4161 { return _M_param.probabilities(); }
4164 * @brief Returns the parameter set of the distribution.
4166 param_type
4167 param() const
4168 { return _M_param; }
4171 * @brief Sets the parameter set of the distribution.
4172 * @param __param The new parameter set of the distribution.
4174 void
4175 param(const param_type& __param)
4176 { _M_param = __param; }
4179 * @brief Returns the greatest lower bound value of the distribution.
4181 result_type
4182 min() const
4183 { return result_type(0); }
4186 * @brief Returns the least upper bound value of the distribution.
4188 result_type
4189 max() const
4190 { return this->_M_param._M_prob.size() - 1; }
4192 template<typename _UniformRandomNumberGenerator>
4193 result_type
4194 operator()(_UniformRandomNumberGenerator& __urng)
4195 { return this->operator()(__urng, this->param()); }
4197 template<typename _UniformRandomNumberGenerator>
4198 result_type
4199 operator()(_UniformRandomNumberGenerator& __urng,
4200 const param_type& __p);
4203 * @brief Inserts a %discrete_distribution random number distribution
4204 * @p __x into the output stream @p __os.
4206 * @param __os An output stream.
4207 * @param __x A %discrete_distribution random number distribution.
4209 * @returns The output stream with the state of @p __x inserted or in
4210 * an error state.
4212 template<typename _IntType1, typename _CharT, typename _Traits>
4213 friend std::basic_ostream<_CharT, _Traits>&
4214 operator<<(std::basic_ostream<_CharT, _Traits>&,
4215 const std::discrete_distribution<_IntType1>&);
4218 * @brief Extracts a %discrete_distribution random number distribution
4219 * @p __x from the input stream @p __is.
4221 * @param __is An input stream.
4222 * @param __x A %discrete_distribution random number
4223 * generator engine.
4225 * @returns The input stream with @p __x extracted or in an error
4226 * state.
4228 template<typename _IntType1, typename _CharT, typename _Traits>
4229 friend std::basic_istream<_CharT, _Traits>&
4230 operator>>(std::basic_istream<_CharT, _Traits>&,
4231 std::discrete_distribution<_IntType1>&);
4233 private:
4234 param_type _M_param;
4239 * @brief A piecewise_constant_distribution random number distribution.
4241 * The formula for the piecewise constant probability mass function is
4244 template<typename _RealType = double>
4245 class piecewise_constant_distribution
4247 static_assert(std::is_floating_point<_RealType>::value,
4248 "template argument not a floating point type");
4250 public:
4251 /** The type of the range of the distribution. */
4252 typedef _RealType result_type;
4253 /** Parameter type. */
4254 struct param_type
4256 typedef piecewise_constant_distribution<_RealType> distribution_type;
4257 friend class piecewise_constant_distribution<_RealType>;
4259 param_type()
4260 : _M_int(), _M_den(), _M_cp()
4261 { _M_initialize(); }
4263 template<typename _InputIteratorB, typename _InputIteratorW>
4264 param_type(_InputIteratorB __bfirst,
4265 _InputIteratorB __bend,
4266 _InputIteratorW __wbegin);
4268 template<typename _Func>
4269 param_type(initializer_list<_RealType> __bi, _Func __fw);
4271 template<typename _Func>
4272 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4273 _Func __fw);
4275 std::vector<_RealType>
4276 intervals() const
4277 { return _M_int; }
4279 std::vector<double>
4280 densities() const
4281 { return _M_den; }
4283 private:
4284 void
4285 _M_initialize();
4287 std::vector<_RealType> _M_int;
4288 std::vector<double> _M_den;
4289 std::vector<double> _M_cp;
4292 explicit
4293 piecewise_constant_distribution()
4294 : _M_param()
4297 template<typename _InputIteratorB, typename _InputIteratorW>
4298 piecewise_constant_distribution(_InputIteratorB __bfirst,
4299 _InputIteratorB __bend,
4300 _InputIteratorW __wbegin)
4301 : _M_param(__bfirst, __bend, __wbegin)
4304 template<typename _Func>
4305 piecewise_constant_distribution(initializer_list<_RealType> __bl,
4306 _Func __fw)
4307 : _M_param(__bl, __fw)
4310 template<typename _Func>
4311 piecewise_constant_distribution(size_t __nw,
4312 _RealType __xmin, _RealType __xmax,
4313 _Func __fw)
4314 : _M_param(__nw, __xmin, __xmax, __fw)
4317 explicit
4318 piecewise_constant_distribution(const param_type& __p)
4319 : _M_param(__p)
4323 * @brief Resets the distribution state.
4325 void
4326 reset()
4330 * @brief Returns a vector of the intervals.
4332 std::vector<_RealType>
4333 intervals() const
4334 { return _M_param.intervals(); }
4337 * @brief Returns a vector of the probability densities.
4339 std::vector<double>
4340 densities() const
4341 { return _M_param.densities(); }
4344 * @brief Returns the parameter set of the distribution.
4346 param_type
4347 param() const
4348 { return _M_param; }
4351 * @brief Sets the parameter set of the distribution.
4352 * @param __param The new parameter set of the distribution.
4354 void
4355 param(const param_type& __param)
4356 { _M_param = __param; }
4359 * @brief Returns the greatest lower bound value of the distribution.
4361 result_type
4362 min() const
4363 { return this->_M_param._M_int.front(); }
4366 * @brief Returns the least upper bound value of the distribution.
4368 result_type
4369 max() const
4370 { return this->_M_param._M_int.back(); }
4372 template<typename _UniformRandomNumberGenerator>
4373 result_type
4374 operator()(_UniformRandomNumberGenerator& __urng)
4375 { return this->operator()(__urng, this->param()); }
4377 template<typename _UniformRandomNumberGenerator>
4378 result_type
4379 operator()(_UniformRandomNumberGenerator& __urng,
4380 const param_type& __p);
4383 * @brief Inserts a %piecewise_constan_distribution random
4384 * number distribution @p __x into the output stream @p __os.
4386 * @param __os An output stream.
4387 * @param __x A %piecewise_constan_distribution random number
4388 * distribution.
4390 * @returns The output stream with the state of @p __x inserted or in
4391 * an error state.
4393 template<typename _RealType1, typename _CharT, typename _Traits>
4394 friend std::basic_ostream<_CharT, _Traits>&
4395 operator<<(std::basic_ostream<_CharT, _Traits>&,
4396 const std::piecewise_constant_distribution<_RealType1>&);
4399 * @brief Extracts a %piecewise_constan_distribution random
4400 * number distribution @p __x from the input stream @p __is.
4402 * @param __is An input stream.
4403 * @param __x A %piecewise_constan_distribution random number
4404 * generator engine.
4406 * @returns The input stream with @p __x extracted or in an error
4407 * state.
4409 template<typename _RealType1, typename _CharT, typename _Traits>
4410 friend std::basic_istream<_CharT, _Traits>&
4411 operator>>(std::basic_istream<_CharT, _Traits>&,
4412 std::piecewise_constant_distribution<_RealType1>&);
4414 private:
4415 param_type _M_param;
4420 * @brief A piecewise_linear_distribution random number distribution.
4422 * The formula for the piecewise linear probability mass function is
4425 template<typename _RealType = double>
4426 class piecewise_linear_distribution
4428 static_assert(std::is_floating_point<_RealType>::value,
4429 "template argument not a floating point type");
4431 public:
4432 /** The type of the range of the distribution. */
4433 typedef _RealType result_type;
4434 /** Parameter type. */
4435 struct param_type
4437 typedef piecewise_linear_distribution<_RealType> distribution_type;
4438 friend class piecewise_linear_distribution<_RealType>;
4440 param_type()
4441 : _M_int(), _M_den(), _M_cp(), _M_m()
4442 { _M_initialize(); }
4444 template<typename _InputIteratorB, typename _InputIteratorW>
4445 param_type(_InputIteratorB __bfirst,
4446 _InputIteratorB __bend,
4447 _InputIteratorW __wbegin);
4449 template<typename _Func>
4450 param_type(initializer_list<_RealType> __bl, _Func __fw);
4452 template<typename _Func>
4453 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4454 _Func __fw);
4456 std::vector<_RealType>
4457 intervals() const
4458 { return _M_int; }
4460 std::vector<double>
4461 densities() const
4462 { return _M_den; }
4464 private:
4465 void
4466 _M_initialize();
4468 std::vector<_RealType> _M_int;
4469 std::vector<double> _M_den;
4470 std::vector<double> _M_cp;
4471 std::vector<double> _M_m;
4474 explicit
4475 piecewise_linear_distribution()
4476 : _M_param()
4479 template<typename _InputIteratorB, typename _InputIteratorW>
4480 piecewise_linear_distribution(_InputIteratorB __bfirst,
4481 _InputIteratorB __bend,
4482 _InputIteratorW __wbegin)
4483 : _M_param(__bfirst, __bend, __wbegin)
4486 template<typename _Func>
4487 piecewise_linear_distribution(initializer_list<_RealType> __bl,
4488 _Func __fw)
4489 : _M_param(__bl, __fw)
4492 template<typename _Func>
4493 piecewise_linear_distribution(size_t __nw,
4494 _RealType __xmin, _RealType __xmax,
4495 _Func __fw)
4496 : _M_param(__nw, __xmin, __xmax, __fw)
4499 explicit
4500 piecewise_linear_distribution(const param_type& __p)
4501 : _M_param(__p)
4505 * Resets the distribution state.
4507 void
4508 reset()
4512 * @brief Return the intervals of the distribution.
4514 std::vector<_RealType>
4515 intervals() const
4516 { return _M_param.intervals(); }
4519 * @brief Return a vector of the probability densities of the
4520 * distribution.
4522 std::vector<double>
4523 densities() const
4524 { return _M_param.densities(); }
4527 * @brief Returns the parameter set of the distribution.
4529 param_type
4530 param() const
4531 { return _M_param; }
4534 * @brief Sets the parameter set of the distribution.
4535 * @param __param The new parameter set of the distribution.
4537 void
4538 param(const param_type& __param)
4539 { _M_param = __param; }
4542 * @brief Returns the greatest lower bound value of the distribution.
4544 result_type
4545 min() const
4546 { return this->_M_param._M_int.front(); }
4549 * @brief Returns the least upper bound value of the distribution.
4551 result_type
4552 max() const
4553 { return this->_M_param._M_int.back(); }
4555 template<typename _UniformRandomNumberGenerator>
4556 result_type
4557 operator()(_UniformRandomNumberGenerator& __urng)
4558 { return this->operator()(__urng, this->param()); }
4560 template<typename _UniformRandomNumberGenerator>
4561 result_type
4562 operator()(_UniformRandomNumberGenerator& __urng,
4563 const param_type& __p);
4566 * @brief Inserts a %piecewise_linear_distribution random number
4567 * distribution @p __x into the output stream @p __os.
4569 * @param __os An output stream.
4570 * @param __x A %piecewise_linear_distribution random number
4571 * distribution.
4573 * @returns The output stream with the state of @p __x inserted or in
4574 * an error state.
4576 template<typename _RealType1, typename _CharT, typename _Traits>
4577 friend std::basic_ostream<_CharT, _Traits>&
4578 operator<<(std::basic_ostream<_CharT, _Traits>&,
4579 const std::piecewise_linear_distribution<_RealType1>&);
4582 * @brief Extracts a %piecewise_linear_distribution random number
4583 * distribution @p __x from the input stream @p __is.
4585 * @param __is An input stream.
4586 * @param __x A %piecewise_linear_distribution random number
4587 * generator engine.
4589 * @returns The input stream with @p __x extracted or in an error
4590 * state.
4592 template<typename _RealType1, typename _CharT, typename _Traits>
4593 friend std::basic_istream<_CharT, _Traits>&
4594 operator>>(std::basic_istream<_CharT, _Traits>&,
4595 std::piecewise_linear_distribution<_RealType1>&);
4597 private:
4598 param_type _M_param;
4602 /* @} */ // group std_random_distributions_poisson
4604 /* @} */ // group std_random_distributions
4607 * @addtogroup std_random_utilities Random Number Utilities
4608 * @ingroup std_random
4609 * @{
4613 * @brief The seed_seq class generates sequences of seeds for random
4614 * number generators.
4616 class seed_seq
4619 public:
4620 /** The type of the seed vales. */
4621 typedef uint_least32_t result_type;
4623 /** Default constructor. */
4624 seed_seq()
4625 : _M_v()
4628 template<typename _IntType>
4629 seed_seq(std::initializer_list<_IntType> il);
4631 template<typename _InputIterator>
4632 seed_seq(_InputIterator __begin, _InputIterator __end);
4634 // generating functions
4635 template<typename _RandomAccessIterator>
4636 void
4637 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
4639 // property functions
4640 size_t size() const
4641 { return _M_v.size(); }
4643 template<typename OutputIterator>
4644 void
4645 param(OutputIterator __dest) const
4646 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
4648 private:
4650 std::vector<result_type> _M_v;
4653 /* @} */ // group std_random_utilities
4655 /* @} */ // group std_random