libstdc++
random.h
Go to the documentation of this file.
1 // random number generation -*- C++ -*-
2 
3 // Copyright (C) 2009, 2010, 2011, 2012 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.
10 
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.
15 
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.
19 
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/>.
24 
25 /**
26  * @file bits/random.h
27  * This is an internal header file, included by other library headers.
28  * Do not attempt to use it directly. @headername{random}
29  */
30 
31 #ifndef _RANDOM_H
32 #define _RANDOM_H 1
33 
34 #include <vector>
35 
36 namespace std _GLIBCXX_VISIBILITY(default)
37 {
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
39 
40  // [26.4] Random number generation
41 
42  /**
43  * @defgroup random Random Number Generation
44  * @ingroup numerics
45  *
46  * A facility for generating random numbers on selected distributions.
47  * @{
48  */
49 
50  /**
51  * @brief A function template for converting the output of a (integral)
52  * uniform random number generator to a floatng point result in the range
53  * [0-1).
54  */
55  template<typename _RealType, size_t __bits,
56  typename _UniformRandomNumberGenerator>
57  _RealType
58  generate_canonical(_UniformRandomNumberGenerator& __g);
59 
60 _GLIBCXX_END_NAMESPACE_VERSION
61 
62  /*
63  * Implementation-space details.
64  */
65  namespace __detail
66  {
67  _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 
69  template<typename _UIntType, size_t __w,
70  bool = __w < static_cast<size_t>
72  struct _Shift
73  { static const _UIntType __value = 0; };
74 
75  template<typename _UIntType, size_t __w>
76  struct _Shift<_UIntType, __w, true>
77  { static const _UIntType __value = _UIntType(1) << __w; };
78 
79  template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
80  struct _Mod;
81 
82  // Dispatch based on modulus value to prevent divide-by-zero compile-time
83  // errors when m == 0.
84  template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
85  inline _Tp
86  __mod(_Tp __x)
87  { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
88 
89  /*
90  * An adaptor class for converting the output of any Generator into
91  * the input for a specific Distribution.
92  */
93  template<typename _Engine, typename _DInputType>
94  struct _Adaptor
95  {
96 
97  public:
98  _Adaptor(_Engine& __g)
99  : _M_g(__g) { }
100 
101  _DInputType
102  min() const
103  { return _DInputType(0); }
104 
105  _DInputType
106  max() const
107  { return _DInputType(1); }
108 
109  /*
110  * Converts a value generated by the adapted random number generator
111  * into a value in the input domain for the dependent random number
112  * distribution.
113  */
114  _DInputType
115  operator()()
116  {
117  return std::generate_canonical<_DInputType,
119  _Engine>(_M_g);
120  }
121 
122  private:
123  _Engine& _M_g;
124  };
125 
126  _GLIBCXX_END_NAMESPACE_VERSION
127  } // namespace __detail
128 
129 _GLIBCXX_BEGIN_NAMESPACE_VERSION
130 
131  /**
132  * @addtogroup random_generators Random Number Generators
133  * @ingroup random
134  *
135  * These classes define objects which provide random or pseudorandom
136  * numbers, either from a discrete or a continuous interval. The
137  * random number generator supplied as a part of this library are
138  * all uniform random number generators which provide a sequence of
139  * random number uniformly distributed over their range.
140  *
141  * A number generator is a function object with an operator() that
142  * takes zero arguments and returns a number.
143  *
144  * A compliant random number generator must satisfy the following
145  * requirements. <table border=1 cellpadding=10 cellspacing=0>
146  * <caption align=top>Random Number Generator Requirements</caption>
147  * <tr><td>To be documented.</td></tr> </table>
148  *
149  * @{
150  */
151 
152  /**
153  * @brief A model of a linear congruential random number generator.
154  *
155  * A random number generator that produces pseudorandom numbers via
156  * linear function:
157  * @f[
158  * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
159  * @f]
160  *
161  * The template parameter @p _UIntType must be an unsigned integral type
162  * large enough to store values up to (__m-1). If the template parameter
163  * @p __m is 0, the modulus @p __m used is
164  * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
165  * parameters @p __a and @p __c must be less than @p __m.
166  *
167  * The size of the state is @f$1@f$.
168  */
169  template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
171  {
172  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
173  "substituting _UIntType not an unsigned integral type");
174  static_assert(__m == 0u || (__a < __m && __c < __m),
175  "template argument substituting __m out of bounds");
176 
177  // XXX FIXME:
178  // _Mod::__calc should handle correctly __m % __a >= __m / __a too.
179  static_assert(__m % __a < __m / __a,
180  "sorry, not implemented yet: try a smaller 'a' constant");
181 
182  public:
183  /** The type of the generated random value. */
184  typedef _UIntType result_type;
185 
186  /** The multiplier. */
187  static constexpr result_type multiplier = __a;
188  /** An increment. */
189  static constexpr result_type increment = __c;
190  /** The modulus. */
191  static constexpr result_type modulus = __m;
192  static constexpr result_type default_seed = 1u;
193 
194  /**
195  * @brief Constructs a %linear_congruential_engine random number
196  * generator engine with seed @p __s. The default seed value
197  * is 1.
198  *
199  * @param __s The initial seed value.
200  */
201  explicit
203  { seed(__s); }
204 
205  /**
206  * @brief Constructs a %linear_congruential_engine random number
207  * generator engine seeded from the seed sequence @p __q.
208  *
209  * @param __q the seed sequence.
210  */
211  template<typename _Sseq, typename = typename
213  ::type>
214  explicit
216  { seed(__q); }
217 
218  /**
219  * @brief Reseeds the %linear_congruential_engine random number generator
220  * engine sequence to the seed @p __s.
221  *
222  * @param __s The new seed.
223  */
224  void
225  seed(result_type __s = default_seed);
226 
227  /**
228  * @brief Reseeds the %linear_congruential_engine random number generator
229  * engine
230  * sequence using values from the seed sequence @p __q.
231  *
232  * @param __q the seed sequence.
233  */
234  template<typename _Sseq>
236  seed(_Sseq& __q);
237 
238  /**
239  * @brief Gets the smallest possible value in the output range.
240  *
241  * The minimum depends on the @p __c parameter: if it is zero, the
242  * minimum generated must be > 0, otherwise 0 is allowed.
243  */
244  static constexpr result_type
245  min()
246  { return __c == 0u ? 1u : 0u; }
247 
248  /**
249  * @brief Gets the largest possible value in the output range.
250  */
251  static constexpr result_type
252  max()
253  { return __m - 1u; }
254 
255  /**
256  * @brief Discard a sequence of random numbers.
257  */
258  void
259  discard(unsigned long long __z)
260  {
261  for (; __z != 0ULL; --__z)
262  (*this)();
263  }
264 
265  /**
266  * @brief Gets the next random number in the sequence.
267  */
270  {
271  _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
272  return _M_x;
273  }
274 
275  /**
276  * @brief Compares two linear congruential random number generator
277  * objects of the same type for equality.
278  *
279  * @param __lhs A linear congruential random number generator object.
280  * @param __rhs Another linear congruential random number generator
281  * object.
282  *
283  * @returns true if the infinite sequences of generated values
284  * would be equal, false otherwise.
285  */
286  friend bool
288  const linear_congruential_engine& __rhs)
289  { return __lhs._M_x == __rhs._M_x; }
290 
291  /**
292  * @brief Writes the textual representation of the state x(i) of x to
293  * @p __os.
294  *
295  * @param __os The output stream.
296  * @param __lcr A % linear_congruential_engine random number generator.
297  * @returns __os.
298  */
299  template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
300  _UIntType1 __m1, typename _CharT, typename _Traits>
302  operator<<(std::basic_ostream<_CharT, _Traits>&,
303  const std::linear_congruential_engine<_UIntType1,
304  __a1, __c1, __m1>&);
305 
306  /**
307  * @brief Sets the state of the engine by reading its textual
308  * representation from @p __is.
309  *
310  * The textual representation must have been previously written using
311  * an output stream whose imbued locale and whose type's template
312  * specialization arguments _CharT and _Traits were the same as those
313  * of @p __is.
314  *
315  * @param __is The input stream.
316  * @param __lcr A % linear_congruential_engine random number generator.
317  * @returns __is.
318  */
319  template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
320  _UIntType1 __m1, typename _CharT, typename _Traits>
323  std::linear_congruential_engine<_UIntType1, __a1,
324  __c1, __m1>&);
325 
326  private:
327  _UIntType _M_x;
328  };
329 
330  /**
331  * @brief Compares two linear congruential random number generator
332  * objects of the same type for inequality.
333  *
334  * @param __lhs A linear congruential random number generator object.
335  * @param __rhs Another linear congruential random number generator
336  * object.
337  *
338  * @returns true if the infinite sequences of generated values
339  * would be different, false otherwise.
340  */
341  template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
342  inline bool
343  operator!=(const std::linear_congruential_engine<_UIntType, __a,
344  __c, __m>& __lhs,
345  const std::linear_congruential_engine<_UIntType, __a,
346  __c, __m>& __rhs)
347  { return !(__lhs == __rhs); }
348 
349 
350  /**
351  * A generalized feedback shift register discrete random number generator.
352  *
353  * This algorithm avoids multiplication and division and is designed to be
354  * friendly to a pipelined architecture. If the parameters are chosen
355  * correctly, this generator will produce numbers with a very long period and
356  * fairly good apparent entropy, although still not cryptographically strong.
357  *
358  * The best way to use this generator is with the predefined mt19937 class.
359  *
360  * This algorithm was originally invented by Makoto Matsumoto and
361  * Takuji Nishimura.
362  *
363  * @var word_size The number of bits in each element of the state vector.
364  * @var state_size The degree of recursion.
365  * @var shift_size The period parameter.
366  * @var mask_bits The separation point bit index.
367  * @var parameter_a The last row of the twist matrix.
368  * @var output_u The first right-shift tempering matrix parameter.
369  * @var output_s The first left-shift tempering matrix parameter.
370  * @var output_b The first left-shift tempering matrix mask.
371  * @var output_t The second left-shift tempering matrix parameter.
372  * @var output_c The second left-shift tempering matrix mask.
373  * @var output_l The second right-shift tempering matrix parameter.
374  */
375  template<typename _UIntType, size_t __w,
376  size_t __n, size_t __m, size_t __r,
377  _UIntType __a, size_t __u, _UIntType __d, size_t __s,
378  _UIntType __b, size_t __t,
379  _UIntType __c, size_t __l, _UIntType __f>
380  class mersenne_twister_engine
381  {
382  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
383  "substituting _UIntType not an unsigned integral type");
384  static_assert(1u <= __m && __m <= __n,
385  "template argument substituting __m out of bounds");
386  static_assert(__r <= __w, "template argument substituting "
387  "__r out of bound");
388  static_assert(__u <= __w, "template argument substituting "
389  "__u out of bound");
390  static_assert(__s <= __w, "template argument substituting "
391  "__s out of bound");
392  static_assert(__t <= __w, "template argument substituting "
393  "__t out of bound");
394  static_assert(__l <= __w, "template argument substituting "
395  "__l out of bound");
396  static_assert(__w <= std::numeric_limits<_UIntType>::digits,
397  "template argument substituting __w out of bound");
398  static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
399  "template argument substituting __a out of bound");
400  static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
401  "template argument substituting __b out of bound");
402  static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
403  "template argument substituting __c out of bound");
404  static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
405  "template argument substituting __d out of bound");
406  static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
407  "template argument substituting __f out of bound");
408 
409  public:
410  /** The type of the generated random value. */
411  typedef _UIntType result_type;
412 
413  // parameter values
414  static constexpr size_t word_size = __w;
415  static constexpr size_t state_size = __n;
416  static constexpr size_t shift_size = __m;
417  static constexpr size_t mask_bits = __r;
418  static constexpr result_type xor_mask = __a;
419  static constexpr size_t tempering_u = __u;
420  static constexpr result_type tempering_d = __d;
421  static constexpr size_t tempering_s = __s;
422  static constexpr result_type tempering_b = __b;
423  static constexpr size_t tempering_t = __t;
424  static constexpr result_type tempering_c = __c;
425  static constexpr size_t tempering_l = __l;
426  static constexpr result_type initialization_multiplier = __f;
427  static constexpr result_type default_seed = 5489u;
428 
429  // constructors and member function
430  explicit
431  mersenne_twister_engine(result_type __sd = default_seed)
432  { seed(__sd); }
433 
434  /**
435  * @brief Constructs a %mersenne_twister_engine random number generator
436  * engine seeded from the seed sequence @p __q.
437  *
438  * @param __q the seed sequence.
439  */
440  template<typename _Sseq, typename = typename
442  ::type>
443  explicit
444  mersenne_twister_engine(_Sseq& __q)
445  { seed(__q); }
446 
447  void
448  seed(result_type __sd = default_seed);
449 
450  template<typename _Sseq>
452  seed(_Sseq& __q);
453 
454  /**
455  * @brief Gets the smallest possible value in the output range.
456  */
457  static constexpr result_type
458  min()
459  { return 0; };
460 
461  /**
462  * @brief Gets the largest possible value in the output range.
463  */
464  static constexpr result_type
465  max()
466  { return __detail::_Shift<_UIntType, __w>::__value - 1; }
467 
468  /**
469  * @brief Discard a sequence of random numbers.
470  */
471  void
472  discard(unsigned long long __z)
473  {
474  for (; __z != 0ULL; --__z)
475  (*this)();
476  }
477 
478  result_type
479  operator()();
480 
481  /**
482  * @brief Compares two % mersenne_twister_engine random number generator
483  * objects of the same type for equality.
484  *
485  * @param __lhs A % mersenne_twister_engine random number generator
486  * object.
487  * @param __rhs Another % mersenne_twister_engine random number
488  * generator object.
489  *
490  * @returns true if the infinite sequences of generated values
491  * would be equal, false otherwise.
492  */
493  friend bool
494  operator==(const mersenne_twister_engine& __lhs,
495  const mersenne_twister_engine& __rhs)
496  { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
497 
498  /**
499  * @brief Inserts the current state of a % mersenne_twister_engine
500  * random number generator engine @p __x into the output stream
501  * @p __os.
502  *
503  * @param __os An output stream.
504  * @param __x A % mersenne_twister_engine random number generator
505  * engine.
506  *
507  * @returns The output stream with the state of @p __x inserted or in
508  * an error state.
509  */
510  template<typename _UIntType1,
511  size_t __w1, size_t __n1,
512  size_t __m1, size_t __r1,
513  _UIntType1 __a1, size_t __u1,
514  _UIntType1 __d1, size_t __s1,
515  _UIntType1 __b1, size_t __t1,
516  _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
517  typename _CharT, typename _Traits>
519  operator<<(std::basic_ostream<_CharT, _Traits>&,
520  const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
521  __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
522  __l1, __f1>&);
523 
524  /**
525  * @brief Extracts the current state of a % mersenne_twister_engine
526  * random number generator engine @p __x from the input stream
527  * @p __is.
528  *
529  * @param __is An input stream.
530  * @param __x A % mersenne_twister_engine random number generator
531  * engine.
532  *
533  * @returns The input stream with the state of @p __x extracted or in
534  * an error state.
535  */
536  template<typename _UIntType1,
537  size_t __w1, size_t __n1,
538  size_t __m1, size_t __r1,
539  _UIntType1 __a1, size_t __u1,
540  _UIntType1 __d1, size_t __s1,
541  _UIntType1 __b1, size_t __t1,
542  _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
543  typename _CharT, typename _Traits>
546  std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
547  __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
548  __l1, __f1>&);
549 
550  private:
551  _UIntType _M_x[state_size];
552  size_t _M_p;
553  };
554 
555  /**
556  * @brief Compares two % mersenne_twister_engine random number generator
557  * objects of the same type for inequality.
558  *
559  * @param __lhs A % mersenne_twister_engine random number generator
560  * object.
561  * @param __rhs Another % mersenne_twister_engine random number
562  * generator object.
563  *
564  * @returns true if the infinite sequences of generated values
565  * would be different, false otherwise.
566  */
567  template<typename _UIntType, size_t __w,
568  size_t __n, size_t __m, size_t __r,
569  _UIntType __a, size_t __u, _UIntType __d, size_t __s,
570  _UIntType __b, size_t __t,
571  _UIntType __c, size_t __l, _UIntType __f>
572  inline bool
573  operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
574  __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
575  const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
576  __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
577  { return !(__lhs == __rhs); }
578 
579 
580  /**
581  * @brief The Marsaglia-Zaman generator.
582  *
583  * This is a model of a Generalized Fibonacci discrete random number
584  * generator, sometimes referred to as the SWC generator.
585  *
586  * A discrete random number generator that produces pseudorandom
587  * numbers using:
588  * @f[
589  * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
590  * @f]
591  *
592  * The size of the state is @f$r@f$
593  * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
594  *
595  * @var _M_x The state of the generator. This is a ring buffer.
596  * @var _M_carry The carry.
597  * @var _M_p Current index of x(i - r).
598  */
599  template<typename _UIntType, size_t __w, size_t __s, size_t __r>
600  class subtract_with_carry_engine
601  {
602  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
603  "substituting _UIntType not an unsigned integral type");
604  static_assert(0u < __s && __s < __r,
605  "template argument substituting __s out of bounds");
606  static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
607  "template argument substituting __w out of bounds");
608 
609  public:
610  /** The type of the generated random value. */
611  typedef _UIntType result_type;
612 
613  // parameter values
614  static constexpr size_t word_size = __w;
615  static constexpr size_t short_lag = __s;
616  static constexpr size_t long_lag = __r;
617  static constexpr result_type default_seed = 19780503u;
618 
619  /**
620  * @brief Constructs an explicitly seeded % subtract_with_carry_engine
621  * random number generator.
622  */
623  explicit
624  subtract_with_carry_engine(result_type __sd = default_seed)
625  { seed(__sd); }
626 
627  /**
628  * @brief Constructs a %subtract_with_carry_engine random number engine
629  * seeded from the seed sequence @p __q.
630  *
631  * @param __q the seed sequence.
632  */
633  template<typename _Sseq, typename = typename
635  ::type>
636  explicit
637  subtract_with_carry_engine(_Sseq& __q)
638  { seed(__q); }
639 
640  /**
641  * @brief Seeds the initial state @f$x_0@f$ of the random number
642  * generator.
643  *
644  * N1688[4.19] modifies this as follows. If @p __value == 0,
645  * sets value to 19780503. In any case, with a linear
646  * congruential generator lcg(i) having parameters @f$ m_{lcg} =
647  * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
648  * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
649  * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
650  * set carry to 1, otherwise sets carry to 0.
651  */
652  void
653  seed(result_type __sd = default_seed);
654 
655  /**
656  * @brief Seeds the initial state @f$x_0@f$ of the
657  * % subtract_with_carry_engine random number generator.
658  */
659  template<typename _Sseq>
661  seed(_Sseq& __q);
662 
663  /**
664  * @brief Gets the inclusive minimum value of the range of random
665  * integers returned by this generator.
666  */
667  static constexpr result_type
668  min()
669  { return 0; }
670 
671  /**
672  * @brief Gets the inclusive maximum value of the range of random
673  * integers returned by this generator.
674  */
675  static constexpr result_type
676  max()
677  { return __detail::_Shift<_UIntType, __w>::__value - 1; }
678 
679  /**
680  * @brief Discard a sequence of random numbers.
681  */
682  void
683  discard(unsigned long long __z)
684  {
685  for (; __z != 0ULL; --__z)
686  (*this)();
687  }
688 
689  /**
690  * @brief Gets the next random number in the sequence.
691  */
692  result_type
693  operator()();
694 
695  /**
696  * @brief Compares two % subtract_with_carry_engine random number
697  * generator objects of the same type for equality.
698  *
699  * @param __lhs A % subtract_with_carry_engine random number generator
700  * object.
701  * @param __rhs Another % subtract_with_carry_engine random number
702  * generator object.
703  *
704  * @returns true if the infinite sequences of generated values
705  * would be equal, false otherwise.
706  */
707  friend bool
708  operator==(const subtract_with_carry_engine& __lhs,
709  const subtract_with_carry_engine& __rhs)
710  { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
711 
712  /**
713  * @brief Inserts the current state of a % subtract_with_carry_engine
714  * random number generator engine @p __x into the output stream
715  * @p __os.
716  *
717  * @param __os An output stream.
718  * @param __x A % subtract_with_carry_engine random number generator
719  * engine.
720  *
721  * @returns The output stream with the state of @p __x inserted or in
722  * an error state.
723  */
724  template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
725  typename _CharT, typename _Traits>
727  operator<<(std::basic_ostream<_CharT, _Traits>&,
728  const std::subtract_with_carry_engine<_UIntType1, __w1,
729  __s1, __r1>&);
730 
731  /**
732  * @brief Extracts the current state of a % subtract_with_carry_engine
733  * random number generator engine @p __x from the input stream
734  * @p __is.
735  *
736  * @param __is An input stream.
737  * @param __x A % subtract_with_carry_engine random number generator
738  * engine.
739  *
740  * @returns The input stream with the state of @p __x extracted or in
741  * an error state.
742  */
743  template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
744  typename _CharT, typename _Traits>
747  std::subtract_with_carry_engine<_UIntType1, __w1,
748  __s1, __r1>&);
749 
750  private:
751  _UIntType _M_x[long_lag];
752  _UIntType _M_carry;
753  size_t _M_p;
754  };
755 
756  /**
757  * @brief Compares two % subtract_with_carry_engine random number
758  * generator objects of the same type for inequality.
759  *
760  * @param __lhs A % subtract_with_carry_engine random number generator
761  * object.
762  * @param __rhs Another % subtract_with_carry_engine random number
763  * generator object.
764  *
765  * @returns true if the infinite sequences of generated values
766  * would be different, false otherwise.
767  */
768  template<typename _UIntType, size_t __w, size_t __s, size_t __r>
769  inline bool
770  operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
771  __s, __r>& __lhs,
772  const std::subtract_with_carry_engine<_UIntType, __w,
773  __s, __r>& __rhs)
774  { return !(__lhs == __rhs); }
775 
776 
777  /**
778  * Produces random numbers from some base engine by discarding blocks of
779  * data.
780  *
781  * 0 <= @p __r <= @p __p
782  */
783  template<typename _RandomNumberEngine, size_t __p, size_t __r>
785  {
786  static_assert(1 <= __r && __r <= __p,
787  "template argument substituting __r out of bounds");
788 
789  public:
790  /** The type of the generated random value. */
791  typedef typename _RandomNumberEngine::result_type result_type;
792 
793  // parameter values
794  static constexpr size_t block_size = __p;
795  static constexpr size_t used_block = __r;
796 
797  /**
798  * @brief Constructs a default %discard_block_engine engine.
799  *
800  * The underlying engine is default constructed as well.
801  */
803  : _M_b(), _M_n(0) { }
804 
805  /**
806  * @brief Copy constructs a %discard_block_engine engine.
807  *
808  * Copies an existing base class random number generator.
809  * @param rng An existing (base class) engine object.
810  */
811  explicit
812  discard_block_engine(const _RandomNumberEngine& __rne)
813  : _M_b(__rne), _M_n(0) { }
814 
815  /**
816  * @brief Move constructs a %discard_block_engine engine.
817  *
818  * Copies an existing base class random number generator.
819  * @param rng An existing (base class) engine object.
820  */
821  explicit
822  discard_block_engine(_RandomNumberEngine&& __rne)
823  : _M_b(std::move(__rne)), _M_n(0) { }
824 
825  /**
826  * @brief Seed constructs a %discard_block_engine engine.
827  *
828  * Constructs the underlying generator engine seeded with @p __s.
829  * @param __s A seed value for the base class engine.
830  */
831  explicit
833  : _M_b(__s), _M_n(0) { }
834 
835  /**
836  * @brief Generator construct a %discard_block_engine engine.
837  *
838  * @param __q A seed sequence.
839  */
840  template<typename _Sseq, typename = typename
843  ::type>
844  explicit
846  : _M_b(__q), _M_n(0)
847  { }
848 
849  /**
850  * @brief Reseeds the %discard_block_engine object with the default
851  * seed for the underlying base class generator engine.
852  */
853  void
855  {
856  _M_b.seed();
857  _M_n = 0;
858  }
859 
860  /**
861  * @brief Reseeds the %discard_block_engine object with the default
862  * seed for the underlying base class generator engine.
863  */
864  void
866  {
867  _M_b.seed(__s);
868  _M_n = 0;
869  }
870 
871  /**
872  * @brief Reseeds the %discard_block_engine object with the given seed
873  * sequence.
874  * @param __q A seed generator function.
875  */
876  template<typename _Sseq>
877  void
878  seed(_Sseq& __q)
879  {
880  _M_b.seed(__q);
881  _M_n = 0;
882  }
883 
884  /**
885  * @brief Gets a const reference to the underlying generator engine
886  * object.
887  */
888  const _RandomNumberEngine&
889  base() const
890  { return _M_b; }
891 
892  /**
893  * @brief Gets the minimum value in the generated random number range.
894  */
895  static constexpr result_type
896  min()
897  { return _RandomNumberEngine::min(); }
898 
899  /**
900  * @brief Gets the maximum value in the generated random number range.
901  */
902  static constexpr result_type
903  max()
904  { return _RandomNumberEngine::max(); }
905 
906  /**
907  * @brief Discard a sequence of random numbers.
908  */
909  void
910  discard(unsigned long long __z)
911  {
912  for (; __z != 0ULL; --__z)
913  (*this)();
914  }
915 
916  /**
917  * @brief Gets the next value in the generated random number sequence.
918  */
920  operator()();
921 
922  /**
923  * @brief Compares two %discard_block_engine random number generator
924  * objects of the same type for equality.
925  *
926  * @param __lhs A %discard_block_engine random number generator object.
927  * @param __rhs Another %discard_block_engine random number generator
928  * object.
929  *
930  * @returns true if the infinite sequences of generated values
931  * would be equal, false otherwise.
932  */
933  friend bool
935  const discard_block_engine& __rhs)
936  { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
937 
938  /**
939  * @brief Inserts the current state of a %discard_block_engine random
940  * number generator engine @p __x into the output stream
941  * @p __os.
942  *
943  * @param __os An output stream.
944  * @param __x A %discard_block_engine random number generator engine.
945  *
946  * @returns The output stream with the state of @p __x inserted or in
947  * an error state.
948  */
949  template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
950  typename _CharT, typename _Traits>
952  operator<<(std::basic_ostream<_CharT, _Traits>&,
953  const std::discard_block_engine<_RandomNumberEngine1,
954  __p1, __r1>&);
955 
956  /**
957  * @brief Extracts the current state of a % subtract_with_carry_engine
958  * random number generator engine @p __x from the input stream
959  * @p __is.
960  *
961  * @param __is An input stream.
962  * @param __x A %discard_block_engine random number generator engine.
963  *
964  * @returns The input stream with the state of @p __x extracted or in
965  * an error state.
966  */
967  template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
968  typename _CharT, typename _Traits>
971  std::discard_block_engine<_RandomNumberEngine1,
972  __p1, __r1>&);
973 
974  private:
975  _RandomNumberEngine _M_b;
976  size_t _M_n;
977  };
978 
979  /**
980  * @brief Compares two %discard_block_engine random number generator
981  * objects of the same type for inequality.
982  *
983  * @param __lhs A %discard_block_engine random number generator object.
984  * @param __rhs Another %discard_block_engine random number generator
985  * object.
986  *
987  * @returns true if the infinite sequences of generated values
988  * would be different, false otherwise.
989  */
990  template<typename _RandomNumberEngine, size_t __p, size_t __r>
991  inline bool
992  operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
993  __r>& __lhs,
994  const std::discard_block_engine<_RandomNumberEngine, __p,
995  __r>& __rhs)
996  { return !(__lhs == __rhs); }
997 
998 
999  /**
1000  * Produces random numbers by combining random numbers from some base
1001  * engine to produce random numbers with a specifies number of bits @p __w.
1002  */
1003  template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1005  {
1006  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
1007  "substituting _UIntType not an unsigned integral type");
1008  static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
1009  "template argument substituting __w out of bounds");
1010 
1011  public:
1012  /** The type of the generated random value. */
1013  typedef _UIntType result_type;
1014 
1015  /**
1016  * @brief Constructs a default %independent_bits_engine engine.
1017  *
1018  * The underlying engine is default constructed as well.
1019  */
1021  : _M_b() { }
1022 
1023  /**
1024  * @brief Copy constructs a %independent_bits_engine engine.
1025  *
1026  * Copies an existing base class random number generator.
1027  * @param rng An existing (base class) engine object.
1028  */
1029  explicit
1030  independent_bits_engine(const _RandomNumberEngine& __rne)
1031  : _M_b(__rne) { }
1032 
1033  /**
1034  * @brief Move constructs a %independent_bits_engine engine.
1035  *
1036  * Copies an existing base class random number generator.
1037  * @param rng An existing (base class) engine object.
1038  */
1039  explicit
1040  independent_bits_engine(_RandomNumberEngine&& __rne)
1041  : _M_b(std::move(__rne)) { }
1042 
1043  /**
1044  * @brief Seed constructs a %independent_bits_engine engine.
1045  *
1046  * Constructs the underlying generator engine seeded with @p __s.
1047  * @param __s A seed value for the base class engine.
1048  */
1049  explicit
1051  : _M_b(__s) { }
1052 
1053  /**
1054  * @brief Generator construct a %independent_bits_engine engine.
1055  *
1056  * @param __q A seed sequence.
1057  */
1058  template<typename _Sseq, typename = typename
1061  ::type>
1062  explicit
1064  : _M_b(__q)
1065  { }
1066 
1067  /**
1068  * @brief Reseeds the %independent_bits_engine object with the default
1069  * seed for the underlying base class generator engine.
1070  */
1071  void
1073  { _M_b.seed(); }
1074 
1075  /**
1076  * @brief Reseeds the %independent_bits_engine object with the default
1077  * seed for the underlying base class generator engine.
1078  */
1079  void
1081  { _M_b.seed(__s); }
1082 
1083  /**
1084  * @brief Reseeds the %independent_bits_engine object with the given
1085  * seed sequence.
1086  * @param __q A seed generator function.
1087  */
1088  template<typename _Sseq>
1089  void
1090  seed(_Sseq& __q)
1091  { _M_b.seed(__q); }
1092 
1093  /**
1094  * @brief Gets a const reference to the underlying generator engine
1095  * object.
1096  */
1097  const _RandomNumberEngine&
1098  base() const
1099  { return _M_b; }
1100 
1101  /**
1102  * @brief Gets the minimum value in the generated random number range.
1103  */
1104  static constexpr result_type
1106  { return 0U; }
1107 
1108  /**
1109  * @brief Gets the maximum value in the generated random number range.
1110  */
1111  static constexpr result_type
1113  { return __detail::_Shift<_UIntType, __w>::__value - 1; }
1114 
1115  /**
1116  * @brief Discard a sequence of random numbers.
1117  */
1118  void
1119  discard(unsigned long long __z)
1120  {
1121  for (; __z != 0ULL; --__z)
1122  (*this)();
1123  }
1124 
1125  /**
1126  * @brief Gets the next value in the generated random number sequence.
1127  */
1128  result_type
1129  operator()();
1130 
1131  /**
1132  * @brief Compares two %independent_bits_engine random number generator
1133  * objects of the same type for equality.
1134  *
1135  * @param __lhs A %independent_bits_engine random number generator
1136  * object.
1137  * @param __rhs Another %independent_bits_engine random number generator
1138  * object.
1139  *
1140  * @returns true if the infinite sequences of generated values
1141  * would be equal, false otherwise.
1142  */
1143  friend bool
1145  const independent_bits_engine& __rhs)
1146  { return __lhs._M_b == __rhs._M_b; }
1147 
1148  /**
1149  * @brief Extracts the current state of a % subtract_with_carry_engine
1150  * random number generator engine @p __x from the input stream
1151  * @p __is.
1152  *
1153  * @param __is An input stream.
1154  * @param __x A %independent_bits_engine random number generator
1155  * engine.
1156  *
1157  * @returns The input stream with the state of @p __x extracted or in
1158  * an error state.
1159  */
1160  template<typename _CharT, typename _Traits>
1163  std::independent_bits_engine<_RandomNumberEngine,
1164  __w, _UIntType>& __x)
1165  {
1166  __is >> __x._M_b;
1167  return __is;
1168  }
1169 
1170  private:
1171  _RandomNumberEngine _M_b;
1172  };
1173 
1174  /**
1175  * @brief Compares two %independent_bits_engine random number generator
1176  * objects of the same type for inequality.
1177  *
1178  * @param __lhs A %independent_bits_engine random number generator
1179  * object.
1180  * @param __rhs Another %independent_bits_engine random number generator
1181  * object.
1182  *
1183  * @returns true if the infinite sequences of generated values
1184  * would be different, false otherwise.
1185  */
1186  template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
1187  inline bool
1188  operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
1189  _UIntType>& __lhs,
1190  const std::independent_bits_engine<_RandomNumberEngine, __w,
1191  _UIntType>& __rhs)
1192  { return !(__lhs == __rhs); }
1193 
1194  /**
1195  * @brief Inserts the current state of a %independent_bits_engine random
1196  * number generator engine @p __x into the output stream @p __os.
1197  *
1198  * @param __os An output stream.
1199  * @param __x A %independent_bits_engine random number generator engine.
1200  *
1201  * @returns The output stream with the state of @p __x inserted or in
1202  * an error state.
1203  */
1204  template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
1205  typename _CharT, typename _Traits>
1207  operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1208  const std::independent_bits_engine<_RandomNumberEngine,
1209  __w, _UIntType>& __x)
1210  {
1211  __os << __x.base();
1212  return __os;
1213  }
1214 
1215 
1216  /**
1217  * @brief Produces random numbers by combining random numbers from some
1218  * base engine to produce random numbers with a specifies number of bits
1219  * @p __w.
1220  */
1221  template<typename _RandomNumberEngine, size_t __k>
1223  {
1224  static_assert(1u <= __k, "template argument substituting "
1225  "__k out of bound");
1226 
1227  public:
1228  /** The type of the generated random value. */
1229  typedef typename _RandomNumberEngine::result_type result_type;
1230 
1231  static constexpr size_t table_size = __k;
1232 
1233  /**
1234  * @brief Constructs a default %shuffle_order_engine engine.
1235  *
1236  * The underlying engine is default constructed as well.
1237  */
1239  : _M_b()
1240  { _M_initialize(); }
1241 
1242  /**
1243  * @brief Copy constructs a %shuffle_order_engine engine.
1244  *
1245  * Copies an existing base class random number generator.
1246  * @param rng An existing (base class) engine object.
1247  */
1248  explicit
1249  shuffle_order_engine(const _RandomNumberEngine& __rne)
1250  : _M_b(__rne)
1251  { _M_initialize(); }
1252 
1253  /**
1254  * @brief Move constructs a %shuffle_order_engine engine.
1255  *
1256  * Copies an existing base class random number generator.
1257  * @param rng An existing (base class) engine object.
1258  */
1259  explicit
1260  shuffle_order_engine(_RandomNumberEngine&& __rne)
1261  : _M_b(std::move(__rne))
1262  { _M_initialize(); }
1263 
1264  /**
1265  * @brief Seed constructs a %shuffle_order_engine engine.
1266  *
1267  * Constructs the underlying generator engine seeded with @p __s.
1268  * @param __s A seed value for the base class engine.
1269  */
1270  explicit
1272  : _M_b(__s)
1273  { _M_initialize(); }
1274 
1275  /**
1276  * @brief Generator construct a %shuffle_order_engine engine.
1277  *
1278  * @param __q A seed sequence.
1279  */
1280  template<typename _Sseq, typename = typename
1283  ::type>
1284  explicit
1286  : _M_b(__q)
1287  { _M_initialize(); }
1288 
1289  /**
1290  * @brief Reseeds the %shuffle_order_engine object with the default seed
1291  for the underlying base class generator engine.
1292  */
1293  void
1295  {
1296  _M_b.seed();
1297  _M_initialize();
1298  }
1299 
1300  /**
1301  * @brief Reseeds the %shuffle_order_engine object with the default seed
1302  * for the underlying base class generator engine.
1303  */
1304  void
1306  {
1307  _M_b.seed(__s);
1308  _M_initialize();
1309  }
1310 
1311  /**
1312  * @brief Reseeds the %shuffle_order_engine object with the given seed
1313  * sequence.
1314  * @param __q A seed generator function.
1315  */
1316  template<typename _Sseq>
1317  void
1318  seed(_Sseq& __q)
1319  {
1320  _M_b.seed(__q);
1321  _M_initialize();
1322  }
1323 
1324  /**
1325  * Gets a const reference to the underlying generator engine object.
1326  */
1327  const _RandomNumberEngine&
1328  base() const
1329  { return _M_b; }
1330 
1331  /**
1332  * Gets the minimum value in the generated random number range.
1333  */
1334  static constexpr result_type
1336  { return _RandomNumberEngine::min(); }
1337 
1338  /**
1339  * Gets the maximum value in the generated random number range.
1340  */
1341  static constexpr result_type
1343  { return _RandomNumberEngine::max(); }
1344 
1345  /**
1346  * Discard a sequence of random numbers.
1347  */
1348  void
1349  discard(unsigned long long __z)
1350  {
1351  for (; __z != 0ULL; --__z)
1352  (*this)();
1353  }
1354 
1355  /**
1356  * Gets the next value in the generated random number sequence.
1357  */
1358  result_type
1359  operator()();
1360 
1361  /**
1362  * Compares two %shuffle_order_engine random number generator objects
1363  * of the same type for equality.
1364  *
1365  * @param __lhs A %shuffle_order_engine random number generator object.
1366  * @param __rhs Another %shuffle_order_engine random number generator
1367  * object.
1368  *
1369  * @returns true if the infinite sequences of generated values
1370  * would be equal, false otherwise.
1371  */
1372  friend bool
1374  const shuffle_order_engine& __rhs)
1375  { return __lhs._M_b == __rhs._M_b; }
1376 
1377  /**
1378  * @brief Inserts the current state of a %shuffle_order_engine random
1379  * number generator engine @p __x into the output stream
1380  @p __os.
1381  *
1382  * @param __os An output stream.
1383  * @param __x A %shuffle_order_engine random number generator engine.
1384  *
1385  * @returns The output stream with the state of @p __x inserted or in
1386  * an error state.
1387  */
1388  template<typename _RandomNumberEngine1, size_t __k1,
1389  typename _CharT, typename _Traits>
1391  operator<<(std::basic_ostream<_CharT, _Traits>&,
1392  const std::shuffle_order_engine<_RandomNumberEngine1,
1393  __k1>&);
1394 
1395  /**
1396  * @brief Extracts the current state of a % subtract_with_carry_engine
1397  * random number generator engine @p __x from the input stream
1398  * @p __is.
1399  *
1400  * @param __is An input stream.
1401  * @param __x A %shuffle_order_engine random number generator engine.
1402  *
1403  * @returns The input stream with the state of @p __x extracted or in
1404  * an error state.
1405  */
1406  template<typename _RandomNumberEngine1, size_t __k1,
1407  typename _CharT, typename _Traits>
1411 
1412  private:
1413  void _M_initialize()
1414  {
1415  for (size_t __i = 0; __i < __k; ++__i)
1416  _M_v[__i] = _M_b();
1417  _M_y = _M_b();
1418  }
1419 
1420  _RandomNumberEngine _M_b;
1421  result_type _M_v[__k];
1422  result_type _M_y;
1423  };
1424 
1425  /**
1426  * Compares two %shuffle_order_engine random number generator objects
1427  * of the same type for inequality.
1428  *
1429  * @param __lhs A %shuffle_order_engine random number generator object.
1430  * @param __rhs Another %shuffle_order_engine random number generator
1431  * object.
1432  *
1433  * @returns true if the infinite sequences of generated values
1434  * would be different, false otherwise.
1435  */
1436  template<typename _RandomNumberEngine, size_t __k>
1437  inline bool
1438  operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
1439  __k>& __lhs,
1440  const std::shuffle_order_engine<_RandomNumberEngine,
1441  __k>& __rhs)
1442  { return !(__lhs == __rhs); }
1443 
1444 
1445  /**
1446  * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
1447  */
1448  typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
1450 
1451  /**
1452  * An alternative LCR (Lehmer Generator function).
1453  */
1456 
1457  /**
1458  * The classic Mersenne Twister.
1459  *
1460  * Reference:
1461  * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
1462  * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
1463  * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
1464  */
1465  typedef mersenne_twister_engine<
1466  uint_fast32_t,
1467  32, 624, 397, 31,
1468  0x9908b0dfUL, 11,
1469  0xffffffffUL, 7,
1470  0x9d2c5680UL, 15,
1471  0xefc60000UL, 18, 1812433253UL> mt19937;
1472 
1473  /**
1474  * An alternative Mersenne Twister.
1475  */
1476  typedef mersenne_twister_engine<
1477  uint_fast64_t,
1478  64, 312, 156, 31,
1479  0xb5026f5aa96619e9ULL, 29,
1480  0x5555555555555555ULL, 17,
1481  0x71d67fffeda60000ULL, 37,
1482  0xfff7eee000000000ULL, 43,
1483  6364136223846793005ULL> mt19937_64;
1484 
1485  typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1486  ranlux24_base;
1487 
1488  typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1489  ranlux48_base;
1490 
1492 
1494 
1496 
1498 
1499  /**
1500  * A standard interface to a platform-specific non-deterministic
1501  * random number generator (if any are available).
1502  */
1504  {
1505  public:
1506  /** The type of the generated random value. */
1507  typedef unsigned int result_type;
1508 
1509  // constructors, destructors and member functions
1510 
1511 #ifdef _GLIBCXX_USE_RANDOM_TR1
1512 
1513  explicit
1514  random_device(const std::string& __token = "/dev/urandom")
1515  {
1516  if ((__token != "/dev/urandom" && __token != "/dev/random")
1517  || !(_M_file = std::fopen(__token.c_str(), "rb")))
1518  std::__throw_runtime_error(__N("random_device::"
1519  "random_device(const std::string&)"));
1520  }
1521 
1522  ~random_device()
1523  { std::fclose(_M_file); }
1524 
1525 #else
1526 
1527  explicit
1528  random_device(const std::string& __token = "mt19937")
1529  : _M_mt(_M_strtoul(__token)) { }
1530 
1531  private:
1532  static unsigned long
1533  _M_strtoul(const std::string& __str)
1534  {
1535  unsigned long __ret = 5489UL;
1536  if (__str != "mt19937")
1537  {
1538  const char* __nptr = __str.c_str();
1539  char* __endptr;
1540  __ret = std::strtoul(__nptr, &__endptr, 0);
1541  if (*__nptr == '\0' || *__endptr != '\0')
1542  std::__throw_runtime_error(__N("random_device::_M_strtoul"
1543  "(const std::string&)"));
1544  }
1545  return __ret;
1546  }
1547 
1548  public:
1549 
1550 #endif
1551 
1552  result_type
1553  min() const
1555 
1556  result_type
1557  max() const
1559 
1560  double
1561  entropy() const
1562  { return 0.0; }
1563 
1564  result_type
1565  operator()()
1566  {
1567 #ifdef _GLIBCXX_USE_RANDOM_TR1
1568  result_type __ret;
1569  std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
1570  1, _M_file);
1571  return __ret;
1572 #else
1573  return _M_mt();
1574 #endif
1575  }
1576 
1577  // No copy functions.
1578  random_device(const random_device&) = delete;
1579  void operator=(const random_device&) = delete;
1580 
1581  private:
1582 
1583 #ifdef _GLIBCXX_USE_RANDOM_TR1
1584  FILE* _M_file;
1585 #else
1586  mt19937 _M_mt;
1587 #endif
1588  };
1589 
1590  /* @} */ // group random_generators
1591 
1592  /**
1593  * @addtogroup random_distributions Random Number Distributions
1594  * @ingroup random
1595  * @{
1596  */
1597 
1598  /**
1599  * @addtogroup random_distributions_uniform Uniform Distributions
1600  * @ingroup random_distributions
1601  * @{
1602  */
1603 
1604  /**
1605  * @brief Uniform discrete distribution for random numbers.
1606  * A discrete random distribution on the range @f$[min, max]@f$ with equal
1607  * probability throughout the range.
1608  */
1609  template<typename _IntType = int>
1611  {
1612  static_assert(std::is_integral<_IntType>::value,
1613  "template argument not an integral type");
1614 
1615  public:
1616  /** The type of the range of the distribution. */
1617  typedef _IntType result_type;
1618  /** Parameter type. */
1619  struct param_type
1620  {
1622 
1623  explicit
1624  param_type(_IntType __a = 0,
1625  _IntType __b = std::numeric_limits<_IntType>::max())
1626  : _M_a(__a), _M_b(__b)
1627  {
1628  _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1629  }
1630 
1631  result_type
1632  a() const
1633  { return _M_a; }
1634 
1635  result_type
1636  b() const
1637  { return _M_b; }
1638 
1639  friend bool
1640  operator==(const param_type& __p1, const param_type& __p2)
1641  { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1642 
1643  private:
1644  _IntType _M_a;
1645  _IntType _M_b;
1646  };
1647 
1648  public:
1649  /**
1650  * @brief Constructs a uniform distribution object.
1651  */
1652  explicit
1653  uniform_int_distribution(_IntType __a = 0,
1654  _IntType __b = std::numeric_limits<_IntType>::max())
1655  : _M_param(__a, __b)
1656  { }
1657 
1658  explicit
1659  uniform_int_distribution(const param_type& __p)
1660  : _M_param(__p)
1661  { }
1662 
1663  /**
1664  * @brief Resets the distribution state.
1665  *
1666  * Does nothing for the uniform integer distribution.
1667  */
1668  void
1669  reset() { }
1670 
1671  result_type
1672  a() const
1673  { return _M_param.a(); }
1674 
1675  result_type
1676  b() const
1677  { return _M_param.b(); }
1678 
1679  /**
1680  * @brief Returns the parameter set of the distribution.
1681  */
1682  param_type
1683  param() const
1684  { return _M_param; }
1685 
1686  /**
1687  * @brief Sets the parameter set of the distribution.
1688  * @param __param The new parameter set of the distribution.
1689  */
1690  void
1691  param(const param_type& __param)
1692  { _M_param = __param; }
1693 
1694  /**
1695  * @brief Returns the inclusive lower bound of the distribution range.
1696  */
1697  result_type
1698  min() const
1699  { return this->a(); }
1700 
1701  /**
1702  * @brief Returns the inclusive upper bound of the distribution range.
1703  */
1704  result_type
1705  max() const
1706  { return this->b(); }
1707 
1708  /**
1709  * @brief Generating functions.
1710  */
1711  template<typename _UniformRandomNumberGenerator>
1712  result_type
1713  operator()(_UniformRandomNumberGenerator& __urng)
1714  { return this->operator()(__urng, this->param()); }
1715 
1716  template<typename _UniformRandomNumberGenerator>
1717  result_type
1718  operator()(_UniformRandomNumberGenerator& __urng,
1719  const param_type& __p);
1720 
1721  param_type _M_param;
1722  };
1723 
1724  /**
1725  * @brief Return true if two uniform integer distributions have
1726  * the same parameters.
1727  */
1728  template<typename _IntType>
1729  inline bool
1732  { return __d1.param() == __d2.param(); }
1733 
1734  /**
1735  * @brief Return true if two uniform integer distributions have
1736  * different parameters.
1737  */
1738  template<typename _IntType>
1739  inline bool
1742  { return !(__d1 == __d2); }
1743 
1744  /**
1745  * @brief Inserts a %uniform_int_distribution random number
1746  * distribution @p __x into the output stream @p os.
1747  *
1748  * @param __os An output stream.
1749  * @param __x A %uniform_int_distribution random number distribution.
1750  *
1751  * @returns The output stream with the state of @p __x inserted or in
1752  * an error state.
1753  */
1754  template<typename _IntType, typename _CharT, typename _Traits>
1756  operator<<(std::basic_ostream<_CharT, _Traits>&,
1758 
1759  /**
1760  * @brief Extracts a %uniform_int_distribution random number distribution
1761  * @p __x from the input stream @p __is.
1762  *
1763  * @param __is An input stream.
1764  * @param __x A %uniform_int_distribution random number generator engine.
1765  *
1766  * @returns The input stream with @p __x extracted or in an error state.
1767  */
1768  template<typename _IntType, typename _CharT, typename _Traits>
1772 
1773 
1774  /**
1775  * @brief Uniform continuous distribution for random numbers.
1776  *
1777  * A continuous random distribution on the range [min, max) with equal
1778  * probability throughout the range. The URNG should be real-valued and
1779  * deliver number in the range [0, 1).
1780  */
1781  template<typename _RealType = double>
1783  {
1785  "template argument not a floating point type");
1786 
1787  public:
1788  /** The type of the range of the distribution. */
1789  typedef _RealType result_type;
1790  /** Parameter type. */
1791  struct param_type
1792  {
1794 
1795  explicit
1796  param_type(_RealType __a = _RealType(0),
1797  _RealType __b = _RealType(1))
1798  : _M_a(__a), _M_b(__b)
1799  {
1800  _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
1801  }
1802 
1803  result_type
1804  a() const
1805  { return _M_a; }
1806 
1807  result_type
1808  b() const
1809  { return _M_b; }
1810 
1811  friend bool
1812  operator==(const param_type& __p1, const param_type& __p2)
1813  { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1814 
1815  private:
1816  _RealType _M_a;
1817  _RealType _M_b;
1818  };
1819 
1820  public:
1821  /**
1822  * @brief Constructs a uniform_real_distribution object.
1823  *
1824  * @param __min [IN] The lower bound of the distribution.
1825  * @param __max [IN] The upper bound of the distribution.
1826  */
1827  explicit
1828  uniform_real_distribution(_RealType __a = _RealType(0),
1829  _RealType __b = _RealType(1))
1830  : _M_param(__a, __b)
1831  { }
1832 
1833  explicit
1834  uniform_real_distribution(const param_type& __p)
1835  : _M_param(__p)
1836  { }
1837 
1838  /**
1839  * @brief Resets the distribution state.
1840  *
1841  * Does nothing for the uniform real distribution.
1842  */
1843  void
1844  reset() { }
1845 
1846  result_type
1847  a() const
1848  { return _M_param.a(); }
1849 
1850  result_type
1851  b() const
1852  { return _M_param.b(); }
1853 
1854  /**
1855  * @brief Returns the parameter set of the distribution.
1856  */
1857  param_type
1858  param() const
1859  { return _M_param; }
1860 
1861  /**
1862  * @brief Sets the parameter set of the distribution.
1863  * @param __param The new parameter set of the distribution.
1864  */
1865  void
1866  param(const param_type& __param)
1867  { _M_param = __param; }
1868 
1869  /**
1870  * @brief Returns the inclusive lower bound of the distribution range.
1871  */
1872  result_type
1873  min() const
1874  { return this->a(); }
1875 
1876  /**
1877  * @brief Returns the inclusive upper bound of the distribution range.
1878  */
1879  result_type
1880  max() const
1881  { return this->b(); }
1882 
1883  /**
1884  * @brief Generating functions.
1885  */
1886  template<typename _UniformRandomNumberGenerator>
1887  result_type
1888  operator()(_UniformRandomNumberGenerator& __urng)
1889  { return this->operator()(__urng, this->param()); }
1890 
1891  template<typename _UniformRandomNumberGenerator>
1892  result_type
1893  operator()(_UniformRandomNumberGenerator& __urng,
1894  const param_type& __p)
1895  {
1896  __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1897  __aurng(__urng);
1898  return (__aurng() * (__p.b() - __p.a())) + __p.a();
1899  }
1900 
1901  private:
1902  param_type _M_param;
1903  };
1904 
1905  /**
1906  * @brief Return true if two uniform real distributions have
1907  * the same parameters.
1908  */
1909  template<typename _IntType>
1910  inline bool
1913  { return __d1.param() == __d2.param(); }
1914 
1915  /**
1916  * @brief Return true if two uniform real distributions have
1917  * different parameters.
1918  */
1919  template<typename _IntType>
1920  inline bool
1923  { return !(__d1 == __d2); }
1924 
1925  /**
1926  * @brief Inserts a %uniform_real_distribution random number
1927  * distribution @p __x into the output stream @p __os.
1928  *
1929  * @param __os An output stream.
1930  * @param __x A %uniform_real_distribution random number distribution.
1931  *
1932  * @returns The output stream with the state of @p __x inserted or in
1933  * an error state.
1934  */
1935  template<typename _RealType, typename _CharT, typename _Traits>
1937  operator<<(std::basic_ostream<_CharT, _Traits>&,
1939 
1940  /**
1941  * @brief Extracts a %uniform_real_distribution random number distribution
1942  * @p __x from the input stream @p __is.
1943  *
1944  * @param __is An input stream.
1945  * @param __x A %uniform_real_distribution random number generator engine.
1946  *
1947  * @returns The input stream with @p __x extracted or in an error state.
1948  */
1949  template<typename _RealType, typename _CharT, typename _Traits>
1953 
1954  /* @} */ // group random_distributions_uniform
1955 
1956  /**
1957  * @addtogroup random_distributions_normal Normal Distributions
1958  * @ingroup random_distributions
1959  * @{
1960  */
1961 
1962  /**
1963  * @brief A normal continuous distribution for random numbers.
1964  *
1965  * The formula for the normal probability density function is
1966  * @f[
1967  * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
1968  * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
1969  * @f]
1970  */
1971  template<typename _RealType = double>
1973  {
1975  "template argument not a floating point type");
1976 
1977  public:
1978  /** The type of the range of the distribution. */
1979  typedef _RealType result_type;
1980  /** Parameter type. */
1981  struct param_type
1982  {
1984 
1985  explicit
1986  param_type(_RealType __mean = _RealType(0),
1987  _RealType __stddev = _RealType(1))
1988  : _M_mean(__mean), _M_stddev(__stddev)
1989  {
1990  _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
1991  }
1992 
1993  _RealType
1994  mean() const
1995  { return _M_mean; }
1996 
1997  _RealType
1998  stddev() const
1999  { return _M_stddev; }
2000 
2001  friend bool
2002  operator==(const param_type& __p1, const param_type& __p2)
2003  { return (__p1._M_mean == __p2._M_mean
2004  && __p1._M_stddev == __p2._M_stddev); }
2005 
2006  private:
2007  _RealType _M_mean;
2008  _RealType _M_stddev;
2009  };
2010 
2011  public:
2012  /**
2013  * Constructs a normal distribution with parameters @f$mean@f$ and
2014  * standard deviation.
2015  */
2016  explicit
2018  result_type __stddev = result_type(1))
2019  : _M_param(__mean, __stddev), _M_saved_available(false)
2020  { }
2021 
2022  explicit
2023  normal_distribution(const param_type& __p)
2024  : _M_param(__p), _M_saved_available(false)
2025  { }
2026 
2027  /**
2028  * @brief Resets the distribution state.
2029  */
2030  void
2032  { _M_saved_available = false; }
2033 
2034  /**
2035  * @brief Returns the mean of the distribution.
2036  */
2037  _RealType
2038  mean() const
2039  { return _M_param.mean(); }
2040 
2041  /**
2042  * @brief Returns the standard deviation of the distribution.
2043  */
2044  _RealType
2045  stddev() const
2046  { return _M_param.stddev(); }
2047 
2048  /**
2049  * @brief Returns the parameter set of the distribution.
2050  */
2051  param_type
2052  param() const
2053  { return _M_param; }
2054 
2055  /**
2056  * @brief Sets the parameter set of the distribution.
2057  * @param __param The new parameter set of the distribution.
2058  */
2059  void
2060  param(const param_type& __param)
2061  { _M_param = __param; }
2062 
2063  /**
2064  * @brief Returns the greatest lower bound value of the distribution.
2065  */
2066  result_type
2067  min() const
2069 
2070  /**
2071  * @brief Returns the least upper bound value of the distribution.
2072  */
2073  result_type
2074  max() const
2076 
2077  /**
2078  * @brief Generating functions.
2079  */
2080  template<typename _UniformRandomNumberGenerator>
2081  result_type
2082  operator()(_UniformRandomNumberGenerator& __urng)
2083  { return this->operator()(__urng, this->param()); }
2084 
2085  template<typename _UniformRandomNumberGenerator>
2086  result_type
2087  operator()(_UniformRandomNumberGenerator& __urng,
2088  const param_type& __p);
2089 
2090  /**
2091  * @brief Return true if two normal distributions have
2092  * the same parameters and the sequences that would
2093  * be generated are equal.
2094  */
2095  template<typename _RealType1>
2096  friend bool
2099 
2100  /**
2101  * @brief Inserts a %normal_distribution random number distribution
2102  * @p __x into the output stream @p __os.
2103  *
2104  * @param __os An output stream.
2105  * @param __x A %normal_distribution random number distribution.
2106  *
2107  * @returns The output stream with the state of @p __x inserted or in
2108  * an error state.
2109  */
2110  template<typename _RealType1, typename _CharT, typename _Traits>
2112  operator<<(std::basic_ostream<_CharT, _Traits>&,
2114 
2115  /**
2116  * @brief Extracts a %normal_distribution random number distribution
2117  * @p __x from the input stream @p __is.
2118  *
2119  * @param __is An input stream.
2120  * @param __x A %normal_distribution random number generator engine.
2121  *
2122  * @returns The input stream with @p __x extracted or in an error
2123  * state.
2124  */
2125  template<typename _RealType1, typename _CharT, typename _Traits>
2129 
2130  private:
2131  param_type _M_param;
2132  result_type _M_saved;
2133  bool _M_saved_available;
2134  };
2135 
2136  /**
2137  * @brief Return true if two normal distributions are different.
2138  */
2139  template<typename _RealType>
2140  inline bool
2141  operator!=(const std::normal_distribution<_RealType>& __d1,
2143  { return !(__d1 == __d2); }
2144 
2145 
2146  /**
2147  * @brief A lognormal_distribution random number distribution.
2148  *
2149  * The formula for the normal probability mass function is
2150  * @f[
2151  * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
2152  * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
2153  * @f]
2154  */
2155  template<typename _RealType = double>
2157  {
2159  "template argument not a floating point type");
2160 
2161  public:
2162  /** The type of the range of the distribution. */
2163  typedef _RealType result_type;
2164  /** Parameter type. */
2165  struct param_type
2166  {
2168 
2169  explicit
2170  param_type(_RealType __m = _RealType(0),
2171  _RealType __s = _RealType(1))
2172  : _M_m(__m), _M_s(__s)
2173  { }
2174 
2175  _RealType
2176  m() const
2177  { return _M_m; }
2178 
2179  _RealType
2180  s() const
2181  { return _M_s; }
2182 
2183  friend bool
2184  operator==(const param_type& __p1, const param_type& __p2)
2185  { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
2186 
2187  private:
2188  _RealType _M_m;
2189  _RealType _M_s;
2190  };
2191 
2192  explicit
2193  lognormal_distribution(_RealType __m = _RealType(0),
2194  _RealType __s = _RealType(1))
2195  : _M_param(__m, __s), _M_nd()
2196  { }
2197 
2198  explicit
2199  lognormal_distribution(const param_type& __p)
2200  : _M_param(__p), _M_nd()
2201  { }
2202 
2203  /**
2204  * Resets the distribution state.
2205  */
2206  void
2208  { _M_nd.reset(); }
2209 
2210  /**
2211  *
2212  */
2213  _RealType
2214  m() const
2215  { return _M_param.m(); }
2216 
2217  _RealType
2218  s() const
2219  { return _M_param.s(); }
2220 
2221  /**
2222  * @brief Returns the parameter set of the distribution.
2223  */
2224  param_type
2225  param() const
2226  { return _M_param; }
2227 
2228  /**
2229  * @brief Sets the parameter set of the distribution.
2230  * @param __param The new parameter set of the distribution.
2231  */
2232  void
2233  param(const param_type& __param)
2234  { _M_param = __param; }
2235 
2236  /**
2237  * @brief Returns the greatest lower bound value of the distribution.
2238  */
2239  result_type
2240  min() const
2241  { return result_type(0); }
2242 
2243  /**
2244  * @brief Returns the least upper bound value of the distribution.
2245  */
2246  result_type
2247  max() const
2249 
2250  /**
2251  * @brief Generating functions.
2252  */
2253  template<typename _UniformRandomNumberGenerator>
2254  result_type
2255  operator()(_UniformRandomNumberGenerator& __urng)
2256  { return this->operator()(__urng, this->param()); }
2257 
2258  template<typename _UniformRandomNumberGenerator>
2259  result_type
2260  operator()(_UniformRandomNumberGenerator& __urng,
2261  const param_type& __p)
2262  { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
2263 
2264  /**
2265  * @brief Return true if two lognormal distributions have
2266  * the same parameters and the sequences that would
2267  * be generated are equal.
2268  */
2269  template<typename _RealType1>
2270  friend bool
2273  { return (__d1.param() == __d2.param()
2274  && __d1._M_nd == __d2._M_nd); }
2275 
2276  /**
2277  * @brief Inserts a %lognormal_distribution random number distribution
2278  * @p __x into the output stream @p __os.
2279  *
2280  * @param __os An output stream.
2281  * @param __x A %lognormal_distribution random number distribution.
2282  *
2283  * @returns The output stream with the state of @p __x inserted or in
2284  * an error state.
2285  */
2286  template<typename _RealType1, typename _CharT, typename _Traits>
2288  operator<<(std::basic_ostream<_CharT, _Traits>&,
2290 
2291  /**
2292  * @brief Extracts a %lognormal_distribution random number distribution
2293  * @p __x from the input stream @p __is.
2294  *
2295  * @param __is An input stream.
2296  * @param __x A %lognormal_distribution random number
2297  * generator engine.
2298  *
2299  * @returns The input stream with @p __x extracted or in an error state.
2300  */
2301  template<typename _RealType1, typename _CharT, typename _Traits>
2305 
2306  private:
2307  param_type _M_param;
2308 
2310  };
2311 
2312  /**
2313  * @brief Return true if two lognormal distributions are different.
2314  */
2315  template<typename _RealType>
2316  inline bool
2319  { return !(__d1 == __d2); }
2320 
2321 
2322  /**
2323  * @brief A gamma continuous distribution for random numbers.
2324  *
2325  * The formula for the gamma probability density function is:
2326  * @f[
2327  * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
2328  * (x/\beta)^{\alpha - 1} e^{-x/\beta}
2329  * @f]
2330  */
2331  template<typename _RealType = double>
2333  {
2335  "template argument not a floating point type");
2336 
2337  public:
2338  /** The type of the range of the distribution. */
2339  typedef _RealType result_type;
2340  /** Parameter type. */
2341  struct param_type
2342  {
2344  friend class gamma_distribution<_RealType>;
2345 
2346  explicit
2347  param_type(_RealType __alpha_val = _RealType(1),
2348  _RealType __beta_val = _RealType(1))
2349  : _M_alpha(__alpha_val), _M_beta(__beta_val)
2350  {
2351  _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
2352  _M_initialize();
2353  }
2354 
2355  _RealType
2356  alpha() const
2357  { return _M_alpha; }
2358 
2359  _RealType
2360  beta() const
2361  { return _M_beta; }
2362 
2363  friend bool
2364  operator==(const param_type& __p1, const param_type& __p2)
2365  { return (__p1._M_alpha == __p2._M_alpha
2366  && __p1._M_beta == __p2._M_beta); }
2367 
2368  private:
2369  void
2370  _M_initialize();
2371 
2372  _RealType _M_alpha;
2373  _RealType _M_beta;
2374 
2375  _RealType _M_malpha, _M_a2;
2376  };
2377 
2378  public:
2379  /**
2380  * @brief Constructs a gamma distribution with parameters
2381  * @f$\alpha@f$ and @f$\beta@f$.
2382  */
2383  explicit
2384  gamma_distribution(_RealType __alpha_val = _RealType(1),
2385  _RealType __beta_val = _RealType(1))
2386  : _M_param(__alpha_val, __beta_val), _M_nd()
2387  { }
2388 
2389  explicit
2390  gamma_distribution(const param_type& __p)
2391  : _M_param(__p), _M_nd()
2392  { }
2393 
2394  /**
2395  * @brief Resets the distribution state.
2396  */
2397  void
2399  { _M_nd.reset(); }
2400 
2401  /**
2402  * @brief Returns the @f$\alpha@f$ of the distribution.
2403  */
2404  _RealType
2405  alpha() const
2406  { return _M_param.alpha(); }
2407 
2408  /**
2409  * @brief Returns the @f$\beta@f$ of the distribution.
2410  */
2411  _RealType
2412  beta() const
2413  { return _M_param.beta(); }
2414 
2415  /**
2416  * @brief Returns the parameter set of the distribution.
2417  */
2418  param_type
2419  param() const
2420  { return _M_param; }
2421 
2422  /**
2423  * @brief Sets the parameter set of the distribution.
2424  * @param __param The new parameter set of the distribution.
2425  */
2426  void
2427  param(const param_type& __param)
2428  { _M_param = __param; }
2429 
2430  /**
2431  * @brief Returns the greatest lower bound value of the distribution.
2432  */
2433  result_type
2434  min() const
2435  { return result_type(0); }
2436 
2437  /**
2438  * @brief Returns the least upper bound value of the distribution.
2439  */
2440  result_type
2441  max() const
2443 
2444  /**
2445  * @brief Generating functions.
2446  */
2447  template<typename _UniformRandomNumberGenerator>
2448  result_type
2449  operator()(_UniformRandomNumberGenerator& __urng)
2450  { return this->operator()(__urng, this->param()); }
2451 
2452  template<typename _UniformRandomNumberGenerator>
2453  result_type
2454  operator()(_UniformRandomNumberGenerator& __urng,
2455  const param_type& __p);
2456 
2457  /**
2458  * @brief Return true if two gamma distributions have the same
2459  * parameters and the sequences that would be generated
2460  * are equal.
2461  */
2462  template<typename _RealType1>
2463  friend bool
2466  { return (__d1.param() == __d2.param()
2467  && __d1._M_nd == __d2._M_nd); }
2468 
2469  /**
2470  * @brief Inserts a %gamma_distribution random number distribution
2471  * @p __x into the output stream @p __os.
2472  *
2473  * @param __os An output stream.
2474  * @param __x A %gamma_distribution random number distribution.
2475  *
2476  * @returns The output stream with the state of @p __x inserted or in
2477  * an error state.
2478  */
2479  template<typename _RealType1, typename _CharT, typename _Traits>
2481  operator<<(std::basic_ostream<_CharT, _Traits>&,
2483 
2484  /**
2485  * @brief Extracts a %gamma_distribution random number distribution
2486  * @p __x from the input stream @p __is.
2487  *
2488  * @param __is An input stream.
2489  * @param __x A %gamma_distribution random number generator engine.
2490  *
2491  * @returns The input stream with @p __x extracted or in an error state.
2492  */
2493  template<typename _RealType1, typename _CharT, typename _Traits>
2497 
2498  private:
2499  param_type _M_param;
2500 
2502  };
2503 
2504  /**
2505  * @brief Return true if two gamma distributions are different.
2506  */
2507  template<typename _RealType>
2508  inline bool
2511  { return !(__d1 == __d2); }
2512 
2513 
2514  /**
2515  * @brief A chi_squared_distribution random number distribution.
2516  *
2517  * The formula for the normal probability mass function is
2518  * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
2519  */
2520  template<typename _RealType = double>
2522  {
2524  "template argument not a floating point type");
2525 
2526  public:
2527  /** The type of the range of the distribution. */
2528  typedef _RealType result_type;
2529  /** Parameter type. */
2530  struct param_type
2531  {
2533 
2534  explicit
2535  param_type(_RealType __n = _RealType(1))
2536  : _M_n(__n)
2537  { }
2538 
2539  _RealType
2540  n() const
2541  { return _M_n; }
2542 
2543  friend bool
2544  operator==(const param_type& __p1, const param_type& __p2)
2545  { return __p1._M_n == __p2._M_n; }
2546 
2547  private:
2548  _RealType _M_n;
2549  };
2550 
2551  explicit
2552  chi_squared_distribution(_RealType __n = _RealType(1))
2553  : _M_param(__n), _M_gd(__n / 2)
2554  { }
2555 
2556  explicit
2557  chi_squared_distribution(const param_type& __p)
2558  : _M_param(__p), _M_gd(__p.n() / 2)
2559  { }
2560 
2561  /**
2562  * @brief Resets the distribution state.
2563  */
2564  void
2566  { _M_gd.reset(); }
2567 
2568  /**
2569  *
2570  */
2571  _RealType
2572  n() const
2573  { return _M_param.n(); }
2574 
2575  /**
2576  * @brief Returns the parameter set of the distribution.
2577  */
2578  param_type
2579  param() const
2580  { return _M_param; }
2581 
2582  /**
2583  * @brief Sets the parameter set of the distribution.
2584  * @param __param The new parameter set of the distribution.
2585  */
2586  void
2587  param(const param_type& __param)
2588  { _M_param = __param; }
2589 
2590  /**
2591  * @brief Returns the greatest lower bound value of the distribution.
2592  */
2593  result_type
2594  min() const
2595  { return result_type(0); }
2596 
2597  /**
2598  * @brief Returns the least upper bound value of the distribution.
2599  */
2600  result_type
2601  max() const
2603 
2604  /**
2605  * @brief Generating functions.
2606  */
2607  template<typename _UniformRandomNumberGenerator>
2608  result_type
2609  operator()(_UniformRandomNumberGenerator& __urng)
2610  { return 2 * _M_gd(__urng); }
2611 
2612  template<typename _UniformRandomNumberGenerator>
2613  result_type
2614  operator()(_UniformRandomNumberGenerator& __urng,
2615  const param_type& __p)
2616  {
2618  param_type;
2619  return 2 * _M_gd(__urng, param_type(__p.n() / 2));
2620  }
2621 
2622  /**
2623  * @brief Return true if two Chi-squared distributions have
2624  * the same parameters and the sequences that would be
2625  * generated are equal.
2626  */
2627  template<typename _RealType1>
2628  friend bool
2631  { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
2632 
2633  /**
2634  * @brief Inserts a %chi_squared_distribution random number distribution
2635  * @p __x into the output stream @p __os.
2636  *
2637  * @param __os An output stream.
2638  * @param __x A %chi_squared_distribution random number distribution.
2639  *
2640  * @returns The output stream with the state of @p __x inserted or in
2641  * an error state.
2642  */
2643  template<typename _RealType1, typename _CharT, typename _Traits>
2645  operator<<(std::basic_ostream<_CharT, _Traits>&,
2647 
2648  /**
2649  * @brief Extracts a %chi_squared_distribution random number distribution
2650  * @p __x from the input stream @p __is.
2651  *
2652  * @param __is An input stream.
2653  * @param __x A %chi_squared_distribution random number
2654  * generator engine.
2655  *
2656  * @returns The input stream with @p __x extracted or in an error state.
2657  */
2658  template<typename _RealType1, typename _CharT, typename _Traits>
2662 
2663  private:
2664  param_type _M_param;
2665 
2667  };
2668 
2669  /**
2670  * @brief Return true if two Chi-squared distributions are different.
2671  */
2672  template<typename _RealType>
2673  inline bool
2676  { return !(__d1 == __d2); }
2677 
2678 
2679  /**
2680  * @brief A cauchy_distribution random number distribution.
2681  *
2682  * The formula for the normal probability mass function is
2683  * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
2684  */
2685  template<typename _RealType = double>
2687  {
2689  "template argument not a floating point type");
2690 
2691  public:
2692  /** The type of the range of the distribution. */
2693  typedef _RealType result_type;
2694  /** Parameter type. */
2695  struct param_type
2696  {
2698 
2699  explicit
2700  param_type(_RealType __a = _RealType(0),
2701  _RealType __b = _RealType(1))
2702  : _M_a(__a), _M_b(__b)
2703  { }
2704 
2705  _RealType
2706  a() const
2707  { return _M_a; }
2708 
2709  _RealType
2710  b() const
2711  { return _M_b; }
2712 
2713  friend bool
2714  operator==(const param_type& __p1, const param_type& __p2)
2715  { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2716 
2717  private:
2718  _RealType _M_a;
2719  _RealType _M_b;
2720  };
2721 
2722  explicit
2723  cauchy_distribution(_RealType __a = _RealType(0),
2724  _RealType __b = _RealType(1))
2725  : _M_param(__a, __b)
2726  { }
2727 
2728  explicit
2729  cauchy_distribution(const param_type& __p)
2730  : _M_param(__p)
2731  { }
2732 
2733  /**
2734  * @brief Resets the distribution state.
2735  */
2736  void
2738  { }
2739 
2740  /**
2741  *
2742  */
2743  _RealType
2744  a() const
2745  { return _M_param.a(); }
2746 
2747  _RealType
2748  b() const
2749  { return _M_param.b(); }
2750 
2751  /**
2752  * @brief Returns the parameter set of the distribution.
2753  */
2754  param_type
2755  param() const
2756  { return _M_param; }
2757 
2758  /**
2759  * @brief Sets the parameter set of the distribution.
2760  * @param __param The new parameter set of the distribution.
2761  */
2762  void
2763  param(const param_type& __param)
2764  { _M_param = __param; }
2765 
2766  /**
2767  * @brief Returns the greatest lower bound value of the distribution.
2768  */
2769  result_type
2770  min() const
2772 
2773  /**
2774  * @brief Returns the least upper bound value of the distribution.
2775  */
2776  result_type
2777  max() const
2779 
2780  /**
2781  * @brief Generating functions.
2782  */
2783  template<typename _UniformRandomNumberGenerator>
2784  result_type
2785  operator()(_UniformRandomNumberGenerator& __urng)
2786  { return this->operator()(__urng, this->param()); }
2787 
2788  template<typename _UniformRandomNumberGenerator>
2789  result_type
2790  operator()(_UniformRandomNumberGenerator& __urng,
2791  const param_type& __p);
2792 
2793  private:
2794  param_type _M_param;
2795  };
2796 
2797  /**
2798  * @brief Return true if two Cauchy distributions have
2799  * the same parameters.
2800  */
2801  template<typename _RealType>
2802  inline bool
2803  operator==(const std::cauchy_distribution<_RealType>& __d1,
2805  { return __d1.param() == __d2.param(); }
2806 
2807  /**
2808  * @brief Return true if two Cauchy distributions have
2809  * different parameters.
2810  */
2811  template<typename _RealType>
2812  inline bool
2813  operator!=(const std::cauchy_distribution<_RealType>& __d1,
2815  { return !(__d1 == __d2); }
2816 
2817  /**
2818  * @brief Inserts a %cauchy_distribution random number distribution
2819  * @p __x into the output stream @p __os.
2820  *
2821  * @param __os An output stream.
2822  * @param __x A %cauchy_distribution random number distribution.
2823  *
2824  * @returns The output stream with the state of @p __x inserted or in
2825  * an error state.
2826  */
2827  template<typename _RealType, typename _CharT, typename _Traits>
2829  operator<<(std::basic_ostream<_CharT, _Traits>&,
2831 
2832  /**
2833  * @brief Extracts a %cauchy_distribution random number distribution
2834  * @p __x from the input stream @p __is.
2835  *
2836  * @param __is An input stream.
2837  * @param __x A %cauchy_distribution random number
2838  * generator engine.
2839  *
2840  * @returns The input stream with @p __x extracted or in an error state.
2841  */
2842  template<typename _RealType, typename _CharT, typename _Traits>
2846 
2847 
2848  /**
2849  * @brief A fisher_f_distribution random number distribution.
2850  *
2851  * The formula for the normal probability mass function is
2852  * @f[
2853  * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
2854  * (\frac{m}{n})^{m/2} x^{(m/2)-1}
2855  * (1 + \frac{mx}{n})^{-(m+n)/2}
2856  * @f]
2857  */
2858  template<typename _RealType = double>
2860  {
2862  "template argument not a floating point type");
2863 
2864  public:
2865  /** The type of the range of the distribution. */
2866  typedef _RealType result_type;
2867  /** Parameter type. */
2868  struct param_type
2869  {
2871 
2872  explicit
2873  param_type(_RealType __m = _RealType(1),
2874  _RealType __n = _RealType(1))
2875  : _M_m(__m), _M_n(__n)
2876  { }
2877 
2878  _RealType
2879  m() const
2880  { return _M_m; }
2881 
2882  _RealType
2883  n() const
2884  { return _M_n; }
2885 
2886  friend bool
2887  operator==(const param_type& __p1, const param_type& __p2)
2888  { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
2889 
2890  private:
2891  _RealType _M_m;
2892  _RealType _M_n;
2893  };
2894 
2895  explicit
2896  fisher_f_distribution(_RealType __m = _RealType(1),
2897  _RealType __n = _RealType(1))
2898  : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
2899  { }
2900 
2901  explicit
2902  fisher_f_distribution(const param_type& __p)
2903  : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
2904  { }
2905 
2906  /**
2907  * @brief Resets the distribution state.
2908  */
2909  void
2911  {
2912  _M_gd_x.reset();
2913  _M_gd_y.reset();
2914  }
2915 
2916  /**
2917  *
2918  */
2919  _RealType
2920  m() const
2921  { return _M_param.m(); }
2922 
2923  _RealType
2924  n() const
2925  { return _M_param.n(); }
2926 
2927  /**
2928  * @brief Returns the parameter set of the distribution.
2929  */
2930  param_type
2931  param() const
2932  { return _M_param; }
2933 
2934  /**
2935  * @brief Sets the parameter set of the distribution.
2936  * @param __param The new parameter set of the distribution.
2937  */
2938  void
2939  param(const param_type& __param)
2940  { _M_param = __param; }
2941 
2942  /**
2943  * @brief Returns the greatest lower bound value of the distribution.
2944  */
2945  result_type
2946  min() const
2947  { return result_type(0); }
2948 
2949  /**
2950  * @brief Returns the least upper bound value of the distribution.
2951  */
2952  result_type
2953  max() const
2955 
2956  /**
2957  * @brief Generating functions.
2958  */
2959  template<typename _UniformRandomNumberGenerator>
2960  result_type
2961  operator()(_UniformRandomNumberGenerator& __urng)
2962  { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
2963 
2964  template<typename _UniformRandomNumberGenerator>
2965  result_type
2966  operator()(_UniformRandomNumberGenerator& __urng,
2967  const param_type& __p)
2968  {
2970  param_type;
2971  return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
2972  / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
2973  }
2974 
2975  /**
2976  * @brief Return true if two Fisher f distributions have
2977  * the same parameters and the sequences that would
2978  * be generated are equal.
2979  */
2980  template<typename _RealType1>
2981  friend bool
2984  { return (__d1.param() == __d2.param()
2985  && __d1._M_gd_x == __d2._M_gd_x
2986  && __d1._M_gd_y == __d2._M_gd_y); }
2987 
2988  /**
2989  * @brief Inserts a %fisher_f_distribution random number distribution
2990  * @p __x into the output stream @p __os.
2991  *
2992  * @param __os An output stream.
2993  * @param __x A %fisher_f_distribution random number distribution.
2994  *
2995  * @returns The output stream with the state of @p __x inserted or in
2996  * an error state.
2997  */
2998  template<typename _RealType1, typename _CharT, typename _Traits>
3000  operator<<(std::basic_ostream<_CharT, _Traits>&,
3002 
3003  /**
3004  * @brief Extracts a %fisher_f_distribution random number distribution
3005  * @p __x from the input stream @p __is.
3006  *
3007  * @param __is An input stream.
3008  * @param __x A %fisher_f_distribution random number
3009  * generator engine.
3010  *
3011  * @returns The input stream with @p __x extracted or in an error state.
3012  */
3013  template<typename _RealType1, typename _CharT, typename _Traits>
3017 
3018  private:
3019  param_type _M_param;
3020 
3021  std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
3022  };
3023 
3024  /**
3025  * @brief Return true if two Fisher f distributions are diferent.
3026  */
3027  template<typename _RealType>
3028  inline bool
3031  { return !(__d1 == __d2); }
3032 
3033  /**
3034  * @brief A student_t_distribution random number distribution.
3035  *
3036  * The formula for the normal probability mass function is:
3037  * @f[
3038  * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
3039  * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
3040  * @f]
3041  */
3042  template<typename _RealType = double>
3044  {
3046  "template argument not a floating point type");
3047 
3048  public:
3049  /** The type of the range of the distribution. */
3050  typedef _RealType result_type;
3051  /** Parameter type. */
3052  struct param_type
3053  {
3055 
3056  explicit
3057  param_type(_RealType __n = _RealType(1))
3058  : _M_n(__n)
3059  { }
3060 
3061  _RealType
3062  n() const
3063  { return _M_n; }
3064 
3065  friend bool
3066  operator==(const param_type& __p1, const param_type& __p2)
3067  { return __p1._M_n == __p2._M_n; }
3068 
3069  private:
3070  _RealType _M_n;
3071  };
3072 
3073  explicit
3074  student_t_distribution(_RealType __n = _RealType(1))
3075  : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
3076  { }
3077 
3078  explicit
3079  student_t_distribution(const param_type& __p)
3080  : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
3081  { }
3082 
3083  /**
3084  * @brief Resets the distribution state.
3085  */
3086  void
3088  {
3089  _M_nd.reset();
3090  _M_gd.reset();
3091  }
3092 
3093  /**
3094  *
3095  */
3096  _RealType
3097  n() const
3098  { return _M_param.n(); }
3099 
3100  /**
3101  * @brief Returns the parameter set of the distribution.
3102  */
3103  param_type
3104  param() const
3105  { return _M_param; }
3106 
3107  /**
3108  * @brief Sets the parameter set of the distribution.
3109  * @param __param The new parameter set of the distribution.
3110  */
3111  void
3112  param(const param_type& __param)
3113  { _M_param = __param; }
3114 
3115  /**
3116  * @brief Returns the greatest lower bound value of the distribution.
3117  */
3118  result_type
3119  min() const
3121 
3122  /**
3123  * @brief Returns the least upper bound value of the distribution.
3124  */
3125  result_type
3126  max() const
3128 
3129  /**
3130  * @brief Generating functions.
3131  */
3132  template<typename _UniformRandomNumberGenerator>
3133  result_type
3134  operator()(_UniformRandomNumberGenerator& __urng)
3135  { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
3136 
3137  template<typename _UniformRandomNumberGenerator>
3138  result_type
3139  operator()(_UniformRandomNumberGenerator& __urng,
3140  const param_type& __p)
3141  {
3143  param_type;
3144 
3145  const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
3146  return _M_nd(__urng) * std::sqrt(__p.n() / __g);
3147  }
3148 
3149  /**
3150  * @brief Return true if two Student t distributions have
3151  * the same parameters and the sequences that would
3152  * be generated are equal.
3153  */
3154  template<typename _RealType1>
3155  friend bool
3158  { return (__d1.param() == __d2.param()
3159  && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
3160 
3161  /**
3162  * @brief Inserts a %student_t_distribution random number distribution
3163  * @p __x into the output stream @p __os.
3164  *
3165  * @param __os An output stream.
3166  * @param __x A %student_t_distribution random number distribution.
3167  *
3168  * @returns The output stream with the state of @p __x inserted or in
3169  * an error state.
3170  */
3171  template<typename _RealType1, typename _CharT, typename _Traits>
3173  operator<<(std::basic_ostream<_CharT, _Traits>&,
3175 
3176  /**
3177  * @brief Extracts a %student_t_distribution random number distribution
3178  * @p __x from the input stream @p __is.
3179  *
3180  * @param __is An input stream.
3181  * @param __x A %student_t_distribution random number
3182  * generator engine.
3183  *
3184  * @returns The input stream with @p __x extracted or in an error state.
3185  */
3186  template<typename _RealType1, typename _CharT, typename _Traits>
3190 
3191  private:
3192  param_type _M_param;
3193 
3196  };
3197 
3198  /**
3199  * @brief Return true if two Student t distributions are different.
3200  */
3201  template<typename _RealType>
3202  inline bool
3205  { return !(__d1 == __d2); }
3206 
3207 
3208  /* @} */ // group random_distributions_normal
3209 
3210  /**
3211  * @addtogroup random_distributions_bernoulli Bernoulli Distributions
3212  * @ingroup random_distributions
3213  * @{
3214  */
3215 
3216  /**
3217  * @brief A Bernoulli random number distribution.
3218  *
3219  * Generates a sequence of true and false values with likelihood @f$p@f$
3220  * that true will come up and @f$(1 - p)@f$ that false will appear.
3221  */
3223  {
3224  public:
3225  /** The type of the range of the distribution. */
3226  typedef bool result_type;
3227  /** Parameter type. */
3228  struct param_type
3229  {
3231 
3232  explicit
3233  param_type(double __p = 0.5)
3234  : _M_p(__p)
3235  {
3236  _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
3237  }
3238 
3239  double
3240  p() const
3241  { return _M_p; }
3242 
3243  friend bool
3244  operator==(const param_type& __p1, const param_type& __p2)
3245  { return __p1._M_p == __p2._M_p; }
3246 
3247  private:
3248  double _M_p;
3249  };
3250 
3251  public:
3252  /**
3253  * @brief Constructs a Bernoulli distribution with likelihood @p p.
3254  *
3255  * @param __p [IN] The likelihood of a true result being returned.
3256  * Must be in the interval @f$[0, 1]@f$.
3257  */
3258  explicit
3259  bernoulli_distribution(double __p = 0.5)
3260  : _M_param(__p)
3261  { }
3262 
3263  explicit
3264  bernoulli_distribution(const param_type& __p)
3265  : _M_param(__p)
3266  { }
3267 
3268  /**
3269  * @brief Resets the distribution state.
3270  *
3271  * Does nothing for a Bernoulli distribution.
3272  */
3273  void
3274  reset() { }
3275 
3276  /**
3277  * @brief Returns the @p p parameter of the distribution.
3278  */
3279  double
3280  p() const
3281  { return _M_param.p(); }
3282 
3283  /**
3284  * @brief Returns the parameter set of the distribution.
3285  */
3286  param_type
3287  param() const
3288  { return _M_param; }
3289 
3290  /**
3291  * @brief Sets the parameter set of the distribution.
3292  * @param __param The new parameter set of the distribution.
3293  */
3294  void
3295  param(const param_type& __param)
3296  { _M_param = __param; }
3297 
3298  /**
3299  * @brief Returns the greatest lower bound value of the distribution.
3300  */
3301  result_type
3302  min() const
3304 
3305  /**
3306  * @brief Returns the least upper bound value of the distribution.
3307  */
3308  result_type
3309  max() const
3311 
3312  /**
3313  * @brief Generating functions.
3314  */
3315  template<typename _UniformRandomNumberGenerator>
3316  result_type
3317  operator()(_UniformRandomNumberGenerator& __urng)
3318  { return this->operator()(__urng, this->param()); }
3319 
3320  template<typename _UniformRandomNumberGenerator>
3321  result_type
3322  operator()(_UniformRandomNumberGenerator& __urng,
3323  const param_type& __p)
3324  {
3325  __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3326  __aurng(__urng);
3327  if ((__aurng() - __aurng.min())
3328  < __p.p() * (__aurng.max() - __aurng.min()))
3329  return true;
3330  return false;
3331  }
3332 
3333  private:
3334  param_type _M_param;
3335  };
3336 
3337  /**
3338  * @brief Return true if two Bernoulli distributions have
3339  * the same parameters.
3340  */
3341  inline bool
3342  operator==(const std::bernoulli_distribution& __d1,
3343  const std::bernoulli_distribution& __d2)
3344  { return __d1.param() == __d2.param(); }
3345 
3346  /**
3347  * @brief Return true if two Bernoulli distributions have
3348  * different parameters.
3349  */
3350  inline bool
3351  operator!=(const std::bernoulli_distribution& __d1,
3352  const std::bernoulli_distribution& __d2)
3353  { return !(__d1 == __d2); }
3354 
3355  /**
3356  * @brief Inserts a %bernoulli_distribution random number distribution
3357  * @p __x into the output stream @p __os.
3358  *
3359  * @param __os An output stream.
3360  * @param __x A %bernoulli_distribution random number distribution.
3361  *
3362  * @returns The output stream with the state of @p __x inserted or in
3363  * an error state.
3364  */
3365  template<typename _CharT, typename _Traits>
3367  operator<<(std::basic_ostream<_CharT, _Traits>&,
3369 
3370  /**
3371  * @brief Extracts a %bernoulli_distribution random number distribution
3372  * @p __x from the input stream @p __is.
3373  *
3374  * @param __is An input stream.
3375  * @param __x A %bernoulli_distribution random number generator engine.
3376  *
3377  * @returns The input stream with @p __x extracted or in an error state.
3378  */
3379  template<typename _CharT, typename _Traits>
3383  {
3384  double __p;
3385  __is >> __p;
3387  return __is;
3388  }
3389 
3390 
3391  /**
3392  * @brief A discrete binomial random number distribution.
3393  *
3394  * The formula for the binomial probability density function is
3395  * @f$p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3396  * and @f$p@f$ are the parameters of the distribution.
3397  */
3398  template<typename _IntType = int>
3400  {
3401  static_assert(std::is_integral<_IntType>::value,
3402  "template argument not an integral type");
3403 
3404  public:
3405  /** The type of the range of the distribution. */
3406  typedef _IntType result_type;
3407  /** Parameter type. */
3408  struct param_type
3409  {
3411  friend class binomial_distribution<_IntType>;
3412 
3413  explicit
3414  param_type(_IntType __t = _IntType(1), double __p = 0.5)
3415  : _M_t(__t), _M_p(__p)
3416  {
3417  _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
3418  && (_M_p >= 0.0)
3419  && (_M_p <= 1.0));
3420  _M_initialize();
3421  }
3422 
3423  _IntType
3424  t() const
3425  { return _M_t; }
3426 
3427  double
3428  p() const
3429  { return _M_p; }
3430 
3431  friend bool
3432  operator==(const param_type& __p1, const param_type& __p2)
3433  { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
3434 
3435  private:
3436  void
3437  _M_initialize();
3438 
3439  _IntType _M_t;
3440  double _M_p;
3441 
3442  double _M_q;
3443 #if _GLIBCXX_USE_C99_MATH_TR1
3444  double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
3445  _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
3446 #endif
3447  bool _M_easy;
3448  };
3449 
3450  // constructors and member function
3451  explicit
3452  binomial_distribution(_IntType __t = _IntType(1),
3453  double __p = 0.5)
3454  : _M_param(__t, __p), _M_nd()
3455  { }
3456 
3457  explicit
3458  binomial_distribution(const param_type& __p)
3459  : _M_param(__p), _M_nd()
3460  { }
3461 
3462  /**
3463  * @brief Resets the distribution state.
3464  */
3465  void
3467  { _M_nd.reset(); }
3468 
3469  /**
3470  * @brief Returns the distribution @p t parameter.
3471  */
3472  _IntType
3473  t() const
3474  { return _M_param.t(); }
3475 
3476  /**
3477  * @brief Returns the distribution @p p parameter.
3478  */
3479  double
3480  p() const
3481  { return _M_param.p(); }
3482 
3483  /**
3484  * @brief Returns the parameter set of the distribution.
3485  */
3486  param_type
3487  param() const
3488  { return _M_param; }
3489 
3490  /**
3491  * @brief Sets the parameter set of the distribution.
3492  * @param __param The new parameter set of the distribution.
3493  */
3494  void
3495  param(const param_type& __param)
3496  { _M_param = __param; }
3497 
3498  /**
3499  * @brief Returns the greatest lower bound value of the distribution.
3500  */
3501  result_type
3502  min() const
3503  { return 0; }
3504 
3505  /**
3506  * @brief Returns the least upper bound value of the distribution.
3507  */
3508  result_type
3509  max() const
3510  { return _M_param.t(); }
3511 
3512  /**
3513  * @brief Generating functions.
3514  */
3515  template<typename _UniformRandomNumberGenerator>
3516  result_type
3517  operator()(_UniformRandomNumberGenerator& __urng)
3518  { return this->operator()(__urng, this->param()); }
3519 
3520  template<typename _UniformRandomNumberGenerator>
3521  result_type
3522  operator()(_UniformRandomNumberGenerator& __urng,
3523  const param_type& __p);
3524 
3525  /**
3526  * @brief Return true if two binomial distributions have
3527  * the same parameters and the sequences that would
3528  * be generated are equal.
3529  */
3530  template<typename _IntType1>
3531  friend bool
3534 #ifdef _GLIBCXX_USE_C99_MATH_TR1
3535  { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
3536 #else
3537  { return __d1.param() == __d2.param(); }
3538 #endif
3539 
3540  /**
3541  * @brief Inserts a %binomial_distribution random number distribution
3542  * @p __x into the output stream @p __os.
3543  *
3544  * @param __os An output stream.
3545  * @param __x A %binomial_distribution random number distribution.
3546  *
3547  * @returns The output stream with the state of @p __x inserted or in
3548  * an error state.
3549  */
3550  template<typename _IntType1,
3551  typename _CharT, typename _Traits>
3553  operator<<(std::basic_ostream<_CharT, _Traits>&,
3555 
3556  /**
3557  * @brief Extracts a %binomial_distribution random number distribution
3558  * @p __x from the input stream @p __is.
3559  *
3560  * @param __is An input stream.
3561  * @param __x A %binomial_distribution random number generator engine.
3562  *
3563  * @returns The input stream with @p __x extracted or in an error
3564  * state.
3565  */
3566  template<typename _IntType1,
3567  typename _CharT, typename _Traits>
3571 
3572  private:
3573  template<typename _UniformRandomNumberGenerator>
3574  result_type
3575  _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
3576 
3577  param_type _M_param;
3578 
3579  // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
3581  };
3582 
3583  /**
3584  * @brief Return true if two binomial distributions are different.
3585  */
3586  template<typename _IntType>
3587  inline bool
3590  { return !(__d1 == __d2); }
3591 
3592 
3593  /**
3594  * @brief A discrete geometric random number distribution.
3595  *
3596  * The formula for the geometric probability density function is
3597  * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
3598  * distribution.
3599  */
3600  template<typename _IntType = int>
3602  {
3603  static_assert(std::is_integral<_IntType>::value,
3604  "template argument not an integral type");
3605 
3606  public:
3607  /** The type of the range of the distribution. */
3608  typedef _IntType result_type;
3609  /** Parameter type. */
3610  struct param_type
3611  {
3613  friend class geometric_distribution<_IntType>;
3614 
3615  explicit
3616  param_type(double __p = 0.5)
3617  : _M_p(__p)
3618  {
3619  _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0)
3620  && (_M_p < 1.0));
3621  _M_initialize();
3622  }
3623 
3624  double
3625  p() const
3626  { return _M_p; }
3627 
3628  friend bool
3629  operator==(const param_type& __p1, const param_type& __p2)
3630  { return __p1._M_p == __p2._M_p; }
3631 
3632  private:
3633  void
3634  _M_initialize()
3635  { _M_log_1_p = std::log(1.0 - _M_p); }
3636 
3637  double _M_p;
3638 
3639  double _M_log_1_p;
3640  };
3641 
3642  // constructors and member function
3643  explicit
3644  geometric_distribution(double __p = 0.5)
3645  : _M_param(__p)
3646  { }
3647 
3648  explicit
3649  geometric_distribution(const param_type& __p)
3650  : _M_param(__p)
3651  { }
3652 
3653  /**
3654  * @brief Resets the distribution state.
3655  *
3656  * Does nothing for the geometric distribution.
3657  */
3658  void
3659  reset() { }
3660 
3661  /**
3662  * @brief Returns the distribution parameter @p p.
3663  */
3664  double
3665  p() const
3666  { return _M_param.p(); }
3667 
3668  /**
3669  * @brief Returns the parameter set of the distribution.
3670  */
3671  param_type
3672  param() const
3673  { return _M_param; }
3674 
3675  /**
3676  * @brief Sets the parameter set of the distribution.
3677  * @param __param The new parameter set of the distribution.
3678  */
3679  void
3680  param(const param_type& __param)
3681  { _M_param = __param; }
3682 
3683  /**
3684  * @brief Returns the greatest lower bound value of the distribution.
3685  */
3686  result_type
3687  min() const
3688  { return 0; }
3689 
3690  /**
3691  * @brief Returns the least upper bound value of the distribution.
3692  */
3693  result_type
3694  max() const
3696 
3697  /**
3698  * @brief Generating functions.
3699  */
3700  template<typename _UniformRandomNumberGenerator>
3701  result_type
3702  operator()(_UniformRandomNumberGenerator& __urng)
3703  { return this->operator()(__urng, this->param()); }
3704 
3705  template<typename _UniformRandomNumberGenerator>
3706  result_type
3707  operator()(_UniformRandomNumberGenerator& __urng,
3708  const param_type& __p);
3709 
3710  private:
3711  param_type _M_param;
3712  };
3713 
3714  /**
3715  * @brief Return true if two geometric distributions have
3716  * the same parameters.
3717  */
3718  template<typename _IntType>
3719  inline bool
3722  { return __d1.param() == __d2.param(); }
3723 
3724  /**
3725  * @brief Return true if two geometric distributions have
3726  * different parameters.
3727  */
3728  template<typename _IntType>
3729  inline bool
3732  { return !(__d1 == __d2); }
3733 
3734  /**
3735  * @brief Inserts a %geometric_distribution random number distribution
3736  * @p __x into the output stream @p __os.
3737  *
3738  * @param __os An output stream.
3739  * @param __x A %geometric_distribution random number distribution.
3740  *
3741  * @returns The output stream with the state of @p __x inserted or in
3742  * an error state.
3743  */
3744  template<typename _IntType,
3745  typename _CharT, typename _Traits>
3747  operator<<(std::basic_ostream<_CharT, _Traits>&,
3749 
3750  /**
3751  * @brief Extracts a %geometric_distribution random number distribution
3752  * @p __x from the input stream @p __is.
3753  *
3754  * @param __is An input stream.
3755  * @param __x A %geometric_distribution random number generator engine.
3756  *
3757  * @returns The input stream with @p __x extracted or in an error state.
3758  */
3759  template<typename _IntType,
3760  typename _CharT, typename _Traits>
3764 
3765 
3766  /**
3767  * @brief A negative_binomial_distribution random number distribution.
3768  *
3769  * The formula for the negative binomial probability mass function is
3770  * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
3771  * and @f$p@f$ are the parameters of the distribution.
3772  */
3773  template<typename _IntType = int>
3775  {
3776  static_assert(std::is_integral<_IntType>::value,
3777  "template argument not an integral type");
3778 
3779  public:
3780  /** The type of the range of the distribution. */
3781  typedef _IntType result_type;
3782  /** Parameter type. */
3783  struct param_type
3784  {
3786 
3787  explicit
3788  param_type(_IntType __k = 1, double __p = 0.5)
3789  : _M_k(__k), _M_p(__p)
3790  {
3791  _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
3792  }
3793 
3794  _IntType
3795  k() const
3796  { return _M_k; }
3797 
3798  double
3799  p() const
3800  { return _M_p; }
3801 
3802  friend bool
3803  operator==(const param_type& __p1, const param_type& __p2)
3804  { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
3805 
3806  private:
3807  _IntType _M_k;
3808  double _M_p;
3809  };
3810 
3811  explicit
3812  negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
3813  : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
3814  { }
3815 
3816  explicit
3817  negative_binomial_distribution(const param_type& __p)
3818  : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
3819  { }
3820 
3821  /**
3822  * @brief Resets the distribution state.
3823  */
3824  void
3826  { _M_gd.reset(); }
3827 
3828  /**
3829  * @brief Return the @f$k@f$ parameter of the distribution.
3830  */
3831  _IntType
3832  k() const
3833  { return _M_param.k(); }
3834 
3835  /**
3836  * @brief Return the @f$p@f$ parameter of the distribution.
3837  */
3838  double
3839  p() const
3840  { return _M_param.p(); }
3841 
3842  /**
3843  * @brief Returns the parameter set of the distribution.
3844  */
3845  param_type
3846  param() const
3847  { return _M_param; }
3848 
3849  /**
3850  * @brief Sets the parameter set of the distribution.
3851  * @param __param The new parameter set of the distribution.
3852  */
3853  void
3854  param(const param_type& __param)
3855  { _M_param = __param; }
3856 
3857  /**
3858  * @brief Returns the greatest lower bound value of the distribution.
3859  */
3860  result_type
3861  min() const
3862  { return result_type(0); }
3863 
3864  /**
3865  * @brief Returns the least upper bound value of the distribution.
3866  */
3867  result_type
3868  max() const
3870 
3871  /**
3872  * @brief Generating functions.
3873  */
3874  template<typename _UniformRandomNumberGenerator>
3875  result_type
3876  operator()(_UniformRandomNumberGenerator& __urng);
3877 
3878  template<typename _UniformRandomNumberGenerator>
3879  result_type
3880  operator()(_UniformRandomNumberGenerator& __urng,
3881  const param_type& __p);
3882 
3883  /**
3884  * @brief Return true if two negative binomial distributions have
3885  * the same parameters and the sequences that would be
3886  * generated are equal.
3887  */
3888  template<typename _IntType1>
3889  friend bool
3892  { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
3893 
3894  /**
3895  * @brief Inserts a %negative_binomial_distribution random
3896  * number distribution @p __x into the output stream @p __os.
3897  *
3898  * @param __os An output stream.
3899  * @param __x A %negative_binomial_distribution random number
3900  * distribution.
3901  *
3902  * @returns The output stream with the state of @p __x inserted or in
3903  * an error state.
3904  */
3905  template<typename _IntType1, typename _CharT, typename _Traits>
3907  operator<<(std::basic_ostream<_CharT, _Traits>&,
3909 
3910  /**
3911  * @brief Extracts a %negative_binomial_distribution random number
3912  * distribution @p __x from the input stream @p __is.
3913  *
3914  * @param __is An input stream.
3915  * @param __x A %negative_binomial_distribution random number
3916  * generator engine.
3917  *
3918  * @returns The input stream with @p __x extracted or in an error state.
3919  */
3920  template<typename _IntType1, typename _CharT, typename _Traits>
3924 
3925  private:
3926  param_type _M_param;
3927 
3929  };
3930 
3931  /**
3932  * @brief Return true if two negative binomial distributions are different.
3933  */
3934  template<typename _IntType>
3935  inline bool
3938  { return !(__d1 == __d2); }
3939 
3940 
3941  /* @} */ // group random_distributions_bernoulli
3942 
3943  /**
3944  * @addtogroup random_distributions_poisson Poisson Distributions
3945  * @ingroup random_distributions
3946  * @{
3947  */
3948 
3949  /**
3950  * @brief A discrete Poisson random number distribution.
3951  *
3952  * The formula for the Poisson probability density function is
3953  * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
3954  * parameter of the distribution.
3955  */
3956  template<typename _IntType = int>
3958  {
3959  static_assert(std::is_integral<_IntType>::value,
3960  "template argument not an integral type");
3961 
3962  public:
3963  /** The type of the range of the distribution. */
3964  typedef _IntType result_type;
3965  /** Parameter type. */
3966  struct param_type
3967  {
3969  friend class poisson_distribution<_IntType>;
3970 
3971  explicit
3972  param_type(double __mean = 1.0)
3973  : _M_mean(__mean)
3974  {
3975  _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
3976  _M_initialize();
3977  }
3978 
3979  double
3980  mean() const
3981  { return _M_mean; }
3982 
3983  friend bool
3984  operator==(const param_type& __p1, const param_type& __p2)
3985  { return __p1._M_mean == __p2._M_mean; }
3986 
3987  private:
3988  // Hosts either log(mean) or the threshold of the simple method.
3989  void
3990  _M_initialize();
3991 
3992  double _M_mean;
3993 
3994  double _M_lm_thr;
3995 #if _GLIBCXX_USE_C99_MATH_TR1
3996  double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
3997 #endif
3998  };
3999 
4000  // constructors and member function
4001  explicit
4002  poisson_distribution(double __mean = 1.0)
4003  : _M_param(__mean), _M_nd()
4004  { }
4005 
4006  explicit
4007  poisson_distribution(const param_type& __p)
4008  : _M_param(__p), _M_nd()
4009  { }
4010 
4011  /**
4012  * @brief Resets the distribution state.
4013  */
4014  void
4016  { _M_nd.reset(); }
4017 
4018  /**
4019  * @brief Returns the distribution parameter @p mean.
4020  */
4021  double
4022  mean() const
4023  { return _M_param.mean(); }
4024 
4025  /**
4026  * @brief Returns the parameter set of the distribution.
4027  */
4028  param_type
4029  param() const
4030  { return _M_param; }
4031 
4032  /**
4033  * @brief Sets the parameter set of the distribution.
4034  * @param __param The new parameter set of the distribution.
4035  */
4036  void
4037  param(const param_type& __param)
4038  { _M_param = __param; }
4039 
4040  /**
4041  * @brief Returns the greatest lower bound value of the distribution.
4042  */
4043  result_type
4044  min() const
4045  { return 0; }
4046 
4047  /**
4048  * @brief Returns the least upper bound value of the distribution.
4049  */
4050  result_type
4051  max() const
4053 
4054  /**
4055  * @brief Generating functions.
4056  */
4057  template<typename _UniformRandomNumberGenerator>
4058  result_type
4059  operator()(_UniformRandomNumberGenerator& __urng)
4060  { return this->operator()(__urng, this->param()); }
4061 
4062  template<typename _UniformRandomNumberGenerator>
4063  result_type
4064  operator()(_UniformRandomNumberGenerator& __urng,
4065  const param_type& __p);
4066 
4067  /**
4068  * @brief Return true if two Poisson distributions have the same
4069  * parameters and the sequences that would be generated
4070  * are equal.
4071  */
4072  template<typename _IntType1>
4073  friend bool
4076 #ifdef _GLIBCXX_USE_C99_MATH_TR1
4077  { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
4078 #else
4079  { return __d1.param() == __d2.param(); }
4080 #endif
4081 
4082  /**
4083  * @brief Inserts a %poisson_distribution random number distribution
4084  * @p __x into the output stream @p __os.
4085  *
4086  * @param __os An output stream.
4087  * @param __x A %poisson_distribution random number distribution.
4088  *
4089  * @returns The output stream with the state of @p __x inserted or in
4090  * an error state.
4091  */
4092  template<typename _IntType1, typename _CharT, typename _Traits>
4094  operator<<(std::basic_ostream<_CharT, _Traits>&,
4096 
4097  /**
4098  * @brief Extracts a %poisson_distribution random number distribution
4099  * @p __x from the input stream @p __is.
4100  *
4101  * @param __is An input stream.
4102  * @param __x A %poisson_distribution random number generator engine.
4103  *
4104  * @returns The input stream with @p __x extracted or in an error
4105  * state.
4106  */
4107  template<typename _IntType1, typename _CharT, typename _Traits>
4111 
4112  private:
4113  param_type _M_param;
4114 
4115  // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
4117  };
4118 
4119  /**
4120  * @brief Return true if two Poisson distributions are different.
4121  */
4122  template<typename _IntType>
4123  inline bool
4126  { return !(__d1 == __d2); }
4127 
4128 
4129  /**
4130  * @brief An exponential continuous distribution for random numbers.
4131  *
4132  * The formula for the exponential probability density function is
4133  * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
4134  *
4135  * <table border=1 cellpadding=10 cellspacing=0>
4136  * <caption align=top>Distribution Statistics</caption>
4137  * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4138  * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
4139  * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
4140  * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
4141  * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
4142  * </table>
4143  */
4144  template<typename _RealType = double>
4146  {
4148  "template argument not a floating point type");
4149 
4150  public:
4151  /** The type of the range of the distribution. */
4152  typedef _RealType result_type;
4153  /** Parameter type. */
4154  struct param_type
4155  {
4157 
4158  explicit
4159  param_type(_RealType __lambda = _RealType(1))
4160  : _M_lambda(__lambda)
4161  {
4162  _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
4163  }
4164 
4165  _RealType
4166  lambda() const
4167  { return _M_lambda; }
4168 
4169  friend bool
4170  operator==(const param_type& __p1, const param_type& __p2)
4171  { return __p1._M_lambda == __p2._M_lambda; }
4172 
4173  private:
4174  _RealType _M_lambda;
4175  };
4176 
4177  public:
4178  /**
4179  * @brief Constructs an exponential distribution with inverse scale
4180  * parameter @f$\lambda@f$.
4181  */
4182  explicit
4184  : _M_param(__lambda)
4185  { }
4186 
4187  explicit
4188  exponential_distribution(const param_type& __p)
4189  : _M_param(__p)
4190  { }
4191 
4192  /**
4193  * @brief Resets the distribution state.
4194  *
4195  * Has no effect on exponential distributions.
4196  */
4197  void
4198  reset() { }
4199 
4200  /**
4201  * @brief Returns the inverse scale parameter of the distribution.
4202  */
4203  _RealType
4204  lambda() const
4205  { return _M_param.lambda(); }
4206 
4207  /**
4208  * @brief Returns the parameter set of the distribution.
4209  */
4210  param_type
4211  param() const
4212  { return _M_param; }
4213 
4214  /**
4215  * @brief Sets the parameter set of the distribution.
4216  * @param __param The new parameter set of the distribution.
4217  */
4218  void
4219  param(const param_type& __param)
4220  { _M_param = __param; }
4221 
4222  /**
4223  * @brief Returns the greatest lower bound value of the distribution.
4224  */
4225  result_type
4226  min() const
4227  { return result_type(0); }
4228 
4229  /**
4230  * @brief Returns the least upper bound value of the distribution.
4231  */
4232  result_type
4233  max() const
4235 
4236  /**
4237  * @brief Generating functions.
4238  */
4239  template<typename _UniformRandomNumberGenerator>
4240  result_type
4241  operator()(_UniformRandomNumberGenerator& __urng)
4242  { return this->operator()(__urng, this->param()); }
4243 
4244  template<typename _UniformRandomNumberGenerator>
4245  result_type
4246  operator()(_UniformRandomNumberGenerator& __urng,
4247  const param_type& __p)
4248  {
4249  __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
4250  __aurng(__urng);
4251  return -std::log(__aurng()) / __p.lambda();
4252  }
4253 
4254  private:
4255  param_type _M_param;
4256  };
4257 
4258  /**
4259  * @brief Return true if two exponential distributions have the same
4260  * parameters.
4261  */
4262  template<typename _RealType>
4263  inline bool
4266  { return __d1.param() == __d2.param(); }
4267 
4268  /**
4269  * @brief Return true if two exponential distributions have different
4270  * parameters.
4271  */
4272  template<typename _RealType>
4273  inline bool
4276  { return !(__d1 == __d2); }
4277 
4278  /**
4279  * @brief Inserts a %exponential_distribution random number distribution
4280  * @p __x into the output stream @p __os.
4281  *
4282  * @param __os An output stream.
4283  * @param __x A %exponential_distribution random number distribution.
4284  *
4285  * @returns The output stream with the state of @p __x inserted or in
4286  * an error state.
4287  */
4288  template<typename _RealType, typename _CharT, typename _Traits>
4290  operator<<(std::basic_ostream<_CharT, _Traits>&,
4292 
4293  /**
4294  * @brief Extracts a %exponential_distribution random number distribution
4295  * @p __x from the input stream @p __is.
4296  *
4297  * @param __is An input stream.
4298  * @param __x A %exponential_distribution random number
4299  * generator engine.
4300  *
4301  * @returns The input stream with @p __x extracted or in an error state.
4302  */
4303  template<typename _RealType, typename _CharT, typename _Traits>
4307 
4308 
4309  /**
4310  * @brief A weibull_distribution random number distribution.
4311  *
4312  * The formula for the normal probability density function is:
4313  * @f[
4314  * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
4315  * \exp{(-(\frac{x}{\beta})^\alpha)}
4316  * @f]
4317  */
4318  template<typename _RealType = double>
4320  {
4322  "template argument not a floating point type");
4323 
4324  public:
4325  /** The type of the range of the distribution. */
4326  typedef _RealType result_type;
4327  /** Parameter type. */
4328  struct param_type
4329  {
4331 
4332  explicit
4333  param_type(_RealType __a = _RealType(1),
4334  _RealType __b = _RealType(1))
4335  : _M_a(__a), _M_b(__b)
4336  { }
4337 
4338  _RealType
4339  a() const
4340  { return _M_a; }
4341 
4342  _RealType
4343  b() const
4344  { return _M_b; }
4345 
4346  friend bool
4347  operator==(const param_type& __p1, const param_type& __p2)
4348  { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4349 
4350  private:
4351  _RealType _M_a;
4352  _RealType _M_b;
4353  };
4354 
4355  explicit
4356  weibull_distribution(_RealType __a = _RealType(1),
4357  _RealType __b = _RealType(1))
4358  : _M_param(__a, __b)
4359  { }
4360 
4361  explicit
4362  weibull_distribution(const param_type& __p)
4363  : _M_param(__p)
4364  { }
4365 
4366  /**
4367  * @brief Resets the distribution state.
4368  */
4369  void
4371  { }
4372 
4373  /**
4374  * @brief Return the @f$a@f$ parameter of the distribution.
4375  */
4376  _RealType
4377  a() const
4378  { return _M_param.a(); }
4379 
4380  /**
4381  * @brief Return the @f$b@f$ parameter of the distribution.
4382  */
4383  _RealType
4384  b() const
4385  { return _M_param.b(); }
4386 
4387  /**
4388  * @brief Returns the parameter set of the distribution.
4389  */
4390  param_type
4391  param() const
4392  { return _M_param; }
4393 
4394  /**
4395  * @brief Sets the parameter set of the distribution.
4396  * @param __param The new parameter set of the distribution.
4397  */
4398  void
4399  param(const param_type& __param)
4400  { _M_param = __param; }
4401 
4402  /**
4403  * @brief Returns the greatest lower bound value of the distribution.
4404  */
4405  result_type
4406  min() const
4407  { return result_type(0); }
4408 
4409  /**
4410  * @brief Returns the least upper bound value of the distribution.
4411  */
4412  result_type
4413  max() const
4415 
4416  /**
4417  * @brief Generating functions.
4418  */
4419  template<typename _UniformRandomNumberGenerator>
4420  result_type
4421  operator()(_UniformRandomNumberGenerator& __urng)
4422  { return this->operator()(__urng, this->param()); }
4423 
4424  template<typename _UniformRandomNumberGenerator>
4425  result_type
4426  operator()(_UniformRandomNumberGenerator& __urng,
4427  const param_type& __p);
4428 
4429  private:
4430  param_type _M_param;
4431  };
4432 
4433  /**
4434  * @brief Return true if two Weibull distributions have the same
4435  * parameters.
4436  */
4437  template<typename _RealType>
4438  inline bool
4441  { return __d1.param() == __d2.param(); }
4442 
4443  /**
4444  * @brief Return true if two Weibull distributions have different
4445  * parameters.
4446  */
4447  template<typename _RealType>
4448  inline bool
4451  { return !(__d1 == __d2); }
4452 
4453  /**
4454  * @brief Inserts a %weibull_distribution random number distribution
4455  * @p __x into the output stream @p __os.
4456  *
4457  * @param __os An output stream.
4458  * @param __x A %weibull_distribution random number distribution.
4459  *
4460  * @returns The output stream with the state of @p __x inserted or in
4461  * an error state.
4462  */
4463  template<typename _RealType, typename _CharT, typename _Traits>
4465  operator<<(std::basic_ostream<_CharT, _Traits>&,
4467 
4468  /**
4469  * @brief Extracts a %weibull_distribution random number distribution
4470  * @p __x from the input stream @p __is.
4471  *
4472  * @param __is An input stream.
4473  * @param __x A %weibull_distribution random number
4474  * generator engine.
4475  *
4476  * @returns The input stream with @p __x extracted or in an error state.
4477  */
4478  template<typename _RealType, typename _CharT, typename _Traits>
4482 
4483 
4484  /**
4485  * @brief A extreme_value_distribution random number distribution.
4486  *
4487  * The formula for the normal probability mass function is
4488  * @f[
4489  * p(x|a,b) = \frac{1}{b}
4490  * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
4491  * @f]
4492  */
4493  template<typename _RealType = double>
4495  {
4497  "template argument not a floating point type");
4498 
4499  public:
4500  /** The type of the range of the distribution. */
4501  typedef _RealType result_type;
4502  /** Parameter type. */
4503  struct param_type
4504  {
4506 
4507  explicit
4508  param_type(_RealType __a = _RealType(0),
4509  _RealType __b = _RealType(1))
4510  : _M_a(__a), _M_b(__b)
4511  { }
4512 
4513  _RealType
4514  a() const
4515  { return _M_a; }
4516 
4517  _RealType
4518  b() const
4519  { return _M_b; }
4520 
4521  friend bool
4522  operator==(const param_type& __p1, const param_type& __p2)
4523  { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
4524 
4525  private:
4526  _RealType _M_a;
4527  _RealType _M_b;
4528  };
4529 
4530  explicit
4531  extreme_value_distribution(_RealType __a = _RealType(0),
4532  _RealType __b = _RealType(1))
4533  : _M_param(__a, __b)
4534  { }
4535 
4536  explicit
4537  extreme_value_distribution(const param_type& __p)
4538  : _M_param(__p)
4539  { }
4540 
4541  /**
4542  * @brief Resets the distribution state.
4543  */
4544  void
4546  { }
4547 
4548  /**
4549  * @brief Return the @f$a@f$ parameter of the distribution.
4550  */
4551  _RealType
4552  a() const
4553  { return _M_param.a(); }
4554 
4555  /**
4556  * @brief Return the @f$b@f$ parameter of the distribution.
4557  */
4558  _RealType
4559  b() const
4560  { return _M_param.b(); }
4561 
4562  /**
4563  * @brief Returns the parameter set of the distribution.
4564  */
4565  param_type
4566  param() const
4567  { return _M_param; }
4568 
4569  /**
4570  * @brief Sets the parameter set of the distribution.
4571  * @param __param The new parameter set of the distribution.
4572  */
4573  void
4574  param(const param_type& __param)
4575  { _M_param = __param; }
4576 
4577  /**
4578  * @brief Returns the greatest lower bound value of the distribution.
4579  */
4580  result_type
4581  min() const
4583 
4584  /**
4585  * @brief Returns the least upper bound value of the distribution.
4586  */
4587  result_type
4588  max() const
4590 
4591  /**
4592  * @brief Generating functions.
4593  */
4594  template<typename _UniformRandomNumberGenerator>
4595  result_type
4596  operator()(_UniformRandomNumberGenerator& __urng)
4597  { return this->operator()(__urng, this->param()); }
4598 
4599  template<typename _UniformRandomNumberGenerator>
4600  result_type
4601  operator()(_UniformRandomNumberGenerator& __urng,
4602  const param_type& __p);
4603 
4604  private:
4605  param_type _M_param;
4606  };
4607 
4608  /**
4609  * @brief Return true if two extreme value distributions have the same
4610  * parameters.
4611  */
4612  template<typename _RealType>
4613  inline bool
4616  { return __d1.param() == __d2.param(); }
4617 
4618  /**
4619  * @brief Return true if two extreme value distributions have different
4620  * parameters.
4621  */
4622  template<typename _RealType>
4623  inline bool
4626  { return !(__d1 == __d2); }
4627 
4628  /**
4629  * @brief Inserts a %extreme_value_distribution random number distribution
4630  * @p __x into the output stream @p __os.
4631  *
4632  * @param __os An output stream.
4633  * @param __x A %extreme_value_distribution random number distribution.
4634  *
4635  * @returns The output stream with the state of @p __x inserted or in
4636  * an error state.
4637  */
4638  template<typename _RealType, typename _CharT, typename _Traits>
4640  operator<<(std::basic_ostream<_CharT, _Traits>&,
4642 
4643  /**
4644  * @brief Extracts a %extreme_value_distribution random number
4645  * distribution @p __x from the input stream @p __is.
4646  *
4647  * @param __is An input stream.
4648  * @param __x A %extreme_value_distribution random number
4649  * generator engine.
4650  *
4651  * @returns The input stream with @p __x extracted or in an error state.
4652  */
4653  template<typename _RealType, typename _CharT, typename _Traits>
4657 
4658 
4659  /**
4660  * @brief A discrete_distribution random number distribution.
4661  *
4662  * The formula for the discrete probability mass function is
4663  *
4664  */
4665  template<typename _IntType = int>
4667  {
4668  static_assert(std::is_integral<_IntType>::value,
4669  "template argument not an integral type");
4670 
4671  public:
4672  /** The type of the range of the distribution. */
4673  typedef _IntType result_type;
4674  /** Parameter type. */
4675  struct param_type
4676  {
4678  friend class discrete_distribution<_IntType>;
4679 
4680  param_type()
4681  : _M_prob(), _M_cp()
4682  { }
4683 
4684  template<typename _InputIterator>
4685  param_type(_InputIterator __wbegin,
4686  _InputIterator __wend)
4687  : _M_prob(__wbegin, __wend), _M_cp()
4688  { _M_initialize(); }
4689 
4690  param_type(initializer_list<double> __wil)
4691  : _M_prob(__wil.begin(), __wil.end()), _M_cp()
4692  { _M_initialize(); }
4693 
4694  template<typename _Func>
4695  param_type(size_t __nw, double __xmin, double __xmax,
4696  _Func __fw);
4697 
4698  // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4699  param_type(const param_type&) = default;
4700  param_type& operator=(const param_type&) = default;
4701 
4703  probabilities() const
4704  { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
4705 
4706  friend bool
4707  operator==(const param_type& __p1, const param_type& __p2)
4708  { return __p1._M_prob == __p2._M_prob; }
4709 
4710  private:
4711  void
4712  _M_initialize();
4713 
4714  std::vector<double> _M_prob;
4715  std::vector<double> _M_cp;
4716  };
4717 
4719  : _M_param()
4720  { }
4721 
4722  template<typename _InputIterator>
4723  discrete_distribution(_InputIterator __wbegin,
4724  _InputIterator __wend)
4725  : _M_param(__wbegin, __wend)
4726  { }
4727 
4728  discrete_distribution(initializer_list<double> __wl)
4729  : _M_param(__wl)
4730  { }
4731 
4732  template<typename _Func>
4733  discrete_distribution(size_t __nw, double __xmin, double __xmax,
4734  _Func __fw)
4735  : _M_param(__nw, __xmin, __xmax, __fw)
4736  { }
4737 
4738  explicit
4739  discrete_distribution(const param_type& __p)
4740  : _M_param(__p)
4741  { }
4742 
4743  /**
4744  * @brief Resets the distribution state.
4745  */
4746  void
4748  { }
4749 
4750  /**
4751  * @brief Returns the probabilities of the distribution.
4752  */
4755  {
4756  return _M_param._M_prob.empty()
4757  ? std::vector<double>(1, 1.0) : _M_param._M_prob;
4758  }
4759 
4760  /**
4761  * @brief Returns the parameter set of the distribution.
4762  */
4763  param_type
4764  param() const
4765  { return _M_param; }
4766 
4767  /**
4768  * @brief Sets the parameter set of the distribution.
4769  * @param __param The new parameter set of the distribution.
4770  */
4771  void
4772  param(const param_type& __param)
4773  { _M_param = __param; }
4774 
4775  /**
4776  * @brief Returns the greatest lower bound value of the distribution.
4777  */
4778  result_type
4779  min() const
4780  { return result_type(0); }
4781 
4782  /**
4783  * @brief Returns the least upper bound value of the distribution.
4784  */
4785  result_type
4786  max() const
4787  {
4788  return _M_param._M_prob.empty()
4789  ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
4790  }
4791 
4792  /**
4793  * @brief Generating functions.
4794  */
4795  template<typename _UniformRandomNumberGenerator>
4796  result_type
4797  operator()(_UniformRandomNumberGenerator& __urng)
4798  { return this->operator()(__urng, this->param()); }
4799 
4800  template<typename _UniformRandomNumberGenerator>
4801  result_type
4802  operator()(_UniformRandomNumberGenerator& __urng,
4803  const param_type& __p);
4804 
4805  /**
4806  * @brief Inserts a %discrete_distribution random number distribution
4807  * @p __x into the output stream @p __os.
4808  *
4809  * @param __os An output stream.
4810  * @param __x A %discrete_distribution random number distribution.
4811  *
4812  * @returns The output stream with the state of @p __x inserted or in
4813  * an error state.
4814  */
4815  template<typename _IntType1, typename _CharT, typename _Traits>
4817  operator<<(std::basic_ostream<_CharT, _Traits>&,
4819 
4820  /**
4821  * @brief Extracts a %discrete_distribution random number distribution
4822  * @p __x from the input stream @p __is.
4823  *
4824  * @param __is An input stream.
4825  * @param __x A %discrete_distribution random number
4826  * generator engine.
4827  *
4828  * @returns The input stream with @p __x extracted or in an error
4829  * state.
4830  */
4831  template<typename _IntType1, typename _CharT, typename _Traits>
4835 
4836  private:
4837  param_type _M_param;
4838  };
4839 
4840  /**
4841  * @brief Return true if two discrete distributions have the same
4842  * parameters.
4843  */
4844  template<typename _IntType>
4845  inline bool
4848  { return __d1.param() == __d2.param(); }
4849 
4850  /**
4851  * @brief Return true if two discrete distributions have different
4852  * parameters.
4853  */
4854  template<typename _IntType>
4855  inline bool
4858  { return !(__d1 == __d2); }
4859 
4860 
4861  /**
4862  * @brief A piecewise_constant_distribution random number distribution.
4863  *
4864  * The formula for the piecewise constant probability mass function is
4865  *
4866  */
4867  template<typename _RealType = double>
4869  {
4871  "template argument not a floating point type");
4872 
4873  public:
4874  /** The type of the range of the distribution. */
4875  typedef _RealType result_type;
4876  /** Parameter type. */
4877  struct param_type
4878  {
4880  friend class piecewise_constant_distribution<_RealType>;
4881 
4882  param_type()
4883  : _M_int(), _M_den(), _M_cp()
4884  { }
4885 
4886  template<typename _InputIteratorB, typename _InputIteratorW>
4887  param_type(_InputIteratorB __bfirst,
4888  _InputIteratorB __bend,
4889  _InputIteratorW __wbegin);
4890 
4891  template<typename _Func>
4892  param_type(initializer_list<_RealType> __bi, _Func __fw);
4893 
4894  template<typename _Func>
4895  param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
4896  _Func __fw);
4897 
4898  // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
4899  param_type(const param_type&) = default;
4900  param_type& operator=(const param_type&) = default;
4901 
4903  intervals() const
4904  {
4905  if (_M_int.empty())
4906  {
4907  std::vector<_RealType> __tmp(2);
4908  __tmp[1] = _RealType(1);
4909  return __tmp;
4910  }
4911  else
4912  return _M_int;
4913  }
4914 
4916  densities() const
4917  { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
4918 
4919  friend bool
4920  operator==(const param_type& __p1, const param_type& __p2)
4921  { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
4922 
4923  private:
4924  void
4925  _M_initialize();
4926 
4927  std::vector<_RealType> _M_int;
4928  std::vector<double> _M_den;
4929  std::vector<double> _M_cp;
4930  };
4931 
4932  explicit
4934  : _M_param()
4935  { }
4936 
4937  template<typename _InputIteratorB, typename _InputIteratorW>
4938  piecewise_constant_distribution(_InputIteratorB __bfirst,
4939  _InputIteratorB __bend,
4940  _InputIteratorW __wbegin)
4941  : _M_param(__bfirst, __bend, __wbegin)
4942  { }
4943 
4944  template<typename _Func>
4945  piecewise_constant_distribution(initializer_list<_RealType> __bl,
4946  _Func __fw)
4947  : _M_param(__bl, __fw)
4948  { }
4949 
4950  template<typename _Func>
4951  piecewise_constant_distribution(size_t __nw,
4952  _RealType __xmin, _RealType __xmax,
4953  _Func __fw)
4954  : _M_param(__nw, __xmin, __xmax, __fw)
4955  { }
4956 
4957  explicit
4958  piecewise_constant_distribution(const param_type& __p)
4959  : _M_param(__p)
4960  { }
4961 
4962  /**
4963  * @brief Resets the distribution state.
4964  */
4965  void
4967  { }
4968 
4969  /**
4970  * @brief Returns a vector of the intervals.
4971  */
4973  intervals() const
4974  {
4975  if (_M_param._M_int.empty())
4976  {
4977  std::vector<_RealType> __tmp(2);
4978  __tmp[1] = _RealType(1);
4979  return __tmp;
4980  }
4981  else
4982  return _M_param._M_int;
4983  }
4984 
4985  /**
4986  * @brief Returns a vector of the probability densities.
4987  */
4989  densities() const
4990  {
4991  return _M_param._M_den.empty()
4992  ? std::vector<double>(1, 1.0) : _M_param._M_den;
4993  }
4994 
4995  /**
4996  * @brief Returns the parameter set of the distribution.
4997  */
4998  param_type
4999  param() const
5000  { return _M_param; }
5001 
5002  /**
5003  * @brief Sets the parameter set of the distribution.
5004  * @param __param The new parameter set of the distribution.
5005  */
5006  void
5007  param(const param_type& __param)
5008  { _M_param = __param; }
5009 
5010  /**
5011  * @brief Returns the greatest lower bound value of the distribution.
5012  */
5013  result_type
5014  min() const
5015  {
5016  return _M_param._M_int.empty()
5017  ? result_type(0) : _M_param._M_int.front();
5018  }
5019 
5020  /**
5021  * @brief Returns the least upper bound value of the distribution.
5022  */
5023  result_type
5024  max() const
5025  {
5026  return _M_param._M_int.empty()
5027  ? result_type(1) : _M_param._M_int.back();
5028  }
5029 
5030  /**
5031  * @brief Generating functions.
5032  */
5033  template<typename _UniformRandomNumberGenerator>
5034  result_type
5035  operator()(_UniformRandomNumberGenerator& __urng)
5036  { return this->operator()(__urng, this->param()); }
5037 
5038  template<typename _UniformRandomNumberGenerator>
5039  result_type
5040  operator()(_UniformRandomNumberGenerator& __urng,
5041  const param_type& __p);
5042 
5043  /**
5044  * @brief Inserts a %piecewise_constan_distribution random
5045  * number distribution @p __x into the output stream @p __os.
5046  *
5047  * @param __os An output stream.
5048  * @param __x A %piecewise_constan_distribution random number
5049  * distribution.
5050  *
5051  * @returns The output stream with the state of @p __x inserted or in
5052  * an error state.
5053  */
5054  template<typename _RealType1, typename _CharT, typename _Traits>
5056  operator<<(std::basic_ostream<_CharT, _Traits>&,
5058 
5059  /**
5060  * @brief Extracts a %piecewise_constan_distribution random
5061  * number distribution @p __x from the input stream @p __is.
5062  *
5063  * @param __is An input stream.
5064  * @param __x A %piecewise_constan_distribution random number
5065  * generator engine.
5066  *
5067  * @returns The input stream with @p __x extracted or in an error
5068  * state.
5069  */
5070  template<typename _RealType1, typename _CharT, typename _Traits>
5074 
5075  private:
5076  param_type _M_param;
5077  };
5078 
5079  /**
5080  * @brief Return true if two piecewise constant distributions have the
5081  * same parameters.
5082  */
5083  template<typename _RealType>
5084  inline bool
5087  { return __d1.param() == __d2.param(); }
5088 
5089  /**
5090  * @brief Return true if two piecewise constant distributions have
5091  * different parameters.
5092  */
5093  template<typename _RealType>
5094  inline bool
5097  { return !(__d1 == __d2); }
5098 
5099 
5100  /**
5101  * @brief A piecewise_linear_distribution random number distribution.
5102  *
5103  * The formula for the piecewise linear probability mass function is
5104  *
5105  */
5106  template<typename _RealType = double>
5108  {
5110  "template argument not a floating point type");
5111 
5112  public:
5113  /** The type of the range of the distribution. */
5114  typedef _RealType result_type;
5115  /** Parameter type. */
5116  struct param_type
5117  {
5119  friend class piecewise_linear_distribution<_RealType>;
5120 
5121  param_type()
5122  : _M_int(), _M_den(), _M_cp(), _M_m()
5123  { }
5124 
5125  template<typename _InputIteratorB, typename _InputIteratorW>
5126  param_type(_InputIteratorB __bfirst,
5127  _InputIteratorB __bend,
5128  _InputIteratorW __wbegin);
5129 
5130  template<typename _Func>
5131  param_type(initializer_list<_RealType> __bl, _Func __fw);
5132 
5133  template<typename _Func>
5134  param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
5135  _Func __fw);
5136 
5137  // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
5138  param_type(const param_type&) = default;
5139  param_type& operator=(const param_type&) = default;
5140 
5142  intervals() const
5143  {
5144  if (_M_int.empty())
5145  {
5146  std::vector<_RealType> __tmp(2);
5147  __tmp[1] = _RealType(1);
5148  return __tmp;
5149  }
5150  else
5151  return _M_int;
5152  }
5153 
5155  densities() const
5156  { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
5157 
5158  friend bool
5159  operator==(const param_type& __p1, const param_type& __p2)
5160  { return (__p1._M_int == __p2._M_int
5161  && __p1._M_den == __p2._M_den); }
5162 
5163  private:
5164  void
5165  _M_initialize();
5166 
5167  std::vector<_RealType> _M_int;
5168  std::vector<double> _M_den;
5169  std::vector<double> _M_cp;
5170  std::vector<double> _M_m;
5171  };
5172 
5173  explicit
5175  : _M_param()
5176  { }
5177 
5178  template<typename _InputIteratorB, typename _InputIteratorW>
5179  piecewise_linear_distribution(_InputIteratorB __bfirst,
5180  _InputIteratorB __bend,
5181  _InputIteratorW __wbegin)
5182  : _M_param(__bfirst, __bend, __wbegin)
5183  { }
5184 
5185  template<typename _Func>
5186  piecewise_linear_distribution(initializer_list<_RealType> __bl,
5187  _Func __fw)
5188  : _M_param(__bl, __fw)
5189  { }
5190 
5191  template<typename _Func>
5192  piecewise_linear_distribution(size_t __nw,
5193  _RealType __xmin, _RealType __xmax,
5194  _Func __fw)
5195  : _M_param(__nw, __xmin, __xmax, __fw)
5196  { }
5197 
5198  explicit
5199  piecewise_linear_distribution(const param_type& __p)
5200  : _M_param(__p)
5201  { }
5202 
5203  /**
5204  * Resets the distribution state.
5205  */
5206  void
5208  { }
5209 
5210  /**
5211  * @brief Return the intervals of the distribution.
5212  */
5214  intervals() const
5215  {
5216  if (_M_param._M_int.empty())
5217  {
5218  std::vector<_RealType> __tmp(2);
5219  __tmp[1] = _RealType(1);
5220  return __tmp;
5221  }
5222  else
5223  return _M_param._M_int;
5224  }
5225 
5226  /**
5227  * @brief Return a vector of the probability densities of the
5228  * distribution.
5229  */
5231  densities() const
5232  {
5233  return _M_param._M_den.empty()
5234  ? std::vector<double>(2, 1.0) : _M_param._M_den;
5235  }
5236 
5237  /**
5238  * @brief Returns the parameter set of the distribution.
5239  */
5240  param_type
5241  param() const
5242  { return _M_param; }
5243 
5244  /**
5245  * @brief Sets the parameter set of the distribution.
5246  * @param __param The new parameter set of the distribution.
5247  */
5248  void
5249  param(const param_type& __param)
5250  { _M_param = __param; }
5251 
5252  /**
5253  * @brief Returns the greatest lower bound value of the distribution.
5254  */
5255  result_type
5256  min() const
5257  {
5258  return _M_param._M_int.empty()
5259  ? result_type(0) : _M_param._M_int.front();
5260  }
5261 
5262  /**
5263  * @brief Returns the least upper bound value of the distribution.
5264  */
5265  result_type
5266  max() const
5267  {
5268  return _M_param._M_int.empty()
5269  ? result_type(1) : _M_param._M_int.back();
5270  }
5271 
5272  /**
5273  * @brief Generating functions.
5274  */
5275  template<typename _UniformRandomNumberGenerator>
5276  result_type
5277  operator()(_UniformRandomNumberGenerator& __urng)
5278  { return this->operator()(__urng, this->param()); }
5279 
5280  template<typename _UniformRandomNumberGenerator>
5281  result_type
5282  operator()(_UniformRandomNumberGenerator& __urng,
5283  const param_type& __p);
5284 
5285  /**
5286  * @brief Inserts a %piecewise_linear_distribution random number
5287  * distribution @p __x into the output stream @p __os.
5288  *
5289  * @param __os An output stream.
5290  * @param __x A %piecewise_linear_distribution random number
5291  * distribution.
5292  *
5293  * @returns The output stream with the state of @p __x inserted or in
5294  * an error state.
5295  */
5296  template<typename _RealType1, typename _CharT, typename _Traits>
5298  operator<<(std::basic_ostream<_CharT, _Traits>&,
5300 
5301  /**
5302  * @brief Extracts a %piecewise_linear_distribution random number
5303  * distribution @p __x from the input stream @p __is.
5304  *
5305  * @param __is An input stream.
5306  * @param __x A %piecewise_linear_distribution random number
5307  * generator engine.
5308  *
5309  * @returns The input stream with @p __x extracted or in an error
5310  * state.
5311  */
5312  template<typename _RealType1, typename _CharT, typename _Traits>
5316 
5317  private:
5318  param_type _M_param;
5319  };
5320 
5321  /**
5322  * @brief Return true if two piecewise linear distributions have the
5323  * same parameters.
5324  */
5325  template<typename _RealType>
5326  inline bool
5329  { return __d1.param() == __d2.param(); }
5330 
5331  /**
5332  * @brief Return true if two piecewise linear distributions have
5333  * different parameters.
5334  */
5335  template<typename _RealType>
5336  inline bool
5339  { return !(__d1 == __d2); }
5340 
5341 
5342  /* @} */ // group random_distributions_poisson
5343 
5344  /* @} */ // group random_distributions
5345 
5346  /**
5347  * @addtogroup random_utilities Random Number Utilities
5348  * @ingroup random
5349  * @{
5350  */
5351 
5352  /**
5353  * @brief The seed_seq class generates sequences of seeds for random
5354  * number generators.
5355  */
5356  class seed_seq
5357  {
5358 
5359  public:
5360  /** The type of the seed vales. */
5361  typedef uint_least32_t result_type;
5362 
5363  /** Default constructor. */
5365  : _M_v()
5366  { }
5367 
5368  template<typename _IntType>
5370 
5371  template<typename _InputIterator>
5372  seed_seq(_InputIterator __begin, _InputIterator __end);
5373 
5374  // generating functions
5375  template<typename _RandomAccessIterator>
5376  void
5377  generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
5378 
5379  // property functions
5380  size_t size() const
5381  { return _M_v.size(); }
5382 
5383  template<typename OutputIterator>
5384  void
5385  param(OutputIterator __dest) const
5386  { std::copy(_M_v.begin(), _M_v.end(), __dest); }
5387 
5388  private:
5389  ///
5391  };
5392 
5393  /* @} */ // group random_utilities
5394 
5395  /* @} */ // group random
5396 
5397 _GLIBCXX_END_NAMESPACE_VERSION
5398 } // namespace std
5399 
5400 #endif
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:5277
result_type operator()()
Gets the next value in the generated random number sequence.
Definition: random.tcc:672
void reset()
Resets the distribution state.
Definition: random.h:2031
A negative_binomial_distribution random number distribution.
Definition: random.h:3774
_RealType b() const
Return the parameter of the distribution.
Definition: random.h:4384
friend bool operator==(const shuffle_order_engine &__lhs, const shuffle_order_engine &__rhs)
Definition: random.h:1373
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:1691
unsigned int result_type
Definition: random.h:1507
_RealType alpha() const
Returns the of the distribution.
Definition: random.h:2405
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:3861
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &)
Sets the state of the engine by reading its textual representation from __is.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
Definition: random.h:1222
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:3846
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:3680
void reset()
Resets the distribution state.
Definition: random.h:3659
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
Definition: random.h:1610
uniform_real_distribution(_RealType __a=_RealType(0), _RealType __b=_RealType(1))
Constructs a uniform_real_distribution object.
Definition: random.h:1828
independent_bits_engine(const _RandomNumberEngine &__rne)
Copy constructs a independent_bits_engine engine.
Definition: random.h:1030
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:4797
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::discard_block_engine< _RandomNumberEngine1, __p1, __r1 > &)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
Definition: iosfwd:88
uint_least32_t result_type
Definition: random.h:5361
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:4574
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:3302
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:4051
normal_distribution(result_type __mean=result_type(0), result_type __stddev=result_type(1))
Definition: random.h:2017
double p() const
Returns the distribution parameter p.
Definition: random.h:3665
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::gamma_distribution< _RealType1 > &)
Extracts a gamma_distribution random number distribution __x from the input stream __is...
independent_bits_engine(_RandomNumberEngine &&__rne)
Move constructs a independent_bits_engine engine.
Definition: random.h:1040
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:3309
_RandomNumberEngine::result_type result_type
Definition: random.h:787
void reset()
Resets the distribution state.
Definition: random.h:4198
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2427
result_type operator()()
Gets the next value in the generated random number sequence.
Definition: random.tcc:729
bool empty() const
Definition: stl_vector.h:659
void reset()
Resets the distribution state.
Definition: random.h:4370
const _RandomNumberEngine & base() const
Gets a const reference to the underlying generator engine object.
Definition: random.h:1098
friend bool operator==(const std::binomial_distribution< _IntType1 > &__d1, const std::binomial_distribution< _IntType1 > &__d2)
Return true if two binomial distributions have the same parameters and the sequences that would be ge...
Definition: random.h:3532
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:3287
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:4037
_RealType mean() const
Returns the mean of the distribution.
Definition: random.h:2038
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2419
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2961
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2082
A model of a linear congruential random number generator.
Definition: random.h:170
friend bool operator==(const std::gamma_distribution< _RealType1 > &__d1, const std::gamma_distribution< _RealType1 > &__d2)
Return true if two gamma distributions have the same parameters and the sequences that would be gener...
Definition: random.h:2464
discard_block_engine(const _RandomNumberEngine &__rne)
Copy constructs a discard_block_engine engine.
Definition: random.h:812
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:3694
reference front()
Definition: stl_vector.h:764
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
Definition: random.tcc:2810
friend bool operator==(const discard_block_engine &__lhs, const discard_block_engine &__rhs)
Compares two discard_block_engine random number generator objects of the same type for equality...
Definition: random.h:934
is_floating_point
Definition: type_traits:144
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
Definition: complex:893
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:4772
iterator begin()
Definition: stl_vector.h:463
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:210
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2777
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2587
A piecewise_constant_distribution random number distribution.
Definition: random.h:4868
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:5249
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:5241
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::discrete_distribution< _IntType1 > &)
Extracts a discrete_distribution random number distribution __x from the input stream __is...
linear_congruential_engine< uint_fast32_t, 16807UL, 0UL, 2147483647UL > minstd_rand0
Definition: random.h:1449
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2946
void reset()
Resets the distribution state.
Definition: random.h:2910
void reset()
Resets the distribution state.
Definition: random.h:3825
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
Definition: random.h:1471
bitset< _Nb > operator>>(size_t __position) const
Self-explanatory.
Definition: bitset:1336
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:1888
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:4413
A normal continuous distribution for random numbers.
Definition: random.h:1972
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:5014
void seed(result_type __s)
Reseeds the discard_block_engine object with the default seed for the underlying base class generator...
Definition: random.h:865
friend bool operator==(const std::chi_squared_distribution< _RealType1 > &__d1, const std::chi_squared_distribution< _RealType1 > &__d2)
Return true if two Chi-squared distributions have the same parameters and the sequences that would be...
Definition: random.h:2629
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:4241
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
Definition: iosfwd:85
std::vector< _RealType > intervals() const
Returns a vector of the intervals.
Definition: random.h:4973
A weibull_distribution random number distribution.
Definition: random.h:4319
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s...
Definition: random.tcc:136
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:3517
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:4044
A discrete binomial random number distribution.
Definition: random.h:3399
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:3295
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:4226
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:3854
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:3672
independent_bits_engine(result_type __s)
Seed constructs a independent_bits_engine engine.
Definition: random.h:1050
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2247
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4029
A discrete Poisson random number distribution.
Definition: random.h:3957
Uniform continuous distribution for random numbers.
Definition: random.h:1782
The seed_seq class generates sequences of seeds for random number generators.
Definition: random.h:5356
result_type min() const
Returns the inclusive lower bound of the distribution range.
Definition: random.h:1698
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2579
std::vector< double > densities() const
Returns a vector of the probability densities.
Definition: random.h:4989
friend bool operator==(const independent_bits_engine &__lhs, const independent_bits_engine &__rhs)
Compares two independent_bits_engine random number generator objects of the same type for equality...
Definition: random.h:1144
bool operator!=(const std::piecewise_linear_distribution< _RealType > &__d1, const std::piecewise_linear_distribution< _RealType > &__d2)
Return true if two piecewise linear distributions have different parameters.
Definition: random.h:5337
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2074
double mean() const
Returns the distribution parameter mean.
Definition: random.h:4022
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:3702
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition: random.h:910
_RandomNumberEngine::result_type result_type
Definition: random.h:1225
friend bool operator==(const linear_congruential_engine &__lhs, const linear_congruential_engine &__rhs)
Compares two linear congruential random number generator objects of the same type for equality...
Definition: random.h:287
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2755
An exponential continuous distribution for random numbers.
Definition: random.h:4145
static constexpr _Tp max()
Definition: limits:313
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:4581
shuffle_order_engine()
Constructs a default shuffle_order_engine engine.
Definition: random.h:1238
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::normal_distribution< _RealType1 > &)
Extracts a normal_distribution random number distribution __x from the input stream __is...
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::independent_bits_engine< _RandomNumberEngine, __w, _UIntType > &__x)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
Definition: random.h:1162
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4566
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::poisson_distribution< _IntType1 > &)
Extracts a poisson_distribution random number distribution __x from the input stream __is...
A chi_squared_distribution random number distribution.
Definition: random.h:2521
A gamma continuous distribution for random numbers.
Definition: random.h:2332
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:3317
iterator end()
Definition: stl_vector.h:481
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
result_type min() const
Returns the inclusive lower bound of the distribution range.
Definition: random.h:1873
std::vector< double > probabilities() const
Returns the probabilities of the distribution.
Definition: random.h:4754
bernoulli_distribution(double __p=0.5)
Constructs a Bernoulli distribution with likelihood p.
Definition: random.h:3259
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:5256
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:1683
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2233
result_type max() const
Returns the inclusive upper bound of the distribution range.
Definition: random.h:1705
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:4406
A Bernoulli random number distribution.
Definition: random.h:3222
discard_block_engine()
Constructs a default discard_block_engine engine.
Definition: random.h:802
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2770
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:3687
One of the math functors.
Definition: stl_function.h:177
discard_block_engine(_Sseq &__q)
Generator construct a discard_block_engine engine.
Definition: random.h:845
const _RandomNumberEngine & base() const
Gets a const reference to the underlying generator engine object.
Definition: random.h:889
static constexpr result_type max()
Gets the maximum value in the generated random number range.
Definition: random.h:1112
static constexpr result_type min()
Gets the minimum value in the generated random number range.
Definition: random.h:1105
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2939
independent_bits_engine(_Sseq &__q)
Generator construct a independent_bits_engine engine.
Definition: random.h:1063
static constexpr result_type multiplier
Definition: random.h:187
exponential_distribution(const result_type &__lambda=result_type(1))
Constructs an exponential distribution with inverse scale parameter .
Definition: random.h:4183
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:3134
void reset()
Resets the distribution state.
Definition: random.h:4747
static constexpr result_type increment
Definition: random.h:189
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:4233
friend bool operator==(const std::fisher_f_distribution< _RealType1 > &__d1, const std::fisher_f_distribution< _RealType1 > &__d2)
Return true if two Fisher f distributions have the same parameters and the sequences that would be ge...
Definition: random.h:2982
void reset()
Resets the distribution state.
Definition: random.h:2565
friend bool operator==(const std::student_t_distribution< _RealType1 > &__d1, const std::student_t_distribution< _RealType1 > &__d2)
Return true if two Student t distributions have the same parameters and the sequences that would be g...
Definition: random.h:3156
discard_block_engine(result_type __s)
Seed constructs a discard_block_engine engine.
Definition: random.h:832
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2067
result_type max() const
Returns the inclusive upper bound of the distribution range.
Definition: random.h:1880
_IntType k() const
Return the parameter of the distribution.
Definition: random.h:3832
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:3495
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:4779
shuffle_order_engine(result_type __s)
Seed constructs a shuffle_order_engine engine.
Definition: random.h:1271
void seed(result_type __s)
Reseeds the shuffle_order_engine object with the default seed for the underlying base class generator...
Definition: random.h:1305
initializer_list
linear_congruential_engine(_Sseq &__q)
Constructs a linear_congruential_engine random number generator engine seeded from the seed sequence ...
Definition: random.h:215
double p() const
Return the parameter of the distribution.
Definition: random.h:3839
A cauchy_distribution random number distribution.
Definition: random.h:2686
void reset()
Resets the distribution state.
Definition: random.h:1844
void reset()
Resets the distribution state.
Definition: random.h:1669
A extreme_value_distribution random number distribution.
Definition: random.h:4494
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::negative_binomial_distribution< _IntType1 > &)
Extracts a negative_binomial_distribution random number distribution __x from the input stream __is...
static constexpr result_type min()
Gets the minimum value in the generated random number range.
Definition: random.h:896
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:3868
mersenne_twister_engine< uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, 17, 0x71d67fffeda60000ULL, 37, 0xfff7eee000000000ULL, 43, 6364136223846793005ULL > mt19937_64
Definition: random.h:1483
_RealType result_type
Definition: random.h:2335
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition: random.h:1119
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:5024
is_unsigned
Definition: type_traits:615
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2449
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:1713
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2434
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:3487
void seed()
Reseeds the shuffle_order_engine object with the default seed for the underlying base class generator...
Definition: random.h:1294
void seed(_Sseq &__q)
Reseeds the independent_bits_engine object with the given seed sequence.
Definition: random.h:1090
reference back()
Definition: stl_vector.h:780
shuffle_order_engine(const _RandomNumberEngine &__rne)
Copy constructs a shuffle_order_engine engine.
Definition: random.h:1249
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:5035
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::shuffle_order_engine< _RandomNumberEngine1, __k1 > &)
Extracts the current state of a % subtract_with_carry_engine random number generator engine __x from ...
void reset()
Resets the distribution state.
Definition: random.h:4015
gamma_distribution(_RealType __alpha_val=_RealType(1), _RealType __beta_val=_RealType(1))
Constructs a gamma distribution with parameters and .
Definition: random.h:2384
shuffle_order_engine(_Sseq &__q)
Generator construct a shuffle_order_engine engine.
Definition: random.h:1285
void reset()
Resets the distribution state.
Definition: random.h:4966
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:3112
_RealType beta() const
Returns the of the distribution.
Definition: random.h:2412
_RealType stddev() const
Returns the standard deviation of the distribution.
Definition: random.h:2045
std::vector< _RealType > intervals() const
Return the intervals of the distribution.
Definition: random.h:5214
A student_t_distribution random number distribution.
Definition: random.h:3043
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:3509
void reset()
Resets the distribution state.
Definition: random.h:3087
double p() const
Returns the p parameter of the distribution.
Definition: random.h:3280
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2601
void reset()
Resets the distribution state.
Definition: random.h:3274
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::piecewise_linear_distribution< _RealType1 > &)
Extracts a piecewise_linear_distribution random number distribution __x from the input stream __is...
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2225
void reset()
Resets the distribution state.
Definition: random.h:2398
A lognormal_distribution random number distribution.
Definition: random.h:2156
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::student_t_distribution< _RealType1 > &)
Extracts a student_t_distribution random number distribution __x from the input stream __is...
void discard(unsigned long long __z)
Discard a sequence of random numbers.
Definition: random.h:259
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4999
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:3126
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2594
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:4786
void seed(_Sseq &__q)
Reseeds the discard_block_engine object with the given seed sequence.
Definition: random.h:878
static constexpr result_type min()
Definition: random.h:1335
is_integral
Definition: type_traits:130
size_type size() const
Definition: stl_vector.h:570
void reset()
Resets the distribution state.
Definition: random.h:2737
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4391
friend bool operator==(const std::negative_binomial_distribution< _IntType1 > &__d1, const std::negative_binomial_distribution< _IntType1 > &__d2)
Return true if two negative binomial distributions have the same parameters and the sequences that wo...
Definition: random.h:3890
is_same
Definition: type_traits:406
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2052
void discard(unsigned long long __z)
Definition: random.h:1349
_RealType a() const
Return the parameter of the distribution.
Definition: random.h:4552
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:4588
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::piecewise_constant_distribution< _RealType1 > &)
Extracts a piecewise_constan_distribution random number distribution __x from the input stream __is...
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:187
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2785
enable_if
Definition: type_traits:836
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:5007
void seed(_Sseq &__q)
Reseeds the shuffle_order_engine object with the given seed sequence.
Definition: random.h:1318
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:4399
Properties of fundamental types.
Definition: limits:304
_IntType t() const
Returns the distribution t parameter.
Definition: random.h:3473
friend bool operator==(const std::poisson_distribution< _IntType1 > &__d1, const std::poisson_distribution< _IntType1 > &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
Definition: random.h:4074
void seed(result_type __s)
Reseeds the independent_bits_engine object with the default seed for the underlying base class genera...
Definition: random.h:1080
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4211
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:4421
_RealType b() const
Return the parameter of the distribution.
Definition: random.h:4559
static constexpr result_type max()
Gets the largest possible value in the output range.
Definition: random.h:252
bool operator==(const std::piecewise_linear_distribution< _RealType > &__d1, const std::piecewise_linear_distribution< _RealType > &__d2)
Return true if two piecewise linear distributions have the same parameters.
Definition: random.h:5327
const _CharT * c_str() const
Return const pointer to null-terminated contents.
static constexpr _Tp min()
Definition: limits:309
__gnu_cxx::__promote_2< _Tpx, _Tpy >::__type beta(_Tpx __x, _Tpy __y)
5.2.1.3 Beta functions.
Definition: tr1/cmath:1133
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:4596
linear_congruential_engine(result_type __s=default_seed)
Constructs a linear_congruential_engine random number generator engine with seed __s. The default seed value is 1.
Definition: random.h:202
void reset()
Resets the distribution state.
Definition: random.h:4545
shuffle_order_engine(_RandomNumberEngine &&__rne)
Move constructs a shuffle_order_engine engine.
Definition: random.h:1260
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::binomial_distribution< _IntType1 > &)
Extracts a binomial_distribution random number distribution __x from the input stream __is...
A discrete_distribution random number distribution.
Definition: random.h:4666
void seed()
Reseeds the discard_block_engine object with the default seed for the underlying base class generator...
Definition: random.h:854
independent_bits_engine()
Constructs a default independent_bits_engine engine.
Definition: random.h:1020
void reset()
Resets the distribution state.
Definition: random.h:3466
double p() const
Returns the distribution p parameter.
Definition: random.h:3480
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::lognormal_distribution< _RealType1 > &)
Extracts a lognormal_distribution random number distribution __x from the input stream __is...
A piecewise_linear_distribution random number distribution.
Definition: random.h:5107
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2060
A discrete geometric random number distribution.
Definition: random.h:3601
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:3502
static constexpr result_type max()
Gets the maximum value in the generated random number range.
Definition: random.h:903
std::vector< double > densities() const
Return a vector of the probability densities of the distribution.
Definition: random.h:5231
A fisher_f_distribution random number distribution.
Definition: random.h:2859
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:5266
friend bool operator==(const std::lognormal_distribution< _RealType1 > &__d1, const std::lognormal_distribution< _RealType1 > &__d2)
Return true if two lognormal distributions have the same parameters and the sequences that would be g...
Definition: random.h:2271
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2953
result_type operator()()
Definition: random.tcc:777
static constexpr result_type max()
Definition: random.h:1342
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:2240
result_type min() const
Returns the greatest lower bound value of the distribution.
Definition: random.h:3119
friend bool operator==(const std::normal_distribution< _RealType1 > &__d1, const std::normal_distribution< _RealType1 > &__d2)
Return true if two normal distributions have the same parameters and the sequences that would be gene...
const _RandomNumberEngine & base() const
Definition: random.h:1328
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
Definition: complex:757
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:3104
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
Definition: complex:784
result_type max() const
Returns the least upper bound value of the distribution.
Definition: random.h:2441
linear_congruential_engine< uint_fast32_t, 48271UL, 0UL, 2147483647UL > minstd_rand
Definition: random.h:1455
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::fisher_f_distribution< _RealType1 > &)
Extracts a fisher_f_distribution random number distribution __x from the input stream __is...
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:1866
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2609
_RealType lambda() const
Returns the inverse scale parameter of the distribution.
Definition: random.h:4204
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:2763
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:4764
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:2931
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:2255
void seed()
Reseeds the independent_bits_engine object with the default seed for the underlying base class genera...
Definition: random.h:1072
result_type operator()()
Gets the next random number in the sequence.
Definition: random.h:269
void param(const param_type &__param)
Sets the parameter set of the distribution.
Definition: random.h:4219
static constexpr result_type min()
Gets the smallest possible value in the output range.
Definition: random.h:245
_RealType a() const
Return the parameter of the distribution.
Definition: random.h:4377
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::chi_squared_distribution< _RealType1 > &)
Extracts a chi_squared_distribution random number distribution __x from the input stream __is...
uniform_int_distribution(_IntType __a=0, _IntType __b=std::numeric_limits< _IntType >::max())
Constructs a uniform distribution object.
Definition: random.h:1653
discard_block_engine(_RandomNumberEngine &&__rne)
Move constructs a discard_block_engine engine.
Definition: random.h:822
param_type param() const
Returns the parameter set of the distribution.
Definition: random.h:1858
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Definition: random.h:4059