- tmp/tmpna0gkhta/{from.md → to.md} +453 -164
tmp/tmpna0gkhta/{from.md → to.md}
RENAMED
|
@@ -49,65 +49,94 @@ conventional bitwise operations. Further:
|
|
| 49 |
#include <initializer_list> // see [initializer.list.syn]
|
| 50 |
|
| 51 |
namespace std {
|
| 52 |
// [rand.req.urng], uniform random bit generator requirements
|
| 53 |
template<class G>
|
| 54 |
-
concept uniform_random_bit_generator = see below;
|
| 55 |
|
| 56 |
// [rand.eng.lcong], class template linear_congruential_engine
|
| 57 |
template<class UIntType, UIntType a, UIntType c, UIntType m>
|
| 58 |
-
class linear_congruential_engine;
|
| 59 |
|
| 60 |
// [rand.eng.mers], class template mersenne_twister_engine
|
| 61 |
template<class UIntType, size_t w, size_t n, size_t m, size_t r,
|
| 62 |
UIntType a, size_t u, UIntType d, size_t s,
|
| 63 |
UIntType b, size_t t,
|
| 64 |
UIntType c, size_t l, UIntType f>
|
| 65 |
class mersenne_twister_engine;
|
| 66 |
|
| 67 |
// [rand.eng.sub], class template subtract_with_carry_engine
|
| 68 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 69 |
-
class subtract_with_carry_engine;
|
| 70 |
|
| 71 |
// [rand.adapt.disc], class template discard_block_engine
|
| 72 |
template<class Engine, size_t p, size_t r>
|
| 73 |
-
class discard_block_engine;
|
| 74 |
|
| 75 |
// [rand.adapt.ibits], class template independent_bits_engine
|
| 76 |
template<class Engine, size_t w, class UIntType>
|
| 77 |
-
class independent_bits_engine;
|
| 78 |
|
| 79 |
// [rand.adapt.shuf], class template shuffle_order_engine
|
| 80 |
template<class Engine, size_t k>
|
| 81 |
class shuffle_order_engine;
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
// [rand.predef], engines and engine adaptors with predefined parameters
|
| 84 |
-
using minstd_rand0 = see below;
|
| 85 |
-
using minstd_rand = see below;
|
| 86 |
-
using mt19937 = see below;
|
| 87 |
-
using mt19937_64 = see below;
|
| 88 |
-
using ranlux24_base = see below;
|
| 89 |
-
using ranlux48_base = see below;
|
| 90 |
-
using ranlux24 = see below;
|
| 91 |
-
using ranlux48 = see below;
|
| 92 |
using knuth_b = see below;
|
|
|
|
|
|
|
| 93 |
|
| 94 |
using default_random_engine = see below;
|
| 95 |
|
| 96 |
// [rand.device], class random_device
|
| 97 |
class random_device;
|
| 98 |
|
| 99 |
// [rand.util.seedseq], class seed_seq
|
| 100 |
class seed_seq;
|
| 101 |
|
| 102 |
// [rand.util.canonical], function template generate_canonical
|
| 103 |
-
template<class RealType, size_t
|
| 104 |
RealType generate_canonical(URBG& g);
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
// [rand.dist.uni.int], class template uniform_int_distribution
|
| 107 |
template<class IntType = int>
|
| 108 |
-
class uniform_int_distribution;
|
| 109 |
|
| 110 |
// [rand.dist.uni.real], class template uniform_real_distribution
|
| 111 |
template<class RealType = double>
|
| 112 |
class uniform_real_distribution;
|
| 113 |
|
|
@@ -186,12 +215,11 @@ namespace std {
|
|
| 186 |
|
| 187 |
### Requirements <a id="rand.req">[[rand.req]]</a>
|
| 188 |
|
| 189 |
#### General requirements <a id="rand.req.genl">[[rand.req.genl]]</a>
|
| 190 |
|
| 191 |
-
Throughout
|
| 192 |
-
template:
|
| 193 |
|
| 194 |
- that has a template type parameter named `Sseq` is undefined unless
|
| 195 |
the corresponding template argument is cv-unqualified and meets the
|
| 196 |
requirements of seed sequence [[rand.req.seedseq]].
|
| 197 |
- that has a template type parameter named `URBG` is undefined unless
|
|
@@ -210,18 +238,18 @@ template:
|
|
| 210 |
- that has a template type parameter named `UIntType` is undefined
|
| 211 |
unless the corresponding template argument is cv-unqualified and is
|
| 212 |
one of `unsigned short`, `unsigned int`, `unsigned long`, or
|
| 213 |
`unsigned long long`.
|
| 214 |
|
| 215 |
-
Throughout
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
|
| 220 |
-
Throughout
|
| 221 |
-
|
| 222 |
-
|
| 223 |
|
| 224 |
#### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
|
| 225 |
|
| 226 |
A *seed sequence* is an object that consumes a sequence of
|
| 227 |
integer-valued data and produces a requested number of unsigned integer
|
|
@@ -232,12 +260,12 @@ streams of random variates. This can be useful, for example, in
|
|
| 232 |
applications requiring large numbers of random number
|
| 233 |
engines. — *end note*]
|
| 234 |
|
| 235 |
A class `S` meets the requirements of a seed sequence if the expressions
|
| 236 |
shown in [[rand.req.seedseq]] are valid and have the indicated
|
| 237 |
-
semantics, and if `S` also meets all other requirements of
|
| 238 |
-
|
| 239 |
subclause:
|
| 240 |
|
| 241 |
- `T` is the type named by `S`’s associated `result_type`;
|
| 242 |
- `q` is a value of type `S` and `r` is a value of type `S` or
|
| 243 |
`const S`;
|
|
@@ -304,12 +332,12 @@ suitable `operator>>`.
|
|
| 304 |
|
| 305 |
A class `E` that meets the requirements of a uniform random bit
|
| 306 |
generator [[rand.req.urng]] also meets the requirements of a *random
|
| 307 |
number engine* if the expressions shown in [[rand.req.eng]] are valid
|
| 308 |
and have the indicated semantics, and if `E` also meets all other
|
| 309 |
-
requirements of
|
| 310 |
-
|
| 311 |
|
| 312 |
- `T` is the type named by `E`’s associated `result_type`;
|
| 313 |
- `e` is a value of `E`, `v` is an lvalue of `E`, `x` and `y` are
|
| 314 |
(possibly const) values of `E`;
|
| 315 |
- `s` is a value of `T`;
|
|
@@ -327,10 +355,56 @@ where `charT` and `traits` are constrained according to [[strings]] and
|
|
| 327 |
`E` shall meet the *Cpp17CopyConstructible* (
|
| 328 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 329 |
[[cpp17.copyassignable]]) requirements. These operations shall each be
|
| 330 |
of complexity no worse than 𝑂(\text{size of state}).
|
| 331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
#### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
|
| 333 |
|
| 334 |
A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
|
| 335 |
of type `A` is a random number engine that takes values produced by some
|
| 336 |
other random number engine, and applies an algorithm to those values in
|
|
@@ -415,12 +489,12 @@ P(zᵢ |{`p`}), to denote a distribution’s parameters `p` taken as a
|
|
| 415 |
whole.
|
| 416 |
|
| 417 |
A class `D` meets the requirements of a *random number distribution* if
|
| 418 |
the expressions shown in [[rand.req.dist]] are valid and have the
|
| 419 |
indicated semantics, and if `D` and its associated types also meet all
|
| 420 |
-
other requirements of
|
| 421 |
-
|
| 422 |
|
| 423 |
- `T` is the type named by `D`’s associated `result_type`;
|
| 424 |
- `P` is the type named by `D`’s associated `param_type`;
|
| 425 |
- `d` is a value of `D`, and `x` and `y` are (possibly const) values of
|
| 426 |
`D`;
|
|
@@ -452,13 +526,12 @@ representation is restored into the same or a different object `y` of
|
|
| 452 |
the same type using `is >> y`, repeated invocations of `y(g)` shall
|
| 453 |
produce the same sequence of numbers as would repeated invocations of
|
| 454 |
`x(g)`.
|
| 455 |
|
| 456 |
It is unspecified whether `D::param_type` is declared as a (nested)
|
| 457 |
-
`class` or via a `typedef`. In
|
| 458 |
-
|
| 459 |
-
exposition only.
|
| 460 |
|
| 461 |
`P` shall meet the *Cpp17CopyConstructible* (
|
| 462 |
[[cpp17.copyconstructible]]), *Cpp17CopyAssignable* (
|
| 463 |
[[cpp17.copyassignable]]), and *Cpp17EqualityComparable* (
|
| 464 |
[[cpp17.equalitycomparable]]) requirements.
|
|
@@ -475,10 +548,46 @@ the identical name, type, and semantics.
|
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
using distribution_type = D;
|
| 478 |
```
|
| 479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
|
| 481 |
|
| 482 |
#### General <a id="rand.eng.general">[[rand.eng.general]]</a>
|
| 483 |
|
| 484 |
Each type instantiated from a class template specified in [[rand.eng]]
|
|
@@ -500,11 +609,11 @@ that are not described in [[rand.req.eng]] or for operations where there
|
|
| 500 |
is additional semantic information. In particular, declarations for copy
|
| 501 |
constructors, for copy assignment operators, for streaming operators,
|
| 502 |
and for equality and inequality operators are not shown in the synopses.
|
| 503 |
|
| 504 |
Each template specified in [[rand.eng]] requires one or more
|
| 505 |
-
relationships, involving the value(s) of its
|
| 506 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 507 |
ill-formed if any such required relationship fails to hold.
|
| 508 |
|
| 509 |
For every random number engine and for every random number engine
|
| 510 |
adaptor `X` defined in [[rand.eng]] and in [[rand.adapt]]:
|
|
@@ -570,21 +679,22 @@ namespace std {
|
|
| 570 |
void discard(unsigned long long z);
|
| 571 |
|
| 572 |
// inserters and extractors
|
| 573 |
template<class charT, class traits>
|
| 574 |
friend basic_ostream<charT, traits>&
|
| 575 |
-
operator<<(basic_ostream<charT, traits>& os,
|
|
|
|
| 576 |
template<class charT, class traits>
|
| 577 |
friend basic_istream<charT, traits>&
|
| 578 |
-
operator>>(basic_istream<charT, traits>& is,
|
|
|
|
| 579 |
};
|
| 580 |
}
|
| 581 |
```
|
| 582 |
|
| 583 |
-
If the template parameter `m` is 0, the modulus m used throughout
|
| 584 |
-
|
| 585 |
-
plus 1.
|
| 586 |
|
| 587 |
[*Note 1*: m need not be representable as a value of type
|
| 588 |
`result_type`. — *end note*]
|
| 589 |
|
| 590 |
If the template parameter `m` is not 0, the following relations shall
|
|
@@ -688,14 +798,16 @@ namespace std {
|
|
| 688 |
void discard(unsigned long long z);
|
| 689 |
|
| 690 |
// inserters and extractors
|
| 691 |
template<class charT, class traits>
|
| 692 |
friend basic_ostream<charT, traits>&
|
| 693 |
-
operator<<(basic_ostream<charT, traits>& os,
|
|
|
|
| 694 |
template<class charT, class traits>
|
| 695 |
friend basic_istream<charT, traits>&
|
| 696 |
-
operator>>(basic_istream<charT, traits>& is,
|
|
|
|
| 697 |
};
|
| 698 |
}
|
| 699 |
```
|
| 700 |
|
| 701 |
The following relations shall hold: `0 < m`, `m <= n`, `2u < w`,
|
|
@@ -768,17 +880,17 @@ namespace std {
|
|
| 768 |
static constexpr size_t word_size = w;
|
| 769 |
static constexpr size_t short_lag = s;
|
| 770 |
static constexpr size_t long_lag = r;
|
| 771 |
static constexpr result_type min() { return 0; }
|
| 772 |
static constexpr result_type max() { return m - 1; }
|
| 773 |
-
static constexpr
|
| 774 |
|
| 775 |
// constructors and seeding functions
|
| 776 |
-
subtract_with_carry_engine() : subtract_with_carry_engine(
|
| 777 |
explicit subtract_with_carry_engine(result_type value);
|
| 778 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 779 |
-
void seed(result_type value =
|
| 780 |
template<class Sseq> void seed(Sseq& q);
|
| 781 |
|
| 782 |
// equality operators
|
| 783 |
friend bool operator==(const subtract_with_carry_engine& x,
|
| 784 |
const subtract_with_carry_engine& y);
|
|
@@ -788,14 +900,16 @@ namespace std {
|
|
| 788 |
void discard(unsigned long long z);
|
| 789 |
|
| 790 |
// inserters and extractors
|
| 791 |
template<class charT, class traits>
|
| 792 |
friend basic_ostream<charT, traits>&
|
| 793 |
-
operator<<(basic_ostream<charT, traits>& os,
|
|
|
|
| 794 |
template<class charT, class traits>
|
| 795 |
friend basic_istream<charT, traits>&
|
| 796 |
-
operator>>(basic_istream<charT, traits>& is,
|
|
|
|
| 797 |
};
|
| 798 |
}
|
| 799 |
```
|
| 800 |
|
| 801 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
|
@@ -813,12 +927,12 @@ below. If X₋₁ is then 0, sets c to 1; otherwise sets c to 0.
|
|
| 813 |
|
| 814 |
To set the values Xₖ, first construct `e`, a
|
| 815 |
`linear_congruential_engine` object, as if by the following definition:
|
| 816 |
|
| 817 |
``` cpp
|
| 818 |
-
linear_congruential_engine<
|
| 819 |
-
|
| 820 |
```
|
| 821 |
|
| 822 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 823 |
successive invocations of `e`. Set Xₖ to
|
| 824 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
|
@@ -833,38 +947,207 @@ template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
|
| 833 |
r ⋅ k, invokes `q.generate(`a + 0`, `a + r ⋅ k`)` and then, iteratively
|
| 834 |
for i = -r, …, -1, sets Xᵢ to
|
| 835 |
$\left(\sum_{j=0}^{k-1}a_{k(i+r)+j} \cdot 2^{32j} \right) \bmod m$. If
|
| 836 |
X₋₁ is then 0, sets c to 1; otherwise sets c to 0.
|
| 837 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
|
| 839 |
|
| 840 |
-
####
|
| 841 |
|
| 842 |
-
Each type instantiated from a class template specified in
|
| 843 |
-
|
| 844 |
-
|
| 845 |
|
| 846 |
Except where specified otherwise, the complexity of each function
|
| 847 |
-
specified in
|
| 848 |
|
| 849 |
-
Except where specified otherwise, no function described in
|
| 850 |
-
|
| 851 |
|
| 852 |
-
Every function described in
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
|
| 857 |
-
Descriptions are provided in
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
|
| 864 |
-
Each template specified in
|
| 865 |
-
|
| 866 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 867 |
ill-formed if any such required relationship fails to hold.
|
| 868 |
|
| 869 |
#### Class template `discard_block_engine` <a id="rand.adapt.disc">[[rand.adapt.disc]]</a>
|
| 870 |
|
|
@@ -887,11 +1170,11 @@ invocation of `e()` while advancing `e`’s state as described above.
|
|
| 887 |
namespace std {
|
| 888 |
template<class Engine, size_t p, size_t r>
|
| 889 |
class discard_block_engine {
|
| 890 |
public:
|
| 891 |
// types
|
| 892 |
-
using result_type =
|
| 893 |
|
| 894 |
// engine characteristics
|
| 895 |
static constexpr size_t block_size = p;
|
| 896 |
static constexpr size_t used_block = r;
|
| 897 |
static constexpr result_type min() { return Engine::min(); }
|
|
@@ -918,14 +1201,14 @@ namespace std {
|
|
| 918 |
const Engine& base() const noexcept { return e; }
|
| 919 |
|
| 920 |
// inserters and extractors
|
| 921 |
template<class charT, class traits>
|
| 922 |
friend basic_ostream<charT, traits>&
|
| 923 |
-
operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x);
|
| 924 |
template<class charT, class traits>
|
| 925 |
friend basic_istream<charT, traits>&
|
| 926 |
-
operator>>(basic_istream<charT, traits>& is, discard_block_engine& x);
|
| 927 |
|
| 928 |
private:
|
| 929 |
Engine e; // exposition only
|
| 930 |
size_t n; // exposition only
|
| 931 |
};
|
|
@@ -981,10 +1264,11 @@ for (k = n₀; k \neq n; k += 1) {
|
|
| 981 |
S = 2^{w₀ + 1} \cdot S + u \bmod 2^{w₀ + 1};
|
| 982 |
}
|
| 983 |
```
|
| 984 |
|
| 985 |
``` cpp
|
|
|
|
| 986 |
template<class Engine, size_t w, class UIntType>
|
| 987 |
class independent_bits_engine {
|
| 988 |
public:
|
| 989 |
// types
|
| 990 |
using result_type = UIntType;
|
|
@@ -1014,18 +1298,19 @@ template<class Engine, size_t w, class UIntType>
|
|
| 1014 |
const Engine& base() const noexcept { return e; }
|
| 1015 |
|
| 1016 |
// inserters and extractors
|
| 1017 |
template<class charT, class traits>
|
| 1018 |
friend basic_ostream<charT, traits>&
|
| 1019 |
-
operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x);
|
| 1020 |
template<class charT, class traits>
|
| 1021 |
friend basic_istream<charT, traits>&
|
| 1022 |
-
operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x);
|
| 1023 |
|
| 1024 |
private:
|
| 1025 |
Engine e; // exposition only
|
| 1026 |
};
|
|
|
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
The following relations shall hold: `0 < w` and
|
| 1030 |
`w <= numeric_limits<result_type>::digits`.
|
| 1031 |
|
|
@@ -1057,11 +1342,11 @@ advancing `e`’s state as described above.
|
|
| 1057 |
namespace std {
|
| 1058 |
template<class Engine, size_t k>
|
| 1059 |
class shuffle_order_engine {
|
| 1060 |
public:
|
| 1061 |
// types
|
| 1062 |
-
using result_type =
|
| 1063 |
|
| 1064 |
// engine characteristics
|
| 1065 |
static constexpr size_t table_size = k;
|
| 1066 |
static constexpr result_type min() { return Engine::min(); }
|
| 1067 |
static constexpr result_type max() { return Engine::max(); }
|
|
@@ -1208,10 +1493,30 @@ provide at least acceptable engine behavior for relatively casual,
|
|
| 1208 |
inexpert, and/or lightweight use. Because different implementations can
|
| 1209 |
select different underlying engine types, code that uses this `typedef`
|
| 1210 |
need not generate identical sequences across
|
| 1211 |
implementations. — *end note*]
|
| 1212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1213 |
### Class `random_device` <a id="rand.device">[[rand.device]]</a>
|
| 1214 |
|
| 1215 |
A `random_device` uniform random bit generator produces nondeterministic
|
| 1216 |
random numbers.
|
| 1217 |
|
|
@@ -1439,52 +1744,64 @@ copy(v.begin(), v.end(), dest);
|
|
| 1439 |
*Throws:* What and when `OutputIterator` operations of `dest` throw.
|
| 1440 |
|
| 1441 |
#### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
|
| 1442 |
|
| 1443 |
``` cpp
|
| 1444 |
-
template<class RealType, size_t
|
| 1445 |
RealType generate_canonical(URBG& g);
|
| 1446 |
```
|
| 1447 |
|
| 1448 |
-
|
| 1449 |
-
respectively. Calculates a quantity
|
| 1450 |
-
$$S = \sum_{i=0}^{k-1} (g_i - \texttt{g.min()})
|
| 1451 |
-
\cdot R^i$$ using arithmetic of type `RealType`.
|
| 1452 |
|
| 1453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1454 |
|
| 1455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1456 |
|
| 1457 |
*Throws:* What and when `g` throws.
|
| 1458 |
|
| 1459 |
-
*Complexity:* Exactly k
|
| 1460 |
-
where b[^6]
|
| 1461 |
|
| 1462 |
-
|
| 1463 |
-
the value of `g.max()` - `g.min()` + 1.
|
| 1464 |
-
|
| 1465 |
-
[*Note 2*: If the values gᵢ produced by `g` are uniformly distributed,
|
| 1466 |
the instantiation’s results are distributed as uniformly as possible.
|
| 1467 |
Obtaining a value in this way can be a useful step in the process of
|
| 1468 |
transforming a value generated by a uniform random bit generator into a
|
| 1469 |
value that can be delivered by a random number
|
| 1470 |
distribution. — *end note*]
|
| 1471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1472 |
### Random number distribution class templates <a id="rand.dist">[[rand.dist]]</a>
|
| 1473 |
|
| 1474 |
-
####
|
| 1475 |
|
| 1476 |
-
Each type instantiated from a class template specified in
|
| 1477 |
-
|
| 1478 |
-
|
| 1479 |
|
| 1480 |
-
Descriptions are provided in
|
| 1481 |
-
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
|
| 1487 |
The algorithms for producing each of the specified distributions are
|
| 1488 |
*implementation-defined*.
|
| 1489 |
|
| 1490 |
The value of each probability density function p(z) and of each discrete
|
|
@@ -1495,11 +1812,11 @@ outside its stated domain.
|
|
| 1495 |
|
| 1496 |
##### Class template `uniform_int_distribution` <a id="rand.dist.uni.int">[[rand.dist.uni.int]]</a>
|
| 1497 |
|
| 1498 |
A `uniform_int_distribution` random number distribution produces random
|
| 1499 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 1500 |
-
probability function
|
| 1501 |
|
| 1502 |
``` cpp
|
| 1503 |
namespace std {
|
| 1504 |
template<class IntType = int>
|
| 1505 |
class uniform_int_distribution {
|
|
@@ -1532,14 +1849,16 @@ namespace std {
|
|
| 1532 |
result_type max() const;
|
| 1533 |
|
| 1534 |
// inserters and extractors
|
| 1535 |
template<class charT, class traits>
|
| 1536 |
friend basic_ostream<charT, traits>&
|
| 1537 |
-
operator<<(basic_ostream<charT, traits>& os,
|
|
|
|
| 1538 |
template<class charT, class traits>
|
| 1539 |
friend basic_istream<charT, traits>&
|
| 1540 |
-
operator>>(basic_istream<charT, traits>& is,
|
|
|
|
| 1541 |
};
|
| 1542 |
}
|
| 1543 |
```
|
| 1544 |
|
| 1545 |
``` cpp
|
|
@@ -1567,11 +1886,11 @@ constructed.
|
|
| 1567 |
|
| 1568 |
##### Class template `uniform_real_distribution` <a id="rand.dist.uni.real">[[rand.dist.uni.real]]</a>
|
| 1569 |
|
| 1570 |
A `uniform_real_distribution` random number distribution produces random
|
| 1571 |
numbers x, a ≤ x < b, distributed according to the constant probability
|
| 1572 |
-
density function
|
| 1573 |
|
| 1574 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 1575 |
`a == b`. — *end note*]
|
| 1576 |
|
| 1577 |
``` cpp
|
|
@@ -1645,15 +1964,11 @@ constructed.
|
|
| 1645 |
#### Bernoulli distributions <a id="rand.dist.bern">[[rand.dist.bern]]</a>
|
| 1646 |
|
| 1647 |
##### Class `bernoulli_distribution` <a id="rand.dist.bern.bernoulli">[[rand.dist.bern.bernoulli]]</a>
|
| 1648 |
|
| 1649 |
A `bernoulli_distribution` random number distribution produces `bool`
|
| 1650 |
-
values b distributed according to the discrete probability function
|
| 1651 |
-
$$P(b\,|\,p) = \left\{ \begin{array}{ll}
|
| 1652 |
-
p & \text{ if $b = \tcode{true}$, or} \\
|
| 1653 |
-
1 - p & \text{ if $b = \tcode{false}$.}
|
| 1654 |
-
\end{array}\right.$$
|
| 1655 |
|
| 1656 |
``` cpp
|
| 1657 |
namespace std {
|
| 1658 |
class bernoulli_distribution {
|
| 1659 |
public:
|
|
@@ -1711,11 +2026,11 @@ constructed.
|
|
| 1711 |
|
| 1712 |
##### Class template `binomial_distribution` <a id="rand.dist.bern.bin">[[rand.dist.bern.bin]]</a>
|
| 1713 |
|
| 1714 |
A `binomial_distribution` random number distribution produces integer
|
| 1715 |
values i ≥ 0 distributed according to the discrete probability function
|
| 1716 |
-
|
| 1717 |
|
| 1718 |
``` cpp
|
| 1719 |
namespace std {
|
| 1720 |
template<class IntType = int>
|
| 1721 |
class binomial_distribution {
|
|
@@ -1783,11 +2098,11 @@ constructed.
|
|
| 1783 |
|
| 1784 |
##### Class template `geometric_distribution` <a id="rand.dist.bern.geo">[[rand.dist.bern.geo]]</a>
|
| 1785 |
|
| 1786 |
A `geometric_distribution` random number distribution produces integer
|
| 1787 |
values i ≥ 0 distributed according to the discrete probability function
|
| 1788 |
-
|
| 1789 |
|
| 1790 |
``` cpp
|
| 1791 |
namespace std {
|
| 1792 |
template<class IntType = int>
|
| 1793 |
class geometric_distribution {
|
|
@@ -1846,12 +2161,11 @@ constructed.
|
|
| 1846 |
|
| 1847 |
##### Class template `negative_binomial_distribution` <a id="rand.dist.bern.negbin">[[rand.dist.bern.negbin]]</a>
|
| 1848 |
|
| 1849 |
A `negative_binomial_distribution` random number distribution produces
|
| 1850 |
random integers i ≥ 0 distributed according to the discrete probability
|
| 1851 |
-
function
|
| 1852 |
-
$$P(i\,|\,k,p) = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i \text{ .}$$
|
| 1853 |
|
| 1854 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 1855 |
`p == 1`. — *end note*]
|
| 1856 |
|
| 1857 |
``` cpp
|
|
@@ -1925,17 +2239,19 @@ constructed.
|
|
| 1925 |
|
| 1926 |
##### Class template `poisson_distribution` <a id="rand.dist.pois.poisson">[[rand.dist.pois.poisson]]</a>
|
| 1927 |
|
| 1928 |
A `poisson_distribution` random number distribution produces integer
|
| 1929 |
values i ≥ 0 distributed according to the discrete probability function
|
| 1930 |
-
|
| 1931 |
-
|
|
|
|
|
|
|
| 1932 |
|
| 1933 |
``` cpp
|
|
|
|
| 1934 |
template<class IntType = int>
|
| 1935 |
-
class poisson_distribution
|
| 1936 |
-
{
|
| 1937 |
public:
|
| 1938 |
// types
|
| 1939 |
using result_type = IntType;
|
| 1940 |
using param_type = unspecified;
|
| 1941 |
|
|
@@ -1967,10 +2283,11 @@ template<class IntType = int>
|
|
| 1967 |
operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x);
|
| 1968 |
template<class charT, class traits>
|
| 1969 |
friend basic_istream<charT, traits>&
|
| 1970 |
operator>>(basic_istream<charT, traits>& is, poisson_distribution& x);
|
| 1971 |
};
|
|
|
|
| 1972 |
```
|
| 1973 |
|
| 1974 |
``` cpp
|
| 1975 |
explicit poisson_distribution(double mean);
|
| 1976 |
```
|
|
@@ -1988,11 +2305,11 @@ constructed.
|
|
| 1988 |
|
| 1989 |
##### Class template `exponential_distribution` <a id="rand.dist.pois.exp">[[rand.dist.pois.exp]]</a>
|
| 1990 |
|
| 1991 |
An `exponential_distribution` random number distribution produces random
|
| 1992 |
numbers x > 0 distributed according to the probability density function
|
| 1993 |
-
|
| 1994 |
|
| 1995 |
``` cpp
|
| 1996 |
namespace std {
|
| 1997 |
template<class RealType = double>
|
| 1998 |
class exponential_distribution {
|
|
@@ -2051,13 +2368,11 @@ constructed.
|
|
| 2051 |
|
| 2052 |
##### Class template `gamma_distribution` <a id="rand.dist.pois.gamma">[[rand.dist.pois.gamma]]</a>
|
| 2053 |
|
| 2054 |
A `gamma_distribution` random number distribution produces random
|
| 2055 |
numbers x > 0 distributed according to the probability density function
|
| 2056 |
-
|
| 2057 |
-
\frac{e^{-x/\beta}}{\beta^{\alpha} \cdot \Gamma(\alpha)} \, \cdot \, x^{\, \alpha-1}
|
| 2058 |
-
\text{ .}$$
|
| 2059 |
|
| 2060 |
``` cpp
|
| 2061 |
namespace std {
|
| 2062 |
template<class RealType = double>
|
| 2063 |
class gamma_distribution {
|
|
@@ -2125,14 +2440,11 @@ constructed.
|
|
| 2125 |
|
| 2126 |
##### Class template `weibull_distribution` <a id="rand.dist.pois.weibull">[[rand.dist.pois.weibull]]</a>
|
| 2127 |
|
| 2128 |
A `weibull_distribution` random number distribution produces random
|
| 2129 |
numbers x ≥ 0 distributed according to the probability density function
|
| 2130 |
-
|
| 2131 |
-
\cdot \left(\frac{x}{b}\right)^{a-1}
|
| 2132 |
-
\cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
|
| 2133 |
-
\text{ .}$$
|
| 2134 |
|
| 2135 |
``` cpp
|
| 2136 |
namespace std {
|
| 2137 |
template<class RealType = double>
|
| 2138 |
class weibull_distribution {
|
|
@@ -2200,15 +2512,11 @@ constructed.
|
|
| 2200 |
|
| 2201 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 2202 |
|
| 2203 |
An `extreme_value_distribution` random number distribution produces
|
| 2204 |
random numbers x distributed according to the probability density
|
| 2205 |
-
function[^7]
|
| 2206 |
-
|
| 2207 |
-
$$p(x\,|\,a,b) = \frac{1}{b}
|
| 2208 |
-
\cdot \exp\left(\frac{a-x}{b} - \exp\left(\frac{a-x}{b}\right)\right)
|
| 2209 |
-
\text{ .}$$
|
| 2210 |
|
| 2211 |
``` cpp
|
| 2212 |
namespace std {
|
| 2213 |
template<class RealType = double>
|
| 2214 |
class extreme_value_distribution {
|
|
@@ -2278,20 +2586,13 @@ constructed.
|
|
| 2278 |
#### Normal distributions <a id="rand.dist.norm">[[rand.dist.norm]]</a>
|
| 2279 |
|
| 2280 |
##### Class template `normal_distribution` <a id="rand.dist.norm.normal">[[rand.dist.norm.normal]]</a>
|
| 2281 |
|
| 2282 |
A `normal_distribution` random number distribution produces random
|
| 2283 |
-
numbers x distributed according to the probability density function
|
| 2284 |
-
|
| 2285 |
-
|
| 2286 |
-
\cdot
|
| 2287 |
-
% e^{-(x-\mu)^2 / (2\sigma^2)}
|
| 2288 |
-
\exp{\left(- \, \frac{(x - \mu)^2}
|
| 2289 |
-
{2 \sigma^2}
|
| 2290 |
-
\right)
|
| 2291 |
-
}
|
| 2292 |
-
\text{ .}$$ The distribution parameters μ and σ are also known as this
|
| 2293 |
distribution’s *mean* and *standard deviation*.
|
| 2294 |
|
| 2295 |
``` cpp
|
| 2296 |
namespace std {
|
| 2297 |
template<class RealType = double>
|
|
@@ -2360,13 +2661,11 @@ constructed.
|
|
| 2360 |
|
| 2361 |
##### Class template `lognormal_distribution` <a id="rand.dist.norm.lognormal">[[rand.dist.norm.lognormal]]</a>
|
| 2362 |
|
| 2363 |
A `lognormal_distribution` random number distribution produces random
|
| 2364 |
numbers x > 0 distributed according to the probability density function
|
| 2365 |
-
|
| 2366 |
-
\cdot \exp{\left(-\frac{(\ln{x} - m)^2}{2 s^2}\right)}
|
| 2367 |
-
\text{ .}$$
|
| 2368 |
|
| 2369 |
``` cpp
|
| 2370 |
namespace std {
|
| 2371 |
template<class RealType = double>
|
| 2372 |
class lognormal_distribution {
|
|
@@ -2434,11 +2733,11 @@ constructed.
|
|
| 2434 |
|
| 2435 |
##### Class template `chi_squared_distribution` <a id="rand.dist.norm.chisq">[[rand.dist.norm.chisq]]</a>
|
| 2436 |
|
| 2437 |
A `chi_squared_distribution` random number distribution produces random
|
| 2438 |
numbers x > 0 distributed according to the probability density function
|
| 2439 |
-
|
| 2440 |
|
| 2441 |
``` cpp
|
| 2442 |
namespace std {
|
| 2443 |
template<class RealType = double>
|
| 2444 |
class chi_squared_distribution {
|
|
@@ -2496,12 +2795,11 @@ RealType n() const;
|
|
| 2496 |
constructed.
|
| 2497 |
|
| 2498 |
##### Class template `cauchy_distribution` <a id="rand.dist.norm.cauchy">[[rand.dist.norm.cauchy]]</a>
|
| 2499 |
|
| 2500 |
A `cauchy_distribution` random number distribution produces random
|
| 2501 |
-
numbers x distributed according to the probability density function
|
| 2502 |
-
$$p(x\,|\,a,b) = \left(\pi b \left(1 + \left(\frac{x-a}{b} \right)^2 \, \right)\right)^{-1} \text{ .}$$
|
| 2503 |
|
| 2504 |
``` cpp
|
| 2505 |
namespace std {
|
| 2506 |
template<class RealType = double>
|
| 2507 |
class cauchy_distribution {
|
|
@@ -2569,15 +2867,11 @@ constructed.
|
|
| 2569 |
|
| 2570 |
##### Class template `fisher_f_distribution` <a id="rand.dist.norm.f">[[rand.dist.norm.f]]</a>
|
| 2571 |
|
| 2572 |
A `fisher_f_distribution` random number distribution produces random
|
| 2573 |
numbers x ≥ 0 distributed according to the probability density function
|
| 2574 |
-
|
| 2575 |
-
\cdot \left(\frac{m}{n}\right)^{m/2}
|
| 2576 |
-
\cdot x^{(m/2)-1}
|
| 2577 |
-
\cdot \left(1 + \frac{m x}{n}\right)^{-(m + n)/2}
|
| 2578 |
-
\text{ .}$$
|
| 2579 |
|
| 2580 |
``` cpp
|
| 2581 |
namespace std {
|
| 2582 |
template<class RealType = double>
|
| 2583 |
class fisher_f_distribution {
|
|
@@ -2644,15 +2938,11 @@ RealType n() const;
|
|
| 2644 |
constructed.
|
| 2645 |
|
| 2646 |
##### Class template `student_t_distribution` <a id="rand.dist.norm.t">[[rand.dist.norm.t]]</a>
|
| 2647 |
|
| 2648 |
A `student_t_distribution` random number distribution produces random
|
| 2649 |
-
numbers x distributed according to the probability density function
|
| 2650 |
-
$$p(x\,|\,n) = \frac{1}{\sqrt{n \pi}}
|
| 2651 |
-
\cdot \frac{\Gamma\big((n+1)/2\big)}{\Gamma(n/2)}
|
| 2652 |
-
\cdot \left(1 + \frac{x^2}{n} \right)^{-(n+1)/2}
|
| 2653 |
-
\text{ .}$$
|
| 2654 |
|
| 2655 |
``` cpp
|
| 2656 |
namespace std {
|
| 2657 |
template<class RealType = double>
|
| 2658 |
class student_t_distribution {
|
|
@@ -2713,11 +3003,11 @@ constructed.
|
|
| 2713 |
|
| 2714 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 2715 |
|
| 2716 |
A `discrete_distribution` random number distribution produces random
|
| 2717 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 2718 |
-
function
|
| 2719 |
|
| 2720 |
Unless specified otherwise, the distribution parameters are calculated
|
| 2721 |
as: pₖ = {wₖ / S} for k = 0, …, n - 1, in which the values wₖ, commonly
|
| 2722 |
known as the *weights* , shall be non-negative, non-NaN, and
|
| 2723 |
non-infinity. Moreover, the following relation shall hold:
|
|
@@ -2792,11 +3082,11 @@ is `true`.
|
|
| 2792 |
requirements [[input.iterators]]. If `firstW == lastW`, let n = 1 and
|
| 2793 |
w₀ = 1. Otherwise, [`firstW`, `lastW`) forms a sequence w of length
|
| 2794 |
n > 0.
|
| 2795 |
|
| 2796 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 2797 |
-
probabilities given by the
|
| 2798 |
|
| 2799 |
``` cpp
|
| 2800 |
discrete_distribution(initializer_list<double> wl);
|
| 2801 |
```
|
| 2802 |
|
|
@@ -2831,12 +3121,11 @@ k = 0, …, n - 1.
|
|
| 2831 |
##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
|
| 2832 |
|
| 2833 |
A `piecewise_constant_distribution` random number distribution produces
|
| 2834 |
random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
|
| 2835 |
subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
|
| 2836 |
-
|
| 2837 |
-
\text{ , for $b_i \le x < b_{i+1}$.}$$
|
| 2838 |
|
| 2839 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 2840 |
*interval boundaries* , shall satisfy the relation $b_i < b_{i + 1}$ for
|
| 2841 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n
|
| 2842 |
distribution parameters are calculated as:
|
|
@@ -2978,15 +3267,11 @@ k = 0, …, n - 1.
|
|
| 2978 |
|
| 2979 |
##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
|
| 2980 |
|
| 2981 |
A `piecewise_linear_distribution` random number distribution produces
|
| 2982 |
random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
|
| 2983 |
-
[bᵢ, bᵢ₊₁) according to the probability density function
|
| 2984 |
-
$$p(x \,|\, b_0, \dotsc, b_n, \; \rho_0, \dotsc, \rho_n)
|
| 2985 |
-
= \rho_{i} \cdot {\frac{b_{i+1} - x}{b_{i+1} - b_i}}
|
| 2986 |
-
+ \rho_{i+1} \cdot {\frac{x - b_i}{b_{i+1} - b_i}}
|
| 2987 |
-
\text{ , for $b_i \le x < b_{i+1}$.}$$
|
| 2988 |
|
| 2989 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 2990 |
*interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
|
| 2991 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
|
| 2992 |
distribution parameters are calculated as ρₖ = {wₖ / S} for k = 0, …, n,
|
|
@@ -3056,12 +3341,16 @@ n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1.
|
|
| 3056 |
template<class InputIteratorB, class InputIteratorW>
|
| 3057 |
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 3058 |
InputIteratorW firstW);
|
| 3059 |
```
|
| 3060 |
|
| 3061 |
-
*Mandates:*
|
| 3062 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3063 |
|
| 3064 |
*Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
|
| 3065 |
*Cpp17InputIterator* requirements [[input.iterators]]. If
|
| 3066 |
`firstB == lastB` or `++firstB == lastB`, let n = 1, ρ₀ = ρ₁ = 1,
|
| 3067 |
b₀ = 0, and b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of
|
|
@@ -3141,7 +3430,7 @@ functions may call `rand`. It is *implementation-defined* whether the
|
|
| 3141 |
document [[rand]] are often preferable to `rand`, because `rand`’s
|
| 3142 |
underlying algorithm is unspecified. Use of `rand` therefore continues
|
| 3143 |
to be non-portable, with unpredictable and oft-questionable quality and
|
| 3144 |
performance. — *end note*]
|
| 3145 |
|
| 3146 |
-
See also: ISO C 7.
|
| 3147 |
|
|
|
|
| 49 |
#include <initializer_list> // see [initializer.list.syn]
|
| 50 |
|
| 51 |
namespace std {
|
| 52 |
// [rand.req.urng], uniform random bit generator requirements
|
| 53 |
template<class G>
|
| 54 |
+
concept uniform_random_bit_generator = see below; // freestanding
|
| 55 |
|
| 56 |
// [rand.eng.lcong], class template linear_congruential_engine
|
| 57 |
template<class UIntType, UIntType a, UIntType c, UIntType m>
|
| 58 |
+
class linear_congruential_engine; // partially freestanding
|
| 59 |
|
| 60 |
// [rand.eng.mers], class template mersenne_twister_engine
|
| 61 |
template<class UIntType, size_t w, size_t n, size_t m, size_t r,
|
| 62 |
UIntType a, size_t u, UIntType d, size_t s,
|
| 63 |
UIntType b, size_t t,
|
| 64 |
UIntType c, size_t l, UIntType f>
|
| 65 |
class mersenne_twister_engine;
|
| 66 |
|
| 67 |
// [rand.eng.sub], class template subtract_with_carry_engine
|
| 68 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 69 |
+
class subtract_with_carry_engine; // partially freestanding
|
| 70 |
|
| 71 |
// [rand.adapt.disc], class template discard_block_engine
|
| 72 |
template<class Engine, size_t p, size_t r>
|
| 73 |
+
class discard_block_engine; // partially freestanding
|
| 74 |
|
| 75 |
// [rand.adapt.ibits], class template independent_bits_engine
|
| 76 |
template<class Engine, size_t w, class UIntType>
|
| 77 |
+
class independent_bits_engine; // partially freestanding
|
| 78 |
|
| 79 |
// [rand.adapt.shuf], class template shuffle_order_engine
|
| 80 |
template<class Engine, size_t k>
|
| 81 |
class shuffle_order_engine;
|
| 82 |
|
| 83 |
+
// [rand.eng.philox], class template philox_engine
|
| 84 |
+
template<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>
|
| 85 |
+
class philox_engine; // partially freestanding
|
| 86 |
+
|
| 87 |
// [rand.predef], engines and engine adaptors with predefined parameters
|
| 88 |
+
using minstd_rand0 = see below; // freestanding
|
| 89 |
+
using minstd_rand = see below; // freestanding
|
| 90 |
+
using mt19937 = see below; // freestanding
|
| 91 |
+
using mt19937_64 = see below; // freestanding
|
| 92 |
+
using ranlux24_base = see below; // freestanding
|
| 93 |
+
using ranlux48_base = see below; // freestanding
|
| 94 |
+
using ranlux24 = see below; // freestanding
|
| 95 |
+
using ranlux48 = see below; // freestanding
|
| 96 |
using knuth_b = see below;
|
| 97 |
+
using philox4x32 = see below; // freestanding
|
| 98 |
+
using philox4x64 = see below; // freestanding
|
| 99 |
|
| 100 |
using default_random_engine = see below;
|
| 101 |
|
| 102 |
// [rand.device], class random_device
|
| 103 |
class random_device;
|
| 104 |
|
| 105 |
// [rand.util.seedseq], class seed_seq
|
| 106 |
class seed_seq;
|
| 107 |
|
| 108 |
// [rand.util.canonical], function template generate_canonical
|
| 109 |
+
template<class RealType, size_t digits, class URBG>
|
| 110 |
RealType generate_canonical(URBG& g);
|
| 111 |
|
| 112 |
+
namespace ranges {
|
| 113 |
+
// [alg.rand.generate], generate_random
|
| 114 |
+
template<class R, class G>
|
| 115 |
+
requires output_range<R, invoke_result_t<G&>> &&
|
| 116 |
+
uniform_random_bit_generator<remove_cvref_t<G>>
|
| 117 |
+
constexpr borrowed_iterator_t<R> generate_random(R&& r, G&& g);
|
| 118 |
+
|
| 119 |
+
template<class G, output_iterator<invoke_result_t<G&>> O, sentinel_for<O> S>
|
| 120 |
+
requires uniform_random_bit_generator<remove_cvref_t<G>>
|
| 121 |
+
constexpr O generate_random(O first, S last, G&& g);
|
| 122 |
+
|
| 123 |
+
template<class R, class G, class D>
|
| 124 |
+
requires output_range<R, invoke_result_t<D&, G&>> && invocable<D&, G&> &&
|
| 125 |
+
uniform_random_bit_generator<remove_cvref_t<G>> &&
|
| 126 |
+
is_arithmetic_v<invoke_result_t<D&, G&>>
|
| 127 |
+
constexpr borrowed_iterator_t<R> generate_random(R&& r, G&& g, D&& d);
|
| 128 |
+
|
| 129 |
+
template<class G, class D, output_iterator<invoke_result_t<D&, G&>> O, sentinel_for<O> S>
|
| 130 |
+
requires invocable<D&, G&> && uniform_random_bit_generator<remove_cvref_t<G>> &&
|
| 131 |
+
is_arithmetic_v<invoke_result_t<D&, G&>>
|
| 132 |
+
constexpr O generate_random(O first, S last, G&& g, D&& d);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
// [rand.dist.uni.int], class template uniform_int_distribution
|
| 136 |
template<class IntType = int>
|
| 137 |
+
class uniform_int_distribution; // partially freestanding
|
| 138 |
|
| 139 |
// [rand.dist.uni.real], class template uniform_real_distribution
|
| 140 |
template<class RealType = double>
|
| 141 |
class uniform_real_distribution;
|
| 142 |
|
|
|
|
| 215 |
|
| 216 |
### Requirements <a id="rand.req">[[rand.req]]</a>
|
| 217 |
|
| 218 |
#### General requirements <a id="rand.req.genl">[[rand.req.genl]]</a>
|
| 219 |
|
| 220 |
+
Throughout [[rand]], the effect of instantiating a template:
|
|
|
|
| 221 |
|
| 222 |
- that has a template type parameter named `Sseq` is undefined unless
|
| 223 |
the corresponding template argument is cv-unqualified and meets the
|
| 224 |
requirements of seed sequence [[rand.req.seedseq]].
|
| 225 |
- that has a template type parameter named `URBG` is undefined unless
|
|
|
|
| 238 |
- that has a template type parameter named `UIntType` is undefined
|
| 239 |
unless the corresponding template argument is cv-unqualified and is
|
| 240 |
one of `unsigned short`, `unsigned int`, `unsigned long`, or
|
| 241 |
`unsigned long long`.
|
| 242 |
|
| 243 |
+
Throughout [[rand]], phrases of the form “`x` is an iterator of a
|
| 244 |
+
specific kind” shall be interpreted as equivalent to the more formal
|
| 245 |
+
requirement that “`x` is a value of a type meeting the requirements of
|
| 246 |
+
the specified iterator type”.
|
| 247 |
|
| 248 |
+
Throughout [[rand]], any constructor that can be called with a single
|
| 249 |
+
argument and that meets a requirement specified in this subclause shall
|
| 250 |
+
be declared `explicit`.
|
| 251 |
|
| 252 |
#### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
|
| 253 |
|
| 254 |
A *seed sequence* is an object that consumes a sequence of
|
| 255 |
integer-valued data and produces a requested number of unsigned integer
|
|
|
|
| 260 |
applications requiring large numbers of random number
|
| 261 |
engines. — *end note*]
|
| 262 |
|
| 263 |
A class `S` meets the requirements of a seed sequence if the expressions
|
| 264 |
shown in [[rand.req.seedseq]] are valid and have the indicated
|
| 265 |
+
semantics, and if `S` also meets all other requirements of
|
| 266 |
+
[[rand.req.seedseq]]. In [[rand.req.seedseq]] and throughout this
|
| 267 |
subclause:
|
| 268 |
|
| 269 |
- `T` is the type named by `S`’s associated `result_type`;
|
| 270 |
- `q` is a value of type `S` and `r` is a value of type `S` or
|
| 271 |
`const S`;
|
|
|
|
| 332 |
|
| 333 |
A class `E` that meets the requirements of a uniform random bit
|
| 334 |
generator [[rand.req.urng]] also meets the requirements of a *random
|
| 335 |
number engine* if the expressions shown in [[rand.req.eng]] are valid
|
| 336 |
and have the indicated semantics, and if `E` also meets all other
|
| 337 |
+
requirements of [[rand.req.eng]]. In [[rand.req.eng]] and throughout
|
| 338 |
+
this subclause:
|
| 339 |
|
| 340 |
- `T` is the type named by `E`’s associated `result_type`;
|
| 341 |
- `e` is a value of `E`, `v` is an lvalue of `E`, `x` and `y` are
|
| 342 |
(possibly const) values of `E`;
|
| 343 |
- `s` is a value of `T`;
|
|
|
|
| 355 |
`E` shall meet the *Cpp17CopyConstructible* (
|
| 356 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 357 |
[[cpp17.copyassignable]]) requirements. These operations shall each be
|
| 358 |
of complexity no worse than 𝑂(\text{size of state}).
|
| 359 |
|
| 360 |
+
On hosted implementations, the following expressions are well-formed and
|
| 361 |
+
have the specified semantics.
|
| 362 |
+
|
| 363 |
+
``` cpp
|
| 364 |
+
os << x
|
| 365 |
+
```
|
| 366 |
+
|
| 367 |
+
*Effects:* With `os.`*`fmtflags`* set to `ios_base::dec|ios_base::left`
|
| 368 |
+
and the fill character set to the space character, writes to `os` the
|
| 369 |
+
textual representation of `x`’s current state. In the output, adjacent
|
| 370 |
+
numbers are separated by one or more space characters.
|
| 371 |
+
|
| 372 |
+
*Ensures:* The `os.`*`fmtflags`* and fill character are unchanged.
|
| 373 |
+
|
| 374 |
+
*Result:* reference to the type of `os`.
|
| 375 |
+
|
| 376 |
+
*Returns:* `os`.
|
| 377 |
+
|
| 378 |
+
*Complexity:* 𝑂(size of state)
|
| 379 |
+
|
| 380 |
+
``` cpp
|
| 381 |
+
is >> v
|
| 382 |
+
```
|
| 383 |
+
|
| 384 |
+
*Preconditions:* `is` provides a textual representation that was
|
| 385 |
+
previously written using an output stream whose imbued locale was the
|
| 386 |
+
same as that of `is`, and whose type’s template specialization arguments
|
| 387 |
+
`charT` and `traits` were respectively the same as those of `is`.
|
| 388 |
+
|
| 389 |
+
*Effects:* With `is.`*`fmtflags`* set to `ios_base::dec`, sets `v`’s
|
| 390 |
+
state as determined by reading its textual representation from `is`. If
|
| 391 |
+
bad input is encountered, ensures that `v`’s state is unchanged by the
|
| 392 |
+
operation and calls `is.setstate(ios_base::failbit)` (which may throw
|
| 393 |
+
`ios_base::failure` [[iostate.flags]]). If a textual representation
|
| 394 |
+
written via `os << x` was subsequently read via `is >> v`, then `x == v`
|
| 395 |
+
provided that there have been no intervening invocations of `x` or of
|
| 396 |
+
`v`.
|
| 397 |
+
|
| 398 |
+
*Ensures:* The `is.`*`fmtflags`* are unchanged.
|
| 399 |
+
|
| 400 |
+
*Result:* reference to the type of `is`.
|
| 401 |
+
|
| 402 |
+
*Returns:* `is`.
|
| 403 |
+
|
| 404 |
+
*Complexity:* 𝑂(size of state)
|
| 405 |
+
|
| 406 |
#### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
|
| 407 |
|
| 408 |
A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
|
| 409 |
of type `A` is a random number engine that takes values produced by some
|
| 410 |
other random number engine, and applies an algorithm to those values in
|
|
|
|
| 489 |
whole.
|
| 490 |
|
| 491 |
A class `D` meets the requirements of a *random number distribution* if
|
| 492 |
the expressions shown in [[rand.req.dist]] are valid and have the
|
| 493 |
indicated semantics, and if `D` and its associated types also meet all
|
| 494 |
+
other requirements of [[rand.req.dist]]. In [[rand.req.dist]] and
|
| 495 |
+
throughout this subclause,
|
| 496 |
|
| 497 |
- `T` is the type named by `D`’s associated `result_type`;
|
| 498 |
- `P` is the type named by `D`’s associated `param_type`;
|
| 499 |
- `d` is a value of `D`, and `x` and `y` are (possibly const) values of
|
| 500 |
`D`;
|
|
|
|
| 526 |
the same type using `is >> y`, repeated invocations of `y(g)` shall
|
| 527 |
produce the same sequence of numbers as would repeated invocations of
|
| 528 |
`x(g)`.
|
| 529 |
|
| 530 |
It is unspecified whether `D::param_type` is declared as a (nested)
|
| 531 |
+
`class` or via a `typedef`. In [[rand]], declarations of `D::param_type`
|
| 532 |
+
are in the form of `typedef`s for convenience of exposition only.
|
|
|
|
| 533 |
|
| 534 |
`P` shall meet the *Cpp17CopyConstructible* (
|
| 535 |
[[cpp17.copyconstructible]]), *Cpp17CopyAssignable* (
|
| 536 |
[[cpp17.copyassignable]]), and *Cpp17EqualityComparable* (
|
| 537 |
[[cpp17.equalitycomparable]]) requirements.
|
|
|
|
| 548 |
|
| 549 |
``` cpp
|
| 550 |
using distribution_type = D;
|
| 551 |
```
|
| 552 |
|
| 553 |
+
On hosted implementations, the following expressions are well-formed and
|
| 554 |
+
have the specified semantics.
|
| 555 |
+
|
| 556 |
+
``` cpp
|
| 557 |
+
os << x
|
| 558 |
+
```
|
| 559 |
+
|
| 560 |
+
*Effects:* Writes to `os` a textual representation for the parameters
|
| 561 |
+
and the additional internal data of `x`.
|
| 562 |
+
|
| 563 |
+
*Ensures:* The `os.`*`fmtflags`* and fill character are unchanged.
|
| 564 |
+
|
| 565 |
+
*Result:* reference to the type of `os`.
|
| 566 |
+
|
| 567 |
+
*Returns:* `os`.
|
| 568 |
+
|
| 569 |
+
``` cpp
|
| 570 |
+
is >> d
|
| 571 |
+
```
|
| 572 |
+
|
| 573 |
+
*Preconditions:* `is` provides a textual representation that was
|
| 574 |
+
previously written using an `os` whose imbued locale and whose type’s
|
| 575 |
+
template specialization arguments `charT` and `traits` were the same as
|
| 576 |
+
those of `is`.
|
| 577 |
+
|
| 578 |
+
*Effects:* Restores from `is` the parameters and additional internal
|
| 579 |
+
data of the lvalue `d`. If bad input is encountered, ensures that `d` is
|
| 580 |
+
unchanged by the operation and calls `is.setstate(ios_base::failbit)`
|
| 581 |
+
(which may throw `ios_base::failure` [[iostate.flags]]).
|
| 582 |
+
|
| 583 |
+
*Ensures:* The `is.`*`fmtflags`* are unchanged.
|
| 584 |
+
|
| 585 |
+
*Result:* reference to the type of `is`.
|
| 586 |
+
|
| 587 |
+
*Returns:* `is`.
|
| 588 |
+
|
| 589 |
### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
|
| 590 |
|
| 591 |
#### General <a id="rand.eng.general">[[rand.eng.general]]</a>
|
| 592 |
|
| 593 |
Each type instantiated from a class template specified in [[rand.eng]]
|
|
|
|
| 609 |
is additional semantic information. In particular, declarations for copy
|
| 610 |
constructors, for copy assignment operators, for streaming operators,
|
| 611 |
and for equality and inequality operators are not shown in the synopses.
|
| 612 |
|
| 613 |
Each template specified in [[rand.eng]] requires one or more
|
| 614 |
+
relationships, involving the value(s) of its constant template
|
| 615 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 616 |
ill-formed if any such required relationship fails to hold.
|
| 617 |
|
| 618 |
For every random number engine and for every random number engine
|
| 619 |
adaptor `X` defined in [[rand.eng]] and in [[rand.adapt]]:
|
|
|
|
| 679 |
void discard(unsigned long long z);
|
| 680 |
|
| 681 |
// inserters and extractors
|
| 682 |
template<class charT, class traits>
|
| 683 |
friend basic_ostream<charT, traits>&
|
| 684 |
+
operator<<(basic_ostream<charT, traits>& os, // hosted
|
| 685 |
+
const linear_congruential_engine& x);
|
| 686 |
template<class charT, class traits>
|
| 687 |
friend basic_istream<charT, traits>&
|
| 688 |
+
operator>>(basic_istream<charT, traits>& is, // hosted
|
| 689 |
+
linear_congruential_engine& x);
|
| 690 |
};
|
| 691 |
}
|
| 692 |
```
|
| 693 |
|
| 694 |
+
If the template parameter `m` is 0, the modulus m used throughout
|
| 695 |
+
[[rand.eng.lcong]] is `numeric_limits<result_type>::max()` plus 1.
|
|
|
|
| 696 |
|
| 697 |
[*Note 1*: m need not be representable as a value of type
|
| 698 |
`result_type`. — *end note*]
|
| 699 |
|
| 700 |
If the template parameter `m` is not 0, the following relations shall
|
|
|
|
| 798 |
void discard(unsigned long long z);
|
| 799 |
|
| 800 |
// inserters and extractors
|
| 801 |
template<class charT, class traits>
|
| 802 |
friend basic_ostream<charT, traits>&
|
| 803 |
+
operator<<(basic_ostream<charT, traits>& os, // hosted
|
| 804 |
+
const mersenne_twister_engine& x);
|
| 805 |
template<class charT, class traits>
|
| 806 |
friend basic_istream<charT, traits>&
|
| 807 |
+
operator>>(basic_istream<charT, traits>& is, // hosted
|
| 808 |
+
mersenne_twister_engine& x);
|
| 809 |
};
|
| 810 |
}
|
| 811 |
```
|
| 812 |
|
| 813 |
The following relations shall hold: `0 < m`, `m <= n`, `2u < w`,
|
|
|
|
| 880 |
static constexpr size_t word_size = w;
|
| 881 |
static constexpr size_t short_lag = s;
|
| 882 |
static constexpr size_t long_lag = r;
|
| 883 |
static constexpr result_type min() { return 0; }
|
| 884 |
static constexpr result_type max() { return m - 1; }
|
| 885 |
+
static constexpr uint_least32_t default_seed = 19780503u;
|
| 886 |
|
| 887 |
// constructors and seeding functions
|
| 888 |
+
subtract_with_carry_engine() : subtract_with_carry_engine(0u) {}
|
| 889 |
explicit subtract_with_carry_engine(result_type value);
|
| 890 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 891 |
+
void seed(result_type value = 0u);
|
| 892 |
template<class Sseq> void seed(Sseq& q);
|
| 893 |
|
| 894 |
// equality operators
|
| 895 |
friend bool operator==(const subtract_with_carry_engine& x,
|
| 896 |
const subtract_with_carry_engine& y);
|
|
|
|
| 900 |
void discard(unsigned long long z);
|
| 901 |
|
| 902 |
// inserters and extractors
|
| 903 |
template<class charT, class traits>
|
| 904 |
friend basic_ostream<charT, traits>&
|
| 905 |
+
operator<<(basic_ostream<charT, traits>& os, // hosted
|
| 906 |
+
const subtract_with_carry_engine& x);
|
| 907 |
template<class charT, class traits>
|
| 908 |
friend basic_istream<charT, traits>&
|
| 909 |
+
operator>>(basic_istream<charT, traits>& is, // hosted
|
| 910 |
+
subtract_with_carry_engine& x);
|
| 911 |
};
|
| 912 |
}
|
| 913 |
```
|
| 914 |
|
| 915 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
|
|
|
| 927 |
|
| 928 |
To set the values Xₖ, first construct `e`, a
|
| 929 |
`linear_congruential_engine` object, as if by the following definition:
|
| 930 |
|
| 931 |
``` cpp
|
| 932 |
+
linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u> e(
|
| 933 |
+
value == 0u ? default_seed : static_cast<uint_least32_t>(value % 2147483563u));
|
| 934 |
```
|
| 935 |
|
| 936 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 937 |
successive invocations of `e`. Set Xₖ to
|
| 938 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
|
|
|
| 947 |
r ⋅ k, invokes `q.generate(`a + 0`, `a + r ⋅ k`)` and then, iteratively
|
| 948 |
for i = -r, …, -1, sets Xᵢ to
|
| 949 |
$\left(\sum_{j=0}^{k-1}a_{k(i+r)+j} \cdot 2^{32j} \right) \bmod m$. If
|
| 950 |
X₋₁ is then 0, sets c to 1; otherwise sets c to 0.
|
| 951 |
|
| 952 |
+
#### Class template `philox_engine` <a id="rand.eng.philox">[[rand.eng.philox]]</a>
|
| 953 |
+
|
| 954 |
+
A `philox_engine` random number engine produces unsigned integer random
|
| 955 |
+
numbers in the interval \[`0`, m), where m = 2ʷ and the template
|
| 956 |
+
parameter w defines the range of the produced numbers. The state of a
|
| 957 |
+
`philox_engine` object consists of a sequence X of n unsigned integer
|
| 958 |
+
values of width w, a sequence K of n/2 values of `result_type`, a
|
| 959 |
+
sequence Y of n values of `result_type`, and a scalar i, where
|
| 960 |
+
|
| 961 |
+
- X is the interpretation of the unsigned integer *counter* value
|
| 962 |
+
$Z \cedef \sum_{j = 0}^{n - 1} X_j \cdot 2^{wj}$ of n ⋅ w bits,
|
| 963 |
+
- K are keys, which are generated once from the seed (see constructors
|
| 964 |
+
below) and remain constant unless the `seed` function [[rand.req.eng]]
|
| 965 |
+
is invoked,
|
| 966 |
+
- Y stores a batch of output values, and
|
| 967 |
+
- i is an index for an element of the sequence Y.
|
| 968 |
+
|
| 969 |
+
The generation algorithm returns Yᵢ, the value stored in the iᵗʰ element
|
| 970 |
+
of Y after applying the transition algorithm.
|
| 971 |
+
|
| 972 |
+
The state transition is performed as if by the following algorithm:
|
| 973 |
+
|
| 974 |
+
``` cpp
|
| 975 |
+
i = i + 1
|
| 976 |
+
if (i == n) {
|
| 977 |
+
Y = Philox(K, X) // see below
|
| 978 |
+
Z = Z + 1
|
| 979 |
+
i = 0
|
| 980 |
+
}
|
| 981 |
+
```
|
| 982 |
+
|
| 983 |
+
The `Philox` function maps the length-n/2 sequence K and the length-n
|
| 984 |
+
sequence X into a length-n output sequence Y. Philox applies an r-round
|
| 985 |
+
substitution-permutation network to the values in X. A single round of
|
| 986 |
+
the generation algorithm performs the following steps:
|
| 987 |
+
|
| 988 |
+
- The output sequence X' of the previous round (X in case of the first
|
| 989 |
+
round) is permuted to obtain the intermediate state V:
|
| 990 |
+
``` cpp
|
| 991 |
+
Vⱼ = X'_{fₙ(j)}
|
| 992 |
+
```
|
| 993 |
+
|
| 994 |
+
where j = 0, …, n - 1 and fₙ(j) is defined in [[rand.eng.philox.f]].
|
| 995 |
+
**Table: Values for the word permutation $\bm{f}_{\bm{n}}\bm{(j)}$** <a id="rand.eng.philox.f">[rand.eng.philox.f]</a>
|
| 996 |
+
|
| 997 |
+
| | |
|
| 998 |
+
| --------------------------------------------- | ---------------------------- |
|
| 999 |
+
| *[spans 2 columns]* $\bm{f}_{\bm{n}}\bm{(j)}$ | *[spans 4 columns]* $\bm{j}$ |
|
| 1000 |
+
| \multicolumn{2}{|c|} | 0 | 1 | 2 | 3 |
|
| 1001 |
+
| $\bm{n} $ | 2 | 0 | 1 | \multicolumn{2}{c|} |
|
| 1002 |
+
| | 4 | 2 | 1 | 0 | 3 |
|
| 1003 |
+
|
| 1004 |
+
|
| 1005 |
+
\[*Note 1*: For n = 2 the sequence is not permuted. — *end note*]
|
| 1006 |
+
- The following computations are applied to the elements of the V
|
| 1007 |
+
sequence:
|
| 1008 |
+
``` cpp
|
| 1009 |
+
X_2k + 0} = \mulhi(V_2k, Mₖ, w) \xor key^qₖ \xor V_2k + 1}
|
| 1010 |
+
X_2k + 1} = \mullo(V_2k, Mₖ, w)
|
| 1011 |
+
```
|
| 1012 |
+
|
| 1013 |
+
where:
|
| 1014 |
+
- μllo(`a`, `b`, `w`) is the low half of the modular multiplication of
|
| 1015 |
+
`a` and `b`: $(\tcode{a} \cdot \tcode{b}) \mod 2^w$,
|
| 1016 |
+
- μlhi(`a`, `b`, `w`) is the high half of the modular multiplication
|
| 1017 |
+
of `a` and `b`: (⌊ (`a` ⋅ `b`) / 2ʷ ⌋),
|
| 1018 |
+
- k = 0, …, n/2 - 1 is the index in the sequences,
|
| 1019 |
+
- q = 0, …, r - 1 is the index of the round,
|
| 1020 |
+
- $\mathit{key}^q_k$ is the kᵗʰ round key for round q,
|
| 1021 |
+
$\mathit{key}^q_k \cedef (K_k + q \cdot C_k) \mod 2^w$,
|
| 1022 |
+
- Kₖ are the elements of the key sequence K,
|
| 1023 |
+
- Mₖ is `multipliers[k]`, and
|
| 1024 |
+
- Cₖ is `round_consts[k]`.
|
| 1025 |
+
|
| 1026 |
+
After r applications of the single-round function, `Philox` returns the
|
| 1027 |
+
sequence Y = X'.
|
| 1028 |
+
|
| 1029 |
+
``` cpp
|
| 1030 |
+
namespace std {
|
| 1031 |
+
template<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>
|
| 1032 |
+
class philox_engine {
|
| 1033 |
+
static constexpr size_t array-size = n / 2; // exposition only
|
| 1034 |
+
public:
|
| 1035 |
+
// types
|
| 1036 |
+
using result_type = UIntType;
|
| 1037 |
+
|
| 1038 |
+
// engine characteristics
|
| 1039 |
+
static constexpr size_t word_size = w;
|
| 1040 |
+
static constexpr size_t word_count = n;
|
| 1041 |
+
static constexpr size_t round_count = r;
|
| 1042 |
+
static constexpr array<result_type, array-size> multipliers;
|
| 1043 |
+
static constexpr array<result_type, array-size> round_consts;
|
| 1044 |
+
static constexpr result_type min() { return 0; }
|
| 1045 |
+
static constexpr result_type max() { return m - 1; }
|
| 1046 |
+
static constexpr result_type default_seed = 20111115u;
|
| 1047 |
+
|
| 1048 |
+
// constructors and seeding functions
|
| 1049 |
+
philox_engine() : philox_engine(default_seed) {}
|
| 1050 |
+
explicit philox_engine(result_type value);
|
| 1051 |
+
template<class Sseq> explicit philox_engine(Sseq& q);
|
| 1052 |
+
void seed(result_type value = default_seed);
|
| 1053 |
+
template<class Sseq> void seed(Sseq& q);
|
| 1054 |
+
|
| 1055 |
+
void set_counter(const array<result_type, n>& counter);
|
| 1056 |
+
|
| 1057 |
+
// equality operators
|
| 1058 |
+
friend bool operator==(const philox_engine& x, const philox_engine& y);
|
| 1059 |
+
|
| 1060 |
+
// generating functions
|
| 1061 |
+
result_type operator()();
|
| 1062 |
+
void discard(unsigned long long z);
|
| 1063 |
+
|
| 1064 |
+
// inserters and extractors
|
| 1065 |
+
template<class charT, class traits>
|
| 1066 |
+
friend basic_ostream<charT, traits>&
|
| 1067 |
+
operator<<(basic_ostream<charT, traits>& os, const philox_engine& x); // hosted
|
| 1068 |
+
template<class charT, class traits>
|
| 1069 |
+
friend basic_istream<charT, traits>&
|
| 1070 |
+
operator>>(basic_istream<charT, traits>& is, philox_engine& x); // hosted
|
| 1071 |
+
};
|
| 1072 |
+
}
|
| 1073 |
+
```
|
| 1074 |
+
|
| 1075 |
+
*Mandates:*
|
| 1076 |
+
|
| 1077 |
+
- `sizeof...(consts) == n` is `true`, and
|
| 1078 |
+
- `n == 2 || n == 4` is `true`, and
|
| 1079 |
+
- `0 < r` is `true`, and
|
| 1080 |
+
- `0 < w && w <= numeric_limits<UIntType>::digits` is `true`.
|
| 1081 |
+
|
| 1082 |
+
The template parameter pack `consts` represents the Mₖ and Cₖ constants
|
| 1083 |
+
which are grouped as follows:
|
| 1084 |
+
$[ M_0, C_0, M_1, C_1, M_2, C_2, \dotsc, M_{n/2 - 1}, C_{n/2 - 1} ]$.
|
| 1085 |
+
|
| 1086 |
+
The textual representation consists of the values of
|
| 1087 |
+
$K_0, \dotsc, K_{n/2 - 1}, X_{0}, \dotsc, X_{n - 1}, i$, in that order.
|
| 1088 |
+
|
| 1089 |
+
[*Note 2*: The stream extraction operator can reconstruct Y from K and
|
| 1090 |
+
X, as needed. — *end note*]
|
| 1091 |
+
|
| 1092 |
+
``` cpp
|
| 1093 |
+
explicit philox_engine(result_type value);
|
| 1094 |
+
```
|
| 1095 |
+
|
| 1096 |
+
*Effects:* Sets the K₀ element of sequence K to
|
| 1097 |
+
$\texttt{value} \mod 2^w$. All elements of sequences X and K (except K₀)
|
| 1098 |
+
are set to `0`. The value of i is set to n - 1.
|
| 1099 |
+
|
| 1100 |
+
``` cpp
|
| 1101 |
+
template<class Sseq> explicit philox_engine(Sseq& q);
|
| 1102 |
+
```
|
| 1103 |
+
|
| 1104 |
+
*Effects:* With p = ⌈ w / 32 ⌉ and an array (or equivalent) `a` of
|
| 1105 |
+
length (n/2) ⋅ p, invokes `q.generate(a + 0, a + n / 2 * `p`)` and then
|
| 1106 |
+
iteratively for k = 0, …, n/2 - 1, sets Kₖ to
|
| 1107 |
+
$\left(\sum_{j = 0}^{p - 1} a_{k p + j} \cdot 2^{32j} \right) \mod 2^w$.
|
| 1108 |
+
All elements of sequence X are set to `0`. The value of i is set to
|
| 1109 |
+
n - 1.
|
| 1110 |
+
|
| 1111 |
+
``` cpp
|
| 1112 |
+
void set_counter(const array<result_type, n>& c);
|
| 1113 |
+
```
|
| 1114 |
+
|
| 1115 |
+
*Effects:* For j = 0, …, n - 1 sets Xⱼ to $C_{n - 1 - j} \mod 2^w$. The
|
| 1116 |
+
value of i is set to n - 1.
|
| 1117 |
+
|
| 1118 |
+
[*Note 1*: The counter is the value Z introduced at the beginning of
|
| 1119 |
+
this subclause. — *end note*]
|
| 1120 |
+
|
| 1121 |
### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
|
| 1122 |
|
| 1123 |
+
#### General <a id="rand.adapt.general">[[rand.adapt.general]]</a>
|
| 1124 |
|
| 1125 |
+
Each type instantiated from a class template specified in [[rand.adapt]]
|
| 1126 |
+
meets the requirements of a random number engine adaptor
|
| 1127 |
+
[[rand.req.adapt]] type.
|
| 1128 |
|
| 1129 |
Except where specified otherwise, the complexity of each function
|
| 1130 |
+
specified in [[rand.adapt]] is constant.
|
| 1131 |
|
| 1132 |
+
Except where specified otherwise, no function described in
|
| 1133 |
+
[[rand.adapt]] throws an exception.
|
| 1134 |
|
| 1135 |
+
Every function described in [[rand.adapt]] that has a function parameter
|
| 1136 |
+
`q` of type `Sseq&` for a template type parameter named `Sseq` that is
|
| 1137 |
+
different from type `seed_seq` throws what and when the invocation of
|
| 1138 |
+
`q.generate` throws.
|
| 1139 |
|
| 1140 |
+
Descriptions are provided in [[rand.adapt]] only for adaptor operations
|
| 1141 |
+
that are not described in subclause [[rand.req.adapt]] or for
|
| 1142 |
+
operations where there is additional semantic information. In
|
| 1143 |
+
particular, declarations for copy constructors, for copy assignment
|
| 1144 |
+
operators, for streaming operators, and for equality and inequality
|
| 1145 |
+
operators are not shown in the synopses.
|
| 1146 |
|
| 1147 |
+
Each template specified in [[rand.adapt]] requires one or more
|
| 1148 |
+
relationships, involving the value(s) of its constant template
|
| 1149 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 1150 |
ill-formed if any such required relationship fails to hold.
|
| 1151 |
|
| 1152 |
#### Class template `discard_block_engine` <a id="rand.adapt.disc">[[rand.adapt.disc]]</a>
|
| 1153 |
|
|
|
|
| 1170 |
namespace std {
|
| 1171 |
template<class Engine, size_t p, size_t r>
|
| 1172 |
class discard_block_engine {
|
| 1173 |
public:
|
| 1174 |
// types
|
| 1175 |
+
using result_type = Engine::result_type;
|
| 1176 |
|
| 1177 |
// engine characteristics
|
| 1178 |
static constexpr size_t block_size = p;
|
| 1179 |
static constexpr size_t used_block = r;
|
| 1180 |
static constexpr result_type min() { return Engine::min(); }
|
|
|
|
| 1201 |
const Engine& base() const noexcept { return e; }
|
| 1202 |
|
| 1203 |
// inserters and extractors
|
| 1204 |
template<class charT, class traits>
|
| 1205 |
friend basic_ostream<charT, traits>&
|
| 1206 |
+
operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x); // hosted
|
| 1207 |
template<class charT, class traits>
|
| 1208 |
friend basic_istream<charT, traits>&
|
| 1209 |
+
operator>>(basic_istream<charT, traits>& is, discard_block_engine& x); // hosted
|
| 1210 |
|
| 1211 |
private:
|
| 1212 |
Engine e; // exposition only
|
| 1213 |
size_t n; // exposition only
|
| 1214 |
};
|
|
|
|
| 1264 |
S = 2^{w₀ + 1} \cdot S + u \bmod 2^{w₀ + 1};
|
| 1265 |
}
|
| 1266 |
```
|
| 1267 |
|
| 1268 |
``` cpp
|
| 1269 |
+
namespace std {
|
| 1270 |
template<class Engine, size_t w, class UIntType>
|
| 1271 |
class independent_bits_engine {
|
| 1272 |
public:
|
| 1273 |
// types
|
| 1274 |
using result_type = UIntType;
|
|
|
|
| 1298 |
const Engine& base() const noexcept { return e; }
|
| 1299 |
|
| 1300 |
// inserters and extractors
|
| 1301 |
template<class charT, class traits>
|
| 1302 |
friend basic_ostream<charT, traits>&
|
| 1303 |
+
operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x); // hosted
|
| 1304 |
template<class charT, class traits>
|
| 1305 |
friend basic_istream<charT, traits>&
|
| 1306 |
+
operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x); // hosted
|
| 1307 |
|
| 1308 |
private:
|
| 1309 |
Engine e; // exposition only
|
| 1310 |
};
|
| 1311 |
+
}
|
| 1312 |
```
|
| 1313 |
|
| 1314 |
The following relations shall hold: `0 < w` and
|
| 1315 |
`w <= numeric_limits<result_type>::digits`.
|
| 1316 |
|
|
|
|
| 1342 |
namespace std {
|
| 1343 |
template<class Engine, size_t k>
|
| 1344 |
class shuffle_order_engine {
|
| 1345 |
public:
|
| 1346 |
// types
|
| 1347 |
+
using result_type = Engine::result_type;
|
| 1348 |
|
| 1349 |
// engine characteristics
|
| 1350 |
static constexpr size_t table_size = k;
|
| 1351 |
static constexpr result_type min() { return Engine::min(); }
|
| 1352 |
static constexpr result_type max() { return Engine::max(); }
|
|
|
|
| 1493 |
inexpert, and/or lightweight use. Because different implementations can
|
| 1494 |
select different underlying engine types, code that uses this `typedef`
|
| 1495 |
need not generate identical sequences across
|
| 1496 |
implementations. — *end note*]
|
| 1497 |
|
| 1498 |
+
``` cpp
|
| 1499 |
+
using philox4x32 =
|
| 1500 |
+
philox_engine<uint_fast32_t, 32, 4, 10,
|
| 1501 |
+
0xCD9E8D57, 0x9E3779B9, 0xD2511F53, 0xBB67AE85>;
|
| 1502 |
+
```
|
| 1503 |
+
|
| 1504 |
+
*Required behavior:* The 10000ᵗʰ consecutive invocation a
|
| 1505 |
+
default-constructed object of type `philox4x32` produces the value
|
| 1506 |
+
1955073260.
|
| 1507 |
+
|
| 1508 |
+
``` cpp
|
| 1509 |
+
using philox4x64 =
|
| 1510 |
+
philox_engine<uint_fast64_t, 64, 4, 10,
|
| 1511 |
+
0xCA5A826395121157, 0x9E3779B97F4A7C15, 0xD2E7470EE14C6C93, 0xBB67AE8584CAA73B>;
|
| 1512 |
+
```
|
| 1513 |
+
|
| 1514 |
+
*Required behavior:* The 10000ᵗʰ consecutive invocation a
|
| 1515 |
+
default-constructed object of type `philox4x64` produces the value
|
| 1516 |
+
3409172418970261260.
|
| 1517 |
+
|
| 1518 |
### Class `random_device` <a id="rand.device">[[rand.device]]</a>
|
| 1519 |
|
| 1520 |
A `random_device` uniform random bit generator produces nondeterministic
|
| 1521 |
random numbers.
|
| 1522 |
|
|
|
|
| 1744 |
*Throws:* What and when `OutputIterator` operations of `dest` throw.
|
| 1745 |
|
| 1746 |
#### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
|
| 1747 |
|
| 1748 |
``` cpp
|
| 1749 |
+
template<class RealType, size_t digits, class URBG>
|
| 1750 |
RealType generate_canonical(URBG& g);
|
| 1751 |
```
|
| 1752 |
|
| 1753 |
+
Let
|
|
|
|
|
|
|
|
|
|
| 1754 |
|
| 1755 |
+
- r be `numeric_limits<RealType>::radix`,
|
| 1756 |
+
- R be `g.max()` - `g.min()` + 1,
|
| 1757 |
+
- d be the smaller of `digits` and
|
| 1758 |
+
`numeric_limits<RealType>::digits`,[^6]
|
| 1759 |
+
- k be the smallest integer such that Rᵏ ≥ rᵈ, and
|
| 1760 |
+
- x be ⌊ Rᵏ / rᵈ ⌋.
|
| 1761 |
|
| 1762 |
+
An *attempt* is k invocations of `g()` to obtain values g₀, …, gₖ₋₁,
|
| 1763 |
+
respectively, and the calculation of a quantity S given by :
|
| 1764 |
+
|
| 1765 |
+
*Effects:* Attempts are made until S < xrᵈ.
|
| 1766 |
+
|
| 1767 |
+
[*Note 1*: When R is a power of r, precisely one attempt is
|
| 1768 |
+
made. — *end note*]
|
| 1769 |
+
|
| 1770 |
+
*Returns:* ⌊ S / x ⌋ / rᵈ.
|
| 1771 |
+
|
| 1772 |
+
[*Note 2*: The return value c satisfies 0 ≤ c < 1. — *end note*]
|
| 1773 |
|
| 1774 |
*Throws:* What and when `g` throws.
|
| 1775 |
|
| 1776 |
+
*Complexity:* Exactly k invocations of `g` per attempt.
|
|
|
|
| 1777 |
|
| 1778 |
+
[*Note 3*: If the values gᵢ produced by `g` are uniformly distributed,
|
|
|
|
|
|
|
|
|
|
| 1779 |
the instantiation’s results are distributed as uniformly as possible.
|
| 1780 |
Obtaining a value in this way can be a useful step in the process of
|
| 1781 |
transforming a value generated by a uniform random bit generator into a
|
| 1782 |
value that can be delivered by a random number
|
| 1783 |
distribution. — *end note*]
|
| 1784 |
|
| 1785 |
+
[*Note 4*: When R is a power of r, an implementation can avoid using an
|
| 1786 |
+
arithmetic type that is wider than the output when computing
|
| 1787 |
+
S. — *end note*]
|
| 1788 |
+
|
| 1789 |
### Random number distribution class templates <a id="rand.dist">[[rand.dist]]</a>
|
| 1790 |
|
| 1791 |
+
#### General <a id="rand.dist.general">[[rand.dist.general]]</a>
|
| 1792 |
|
| 1793 |
+
Each type instantiated from a class template specified in [[rand.dist]]
|
| 1794 |
+
meets the requirements of a random number distribution [[rand.req.dist]]
|
| 1795 |
+
type.
|
| 1796 |
|
| 1797 |
+
Descriptions are provided in [[rand.dist]] only for distribution
|
| 1798 |
+
operations that are not described in [[rand.req.dist]] or for operations
|
| 1799 |
+
where there is additional semantic information. In particular,
|
| 1800 |
+
declarations for copy constructors, for copy assignment operators, for
|
| 1801 |
+
streaming operators, and for equality and inequality operators are not
|
| 1802 |
+
shown in the synopses.
|
| 1803 |
|
| 1804 |
The algorithms for producing each of the specified distributions are
|
| 1805 |
*implementation-defined*.
|
| 1806 |
|
| 1807 |
The value of each probability density function p(z) and of each discrete
|
|
|
|
| 1812 |
|
| 1813 |
##### Class template `uniform_int_distribution` <a id="rand.dist.uni.int">[[rand.dist.uni.int]]</a>
|
| 1814 |
|
| 1815 |
A `uniform_int_distribution` random number distribution produces random
|
| 1816 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 1817 |
+
probability function in .
|
| 1818 |
|
| 1819 |
``` cpp
|
| 1820 |
namespace std {
|
| 1821 |
template<class IntType = int>
|
| 1822 |
class uniform_int_distribution {
|
|
|
|
| 1849 |
result_type max() const;
|
| 1850 |
|
| 1851 |
// inserters and extractors
|
| 1852 |
template<class charT, class traits>
|
| 1853 |
friend basic_ostream<charT, traits>&
|
| 1854 |
+
operator<<(basic_ostream<charT, traits>& os, // hosted
|
| 1855 |
+
const uniform_int_distribution& x);
|
| 1856 |
template<class charT, class traits>
|
| 1857 |
friend basic_istream<charT, traits>&
|
| 1858 |
+
operator>>(basic_istream<charT, traits>& is, // hosted
|
| 1859 |
+
uniform_int_distribution& x);
|
| 1860 |
};
|
| 1861 |
}
|
| 1862 |
```
|
| 1863 |
|
| 1864 |
``` cpp
|
|
|
|
| 1886 |
|
| 1887 |
##### Class template `uniform_real_distribution` <a id="rand.dist.uni.real">[[rand.dist.uni.real]]</a>
|
| 1888 |
|
| 1889 |
A `uniform_real_distribution` random number distribution produces random
|
| 1890 |
numbers x, a ≤ x < b, distributed according to the constant probability
|
| 1891 |
+
density function in .
|
| 1892 |
|
| 1893 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 1894 |
`a == b`. — *end note*]
|
| 1895 |
|
| 1896 |
``` cpp
|
|
|
|
| 1964 |
#### Bernoulli distributions <a id="rand.dist.bern">[[rand.dist.bern]]</a>
|
| 1965 |
|
| 1966 |
##### Class `bernoulli_distribution` <a id="rand.dist.bern.bernoulli">[[rand.dist.bern.bernoulli]]</a>
|
| 1967 |
|
| 1968 |
A `bernoulli_distribution` random number distribution produces `bool`
|
| 1969 |
+
values b distributed according to the discrete probability function in .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1970 |
|
| 1971 |
``` cpp
|
| 1972 |
namespace std {
|
| 1973 |
class bernoulli_distribution {
|
| 1974 |
public:
|
|
|
|
| 2026 |
|
| 2027 |
##### Class template `binomial_distribution` <a id="rand.dist.bern.bin">[[rand.dist.bern.bin]]</a>
|
| 2028 |
|
| 2029 |
A `binomial_distribution` random number distribution produces integer
|
| 2030 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2031 |
+
in .
|
| 2032 |
|
| 2033 |
``` cpp
|
| 2034 |
namespace std {
|
| 2035 |
template<class IntType = int>
|
| 2036 |
class binomial_distribution {
|
|
|
|
| 2098 |
|
| 2099 |
##### Class template `geometric_distribution` <a id="rand.dist.bern.geo">[[rand.dist.bern.geo]]</a>
|
| 2100 |
|
| 2101 |
A `geometric_distribution` random number distribution produces integer
|
| 2102 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2103 |
+
in .
|
| 2104 |
|
| 2105 |
``` cpp
|
| 2106 |
namespace std {
|
| 2107 |
template<class IntType = int>
|
| 2108 |
class geometric_distribution {
|
|
|
|
| 2161 |
|
| 2162 |
##### Class template `negative_binomial_distribution` <a id="rand.dist.bern.negbin">[[rand.dist.bern.negbin]]</a>
|
| 2163 |
|
| 2164 |
A `negative_binomial_distribution` random number distribution produces
|
| 2165 |
random integers i ≥ 0 distributed according to the discrete probability
|
| 2166 |
+
function in .
|
|
|
|
| 2167 |
|
| 2168 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 2169 |
`p == 1`. — *end note*]
|
| 2170 |
|
| 2171 |
``` cpp
|
|
|
|
| 2239 |
|
| 2240 |
##### Class template `poisson_distribution` <a id="rand.dist.pois.poisson">[[rand.dist.pois.poisson]]</a>
|
| 2241 |
|
| 2242 |
A `poisson_distribution` random number distribution produces integer
|
| 2243 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2244 |
+
in .
|
| 2245 |
+
|
| 2246 |
+
The distribution parameter μ is also known as this distribution’s
|
| 2247 |
+
*mean*.
|
| 2248 |
|
| 2249 |
``` cpp
|
| 2250 |
+
namespace std {
|
| 2251 |
template<class IntType = int>
|
| 2252 |
+
class poisson_distribution {
|
|
|
|
| 2253 |
public:
|
| 2254 |
// types
|
| 2255 |
using result_type = IntType;
|
| 2256 |
using param_type = unspecified;
|
| 2257 |
|
|
|
|
| 2283 |
operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x);
|
| 2284 |
template<class charT, class traits>
|
| 2285 |
friend basic_istream<charT, traits>&
|
| 2286 |
operator>>(basic_istream<charT, traits>& is, poisson_distribution& x);
|
| 2287 |
};
|
| 2288 |
+
}
|
| 2289 |
```
|
| 2290 |
|
| 2291 |
``` cpp
|
| 2292 |
explicit poisson_distribution(double mean);
|
| 2293 |
```
|
|
|
|
| 2305 |
|
| 2306 |
##### Class template `exponential_distribution` <a id="rand.dist.pois.exp">[[rand.dist.pois.exp]]</a>
|
| 2307 |
|
| 2308 |
An `exponential_distribution` random number distribution produces random
|
| 2309 |
numbers x > 0 distributed according to the probability density function
|
| 2310 |
+
in .
|
| 2311 |
|
| 2312 |
``` cpp
|
| 2313 |
namespace std {
|
| 2314 |
template<class RealType = double>
|
| 2315 |
class exponential_distribution {
|
|
|
|
| 2368 |
|
| 2369 |
##### Class template `gamma_distribution` <a id="rand.dist.pois.gamma">[[rand.dist.pois.gamma]]</a>
|
| 2370 |
|
| 2371 |
A `gamma_distribution` random number distribution produces random
|
| 2372 |
numbers x > 0 distributed according to the probability density function
|
| 2373 |
+
in .
|
|
|
|
|
|
|
| 2374 |
|
| 2375 |
``` cpp
|
| 2376 |
namespace std {
|
| 2377 |
template<class RealType = double>
|
| 2378 |
class gamma_distribution {
|
|
|
|
| 2440 |
|
| 2441 |
##### Class template `weibull_distribution` <a id="rand.dist.pois.weibull">[[rand.dist.pois.weibull]]</a>
|
| 2442 |
|
| 2443 |
A `weibull_distribution` random number distribution produces random
|
| 2444 |
numbers x ≥ 0 distributed according to the probability density function
|
| 2445 |
+
in .
|
|
|
|
|
|
|
|
|
|
| 2446 |
|
| 2447 |
``` cpp
|
| 2448 |
namespace std {
|
| 2449 |
template<class RealType = double>
|
| 2450 |
class weibull_distribution {
|
|
|
|
| 2512 |
|
| 2513 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 2514 |
|
| 2515 |
An `extreme_value_distribution` random number distribution produces
|
| 2516 |
random numbers x distributed according to the probability density
|
| 2517 |
+
function in .[^7]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2518 |
|
| 2519 |
``` cpp
|
| 2520 |
namespace std {
|
| 2521 |
template<class RealType = double>
|
| 2522 |
class extreme_value_distribution {
|
|
|
|
| 2586 |
#### Normal distributions <a id="rand.dist.norm">[[rand.dist.norm]]</a>
|
| 2587 |
|
| 2588 |
##### Class template `normal_distribution` <a id="rand.dist.norm.normal">[[rand.dist.norm.normal]]</a>
|
| 2589 |
|
| 2590 |
A `normal_distribution` random number distribution produces random
|
| 2591 |
+
numbers x distributed according to the probability density function in .
|
| 2592 |
+
|
| 2593 |
+
The distribution parameters μ and σ are also known as this
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2594 |
distribution’s *mean* and *standard deviation*.
|
| 2595 |
|
| 2596 |
``` cpp
|
| 2597 |
namespace std {
|
| 2598 |
template<class RealType = double>
|
|
|
|
| 2661 |
|
| 2662 |
##### Class template `lognormal_distribution` <a id="rand.dist.norm.lognormal">[[rand.dist.norm.lognormal]]</a>
|
| 2663 |
|
| 2664 |
A `lognormal_distribution` random number distribution produces random
|
| 2665 |
numbers x > 0 distributed according to the probability density function
|
| 2666 |
+
in .
|
|
|
|
|
|
|
| 2667 |
|
| 2668 |
``` cpp
|
| 2669 |
namespace std {
|
| 2670 |
template<class RealType = double>
|
| 2671 |
class lognormal_distribution {
|
|
|
|
| 2733 |
|
| 2734 |
##### Class template `chi_squared_distribution` <a id="rand.dist.norm.chisq">[[rand.dist.norm.chisq]]</a>
|
| 2735 |
|
| 2736 |
A `chi_squared_distribution` random number distribution produces random
|
| 2737 |
numbers x > 0 distributed according to the probability density function
|
| 2738 |
+
in .
|
| 2739 |
|
| 2740 |
``` cpp
|
| 2741 |
namespace std {
|
| 2742 |
template<class RealType = double>
|
| 2743 |
class chi_squared_distribution {
|
|
|
|
| 2795 |
constructed.
|
| 2796 |
|
| 2797 |
##### Class template `cauchy_distribution` <a id="rand.dist.norm.cauchy">[[rand.dist.norm.cauchy]]</a>
|
| 2798 |
|
| 2799 |
A `cauchy_distribution` random number distribution produces random
|
| 2800 |
+
numbers x distributed according to the probability density function in .
|
|
|
|
| 2801 |
|
| 2802 |
``` cpp
|
| 2803 |
namespace std {
|
| 2804 |
template<class RealType = double>
|
| 2805 |
class cauchy_distribution {
|
|
|
|
| 2867 |
|
| 2868 |
##### Class template `fisher_f_distribution` <a id="rand.dist.norm.f">[[rand.dist.norm.f]]</a>
|
| 2869 |
|
| 2870 |
A `fisher_f_distribution` random number distribution produces random
|
| 2871 |
numbers x ≥ 0 distributed according to the probability density function
|
| 2872 |
+
in .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2873 |
|
| 2874 |
``` cpp
|
| 2875 |
namespace std {
|
| 2876 |
template<class RealType = double>
|
| 2877 |
class fisher_f_distribution {
|
|
|
|
| 2938 |
constructed.
|
| 2939 |
|
| 2940 |
##### Class template `student_t_distribution` <a id="rand.dist.norm.t">[[rand.dist.norm.t]]</a>
|
| 2941 |
|
| 2942 |
A `student_t_distribution` random number distribution produces random
|
| 2943 |
+
numbers x distributed according to the probability density function in .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2944 |
|
| 2945 |
``` cpp
|
| 2946 |
namespace std {
|
| 2947 |
template<class RealType = double>
|
| 2948 |
class student_t_distribution {
|
|
|
|
| 3003 |
|
| 3004 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 3005 |
|
| 3006 |
A `discrete_distribution` random number distribution produces random
|
| 3007 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 3008 |
+
function in .
|
| 3009 |
|
| 3010 |
Unless specified otherwise, the distribution parameters are calculated
|
| 3011 |
as: pₖ = {wₖ / S} for k = 0, …, n - 1, in which the values wₖ, commonly
|
| 3012 |
known as the *weights* , shall be non-negative, non-NaN, and
|
| 3013 |
non-infinity. Moreover, the following relation shall hold:
|
|
|
|
| 3082 |
requirements [[input.iterators]]. If `firstW == lastW`, let n = 1 and
|
| 3083 |
w₀ = 1. Otherwise, [`firstW`, `lastW`) forms a sequence w of length
|
| 3084 |
n > 0.
|
| 3085 |
|
| 3086 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 3087 |
+
probabilities given by the .
|
| 3088 |
|
| 3089 |
``` cpp
|
| 3090 |
discrete_distribution(initializer_list<double> wl);
|
| 3091 |
```
|
| 3092 |
|
|
|
|
| 3121 |
##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
|
| 3122 |
|
| 3123 |
A `piecewise_constant_distribution` random number distribution produces
|
| 3124 |
random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
|
| 3125 |
subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
|
| 3126 |
+
in .
|
|
|
|
| 3127 |
|
| 3128 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 3129 |
*interval boundaries* , shall satisfy the relation $b_i < b_{i + 1}$ for
|
| 3130 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n
|
| 3131 |
distribution parameters are calculated as:
|
|
|
|
| 3267 |
|
| 3268 |
##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
|
| 3269 |
|
| 3270 |
A `piecewise_linear_distribution` random number distribution produces
|
| 3271 |
random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
|
| 3272 |
+
[bᵢ, bᵢ₊₁) according to the probability density function in .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3273 |
|
| 3274 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 3275 |
*interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
|
| 3276 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
|
| 3277 |
distribution parameters are calculated as ρₖ = {wₖ / S} for k = 0, …, n,
|
|
|
|
| 3341 |
template<class InputIteratorB, class InputIteratorW>
|
| 3342 |
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 3343 |
InputIteratorW firstW);
|
| 3344 |
```
|
| 3345 |
|
| 3346 |
+
*Mandates:* Both of
|
| 3347 |
+
|
| 3348 |
+
- `is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>`
|
| 3349 |
+
- `is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>`
|
| 3350 |
+
|
| 3351 |
+
are `true`.
|
| 3352 |
|
| 3353 |
*Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
|
| 3354 |
*Cpp17InputIterator* requirements [[input.iterators]]. If
|
| 3355 |
`firstB == lastB` or `++firstB == lastB`, let n = 1, ρ₀ = ρ₁ = 1,
|
| 3356 |
b₀ = 0, and b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of
|
|
|
|
| 3430 |
document [[rand]] are often preferable to `rand`, because `rand`’s
|
| 3431 |
underlying algorithm is unspecified. Use of `rand` therefore continues
|
| 3432 |
to be non-portable, with unpredictable and oft-questionable quality and
|
| 3433 |
performance. — *end note*]
|
| 3434 |
|
| 3435 |
+
See also: ISO C 7.24.3
|
| 3436 |
|