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