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