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