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