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