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