This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

291
cppdraft/rand/adapt.md Normal file
View File

@@ -0,0 +1,291 @@
[rand.adapt]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#adapt)
### 29.5.5 Random number engine adaptor class templates [rand.adapt]
#### [29.5.5.1](#general) General [[rand.adapt.general]](rand.adapt.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3393)
Each type instantiated
from a class template specified in [rand.adapt]
meets the requirements
of a [random number engine adaptor](rand.req.adapt "29.5.3.5Random number engine adaptor requirements[rand.req.adapt]") type[.](#general-1.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3399)
Except where specified otherwise,
the complexity of each function
specified in [rand.adapt]
is constant[.](#general-2.sentence-1)
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3405)
Except where specified otherwise,
no function described in [rand.adapt]
throws an exception[.](#general-3.sentence-1)
[4](#general-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3410)
Every function described in [rand.adapt]
that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#general-4.sentence-1)
[5](#general-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3417)
Descriptions are provided in [rand.adapt]
only for adaptor operations
that are not described in subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements") or for operations where there is additional semantic information[.](#general-5.sentence-1)
In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#general-5.sentence-2)
[6](#general-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3429)
Each template specified in [rand.adapt]
requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#general-6.sentence-1)
A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#general-6.sentence-2)
#### [29.5.5.2](#disc) Class template discard_block_engine [[rand.adapt.disc]](rand.adapt.disc)
[1](#disc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3443)
A discard_block_engine random number engine adaptor
produces random numbers
selected from those produced by some base engine e[.](#disc-1.sentence-1)
The state xi of a discard_block_engine engine adaptor object x consists of the state ei of its base engine e and an additional integer n[.](#disc-1.sentence-2)
The size of the state is
the size of e's state plus 1[.](#disc-1.sentence-3)
[2](#disc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3454)
The transition algorithm
discards all but r>0 values
from each block of p ≥ r values delivered by e[.](#disc-2.sentence-1)
The state transition is performed as follows:
If n ≥ r,
advance the state of e from ei to ei+p−r and set n to 0[.](#disc-2.sentence-2)
In any case,
then increment n and advance e's then-current state ej to ej+1[.](#disc-2.sentence-3)
[3](#disc-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3467)
The generation algorithm
yields the value returned by the last invocation of e() while advancing e's state as described above[.](#disc-3.sentence-1)
[🔗](#lib:discard_block_engine_)
namespace std {template<class Engine, size_t p, size_t r>class discard_block_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t block_size = p; static constexpr size_t used_block = r; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions discard_block_engine(); explicit discard_block_engine(const Engine& e); explicit discard_block_engine(Engine&& e); explicit discard_block_engine(result_type s); template<class Sseq> explicit discard_block_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const discard_block_engine& x, const discard_block_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discard_block_engine& x); // hostedprivate: Engine e; // *exposition only* size_t n; // *exposition only*};}
[4](#disc-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3523)
The following relations shall hold: 0 < r and r <= p[.](#disc-4.sentence-1)
[5](#disc-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3529)
The textual representation
consists of
the textual representation of e followed by
the value of n[.](#disc-5.sentence-1)
[6](#disc-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3536)
In addition to its behavior
pursuant to subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements"),
each constructor that is not a copy constructor
sets n to 0[.](#disc-6.sentence-1)
#### [29.5.5.3](#ibits) Class template independent_bits_engine [[rand.adapt.ibits]](rand.adapt.ibits)
[1](#ibits-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3550)
An independent_bits_engine random number engine adaptor
combines random numbers
that are produced by some base engine e,
so as to produce random numbers
with a specified number of bits w[.](#ibits-1.sentence-1)
The state xi of an independent_bits_engine engine adaptor object x consists of
the state ei of its base engine e;
the size of the state is
the size of e's state[.](#ibits-1.sentence-2)
[2](#ibits-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3565)
The transition and generation algorithms
are described in terms
of the following integral constants:
- [(2.1)](#ibits-2.1)
Let R=e.max() - e.min() + 1 and m=⌊log2R⌋[.](#ibits-2.1.sentence-1)
- [(2.2)](#ibits-2.2)
With n as determined below,
let w0=⌊w/n⌋, n0=ˆ’wmodn, y0=2w0⌊R/2w0⌋,
and y1=2w0+1⌊R/2w0+1⌋[.](#ibits-2.2.sentence-1)
- [(2.3)](#ibits-2.3)
Let n=⌈w/m⌉ if and only if the relation ˆ’y0≤⌊y0/Œ‹ holds as a result[.](#ibits-2.3.sentence-1)
Otherwise let n=1+⌈w/m⌉[.](#ibits-2.3.sentence-2)
[*Note [1](#ibits-note-1)*:
The relation w=n0w0+(n−n0)(w0+1) always holds[.](#ibits-2.sentence-2)
— *end note*]
[3](#ibits-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3598)
The transition algorithm
is carried out by invoking e() as often as needed to obtain n0 values less than y0+e.min() and ˆ’n0 values less than y1+e.min()[.](#ibits-3.sentence-1)
[4](#ibits-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3605)
The generation algorithm
uses the values produced
while advancing the state as described above
to yield a quantity S obtained as if by the following algorithm:S = 0;for (k = 0; ‰ n0; k += 1) {do u = e() - e.min(); while (‰¥y0); S = 2w0â‹S+umod2w0;}for (k = n0; k ≠n; k += 1) {do u = e() - e.min(); while (‰¥y1); S = 2w0+1â‹S+umod2w0+1;}
[🔗](#lib:independent_bits_engine_)
namespace std {template<class Engine, size_t w, class UIntType>class independent_bits_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type min() { return 0; }static constexpr result_type max() { return 2w−1; }// constructors and seeding functions independent_bits_engine(); explicit independent_bits_engine(const Engine& e); explicit independent_bits_engine(Engine&& e); explicit independent_bits_engine(result_type s); template<class Sseq> explicit independent_bits_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const independent_bits_engine& x, const independent_bits_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x); // hostedprivate: Engine e; // *exposition only*};}
[5](#ibits-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3671)
The following relations shall hold: 0 < w and w <= numeric_limits<result_type>::digits[.](#ibits-5.sentence-1)
[6](#ibits-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3677)
The textual representation
consists of the textual representation of e[.](#ibits-6.sentence-1)
#### [29.5.5.4](#shuf) Class template shuffle_order_engine [[rand.adapt.shuf]](rand.adapt.shuf)
[1](#shuf-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3688)
A shuffle_order_engine random number engine adaptor
produces the same random numbers
that are produced by some base engine e,
but delivers them in a different sequence[.](#shuf-1.sentence-1)
The state xi of a shuffle_order_engine engine adaptor object x consists of
the state ei of its base engine e,
an additional value Y of the type delivered by e,
and
an additional sequence V of k values
also of the type delivered by e[.](#shuf-1.sentence-2)
The size of the state is
the size of e's state plus k+1[.](#shuf-1.sentence-3)
[2](#shuf-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3704)
The transition algorithm
permutes the values produced by e[.](#shuf-2.sentence-1)
The state transition is performed as follows:
- [(2.1)](#shuf-2.1)
Calculate an integer j=⌊‹(Y−emin)emax−emin+1⌋ [.](#shuf-2.1.sentence-1)
- [(2.2)](#shuf-2.2)
Set Y to Vj and then set Vj to e()[.](#shuf-2.2.sentence-1)
[3](#shuf-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3720)
The generation algorithm
yields the last value of Y produced while advancing e's state as described above[.](#shuf-3.sentence-1)
[🔗](#lib:shuffle_order_engine_)
namespace std {template<class Engine, size_t k>class shuffle_order_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t table_size = k; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions shuffle_order_engine(); explicit shuffle_order_engine(const Engine& e); explicit shuffle_order_engine(Engine&& e); explicit shuffle_order_engine(result_type s); template<class Sseq> explicit shuffle_order_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const shuffle_order_engine& x, const shuffle_order_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const shuffle_order_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, shuffle_order_engine& x); private: Engine e; // *exposition only* result_type V[k]; // *exposition only* result_type Y; // *exposition only*};}
[4](#shuf-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3776)
The following relation shall hold: 0 < k[.](#shuf-4.sentence-1)
[5](#shuf-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3780)
The textual representation
consists of
the textual representation of e,
followed by
the k values of V,
followed by
the value of Y[.](#shuf-5.sentence-1)
[6](#shuf-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3789)
In addition to its behavior
pursuant to subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements"),
each constructor that is not a copy constructor
initializes V[0], …, V[k - 1] and Y,
in that order,
with values returned by successive invocations of e()[.](#shuf-6.sentence-1)

View File

@@ -0,0 +1,72 @@
[rand.adapt.disc]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#adapt.disc)
### 29.5.5 Random number engine adaptor class templates [[rand.adapt]](rand.adapt#disc)
#### 29.5.5.2 Class template discard_block_engine [rand.adapt.disc]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3443)
A discard_block_engine random number engine adaptor
produces random numbers
selected from those produced by some base engine e[.](#1.sentence-1)
The state xi of a discard_block_engine engine adaptor object x consists of the state ei of its base engine e and an additional integer n[.](#1.sentence-2)
The size of the state is
the size of e's state plus 1[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3454)
The transition algorithm
discards all but r>0 values
from each block of p ≥ r values delivered by e[.](#2.sentence-1)
The state transition is performed as follows:
If n ≥ r,
advance the state of e from ei to ei+p−r and set n to 0[.](#2.sentence-2)
In any case,
then increment n and advance e's then-current state ej to ej+1[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3467)
The generation algorithm
yields the value returned by the last invocation of e() while advancing e's state as described above[.](#3.sentence-1)
[🔗](#lib:discard_block_engine_)
namespace std {template<class Engine, size_t p, size_t r>class discard_block_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t block_size = p; static constexpr size_t used_block = r; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions discard_block_engine(); explicit discard_block_engine(const Engine& e); explicit discard_block_engine(Engine&& e); explicit discard_block_engine(result_type s); template<class Sseq> explicit discard_block_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const discard_block_engine& x, const discard_block_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discard_block_engine& x); // hostedprivate: Engine e; // *exposition only* size_t n; // *exposition only*};}
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3523)
The following relations shall hold: 0 < r and r <= p[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3529)
The textual representation
consists of
the textual representation of e followed by
the value of n[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3536)
In addition to its behavior
pursuant to subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements"),
each constructor that is not a copy constructor
sets n to 0[.](#6.sentence-1)

View File

@@ -0,0 +1,63 @@
[rand.adapt.general]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#adapt.general)
### 29.5.5 Random number engine adaptor class templates [[rand.adapt]](rand.adapt#general)
#### 29.5.5.1 General [rand.adapt.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3393)
Each type instantiated
from a class template specified in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") meets the requirements
of a [random number engine adaptor](rand.req.adapt "29.5.3.5Random number engine adaptor requirements[rand.req.adapt]") type[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3399)
Except where specified otherwise,
the complexity of each function
specified in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") is constant[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3405)
Except where specified otherwise,
no function described in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") throws an exception[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3410)
Every function described in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3417)
Descriptions are provided in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") only for adaptor operations
that are not described in subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements") or for operations where there is additional semantic information[.](#5.sentence-1)
In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3429)
Each template specified in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates") requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#6.sentence-1)
A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#6.sentence-2)

View File

@@ -0,0 +1,86 @@
[rand.adapt.ibits]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#adapt.ibits)
### 29.5.5 Random number engine adaptor class templates [[rand.adapt]](rand.adapt#ibits)
#### 29.5.5.3 Class template independent_bits_engine [rand.adapt.ibits]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3550)
An independent_bits_engine random number engine adaptor
combines random numbers
that are produced by some base engine e,
so as to produce random numbers
with a specified number of bits w[.](#1.sentence-1)
The state xi of an independent_bits_engine engine adaptor object x consists of
the state ei of its base engine e;
the size of the state is
the size of e's state[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3565)
The transition and generation algorithms
are described in terms
of the following integral constants:
- [(2.1)](#2.1)
Let R=e.max() - e.min() + 1 and m=⌊log2R⌋[.](#2.1.sentence-1)
- [(2.2)](#2.2)
With n as determined below,
let w0=⌊w/n⌋, n0=n−wmodn, y0=2w0⌊R/2w0⌋,
and y1=2w0+1⌊R/2w0+1⌋[.](#2.2.sentence-1)
- [(2.3)](#2.3)
Let n=⌈w/m⌉ if and only if the relation R−y0≤⌊y0/n⌋ holds as a result[.](#2.3.sentence-1)
Otherwise let n=1+⌈w/m⌉[.](#2.3.sentence-2)
[*Note [1](#note-1)*:
The relation w=n0w0+(n−n0)(w0+1) always holds[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3598)
The transition algorithm
is carried out by invoking e() as often as needed to obtain n0 values less than y0+e.min() and n−n0 values less than y1+e.min()[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3605)
The generation algorithm
uses the values produced
while advancing the state as described above
to yield a quantity S obtained as if by the following algorithm:S = 0;for (k = 0; k≠n0; k += 1) {do u = e() - e.min(); while (u≥y0); S = 2w0â‹S+umod2w0;}for (k = n0; k ≠n; k += 1) {do u = e() - e.min(); while (u≥y1); S = 2w0+1â‹S+umod2w0+1;}
[🔗](#lib:independent_bits_engine_)
namespace std {template<class Engine, size_t w, class UIntType>class independent_bits_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type min() { return 0; }static constexpr result_type max() { return 2w−1; }// constructors and seeding functions independent_bits_engine(); explicit independent_bits_engine(const Engine& e); explicit independent_bits_engine(Engine&& e); explicit independent_bits_engine(result_type s); template<class Sseq> explicit independent_bits_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const independent_bits_engine& x, const independent_bits_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x); // hostedprivate: Engine e; // *exposition only*};}
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3671)
The following relations shall hold: 0 < w and w <= numeric_limits<result_type>::digits[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3677)
The textual representation
consists of the textual representation of e[.](#6.sentence-1)

View File

@@ -0,0 +1,85 @@
[rand.adapt.shuf]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#adapt.shuf)
### 29.5.5 Random number engine adaptor class templates [[rand.adapt]](rand.adapt#shuf)
#### 29.5.5.4 Class template shuffle_order_engine [rand.adapt.shuf]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3688)
A shuffle_order_engine random number engine adaptor
produces the same random numbers
that are produced by some base engine e,
but delivers them in a different sequence[.](#1.sentence-1)
The state xi of a shuffle_order_engine engine adaptor object x consists of
the state ei of its base engine e,
an additional value Y of the type delivered by e,
and
an additional sequence V of k values
also of the type delivered by e[.](#1.sentence-2)
The size of the state is
the size of e's state plus k+1[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3704)
The transition algorithm
permutes the values produced by e[.](#2.sentence-1)
The state transition is performed as follows:
- [(2.1)](#2.1)
Calculate an integer j=⌊‹(Y−emin)emax−emin+1⌋ [.](#2.1.sentence-1)
- [(2.2)](#2.2)
Set Y to Vj and then set Vj to e()[.](#2.2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3720)
The generation algorithm
yields the last value of Y produced while advancing e's state as described above[.](#3.sentence-1)
[🔗](#lib:shuffle_order_engine_)
namespace std {template<class Engine, size_t k>class shuffle_order_engine {public:// typesusing result_type = typename Engine::result_type; // engine characteristicsstatic constexpr size_t table_size = k; static constexpr result_type min() { return Engine::min(); }static constexpr result_type max() { return Engine::max(); }// constructors and seeding functions shuffle_order_engine(); explicit shuffle_order_engine(const Engine& e); explicit shuffle_order_engine(Engine&& e); explicit shuffle_order_engine(result_type s); template<class Sseq> explicit shuffle_order_engine(Sseq& q); void seed(); void seed(result_type s); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const shuffle_order_engine& x, const shuffle_order_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // property functionsconst Engine& base() const noexcept { return e; }// inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const shuffle_order_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, shuffle_order_engine& x); private: Engine e; // *exposition only* result_type V[k]; // *exposition only* result_type Y; // *exposition only*};}
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3776)
The following relation shall hold: 0 < k[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3780)
The textual representation
consists of
the textual representation of e,
followed by
the k values of V,
followed by
the value of Y[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3789)
In addition to its behavior
pursuant to subclause [[rand.req.adapt]](rand.req.adapt "29.5.3.5Random number engine adaptor requirements"),
each constructor that is not a copy constructor
initializes V[0], …, V[k - 1] and Y,
in that order,
with values returned by successive invocations of e()[.](#6.sentence-1)

97
cppdraft/rand/device.md Normal file
View File

@@ -0,0 +1,97 @@
[rand.device]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#device)
### 29.5.7 Class random_device [rand.device]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4027)
A random_device uniform random bit generator
produces nondeterministic random numbers[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4032)
If implementation limitations
prevent generating nondeterministic random numbers,
the implementation may employ a random number engine[.](#2.sentence-1)
[🔗](#lib:random_device_)
namespace std {class random_device {public:// typesusing result_type = unsigned int; // generator characteristicsstatic constexpr result_type min() { return numeric_limits<result_type>::min(); }static constexpr result_type max() { return numeric_limits<result_type>::max(); }// constructors random_device() : random_device(*implementation-defined*) {}explicit random_device(const string& token); // generating functions result_type operator()(); // property functionsdouble entropy() const noexcept; // no copy functions random_device(const random_device&) = delete; void operator=(const random_device&) = delete; };}
[🔗](#lib:random_device,constructor)
`explicit random_device(const string& token);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4074)
*Throws*: A value of an implementation-defined type
derived from exception if the random_device cannot be initialized[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4080)
*Remarks*: The semantics of the token parameter
and the token value used by the default constructor are implementation-defined[.](#4.sentence-1)[243](#footnote-243 "The parameter is intended to allow an implementation to differentiate between different sources of randomness.")
[🔗](#lib:entropy,random_device)
`double entropy() const noexcept;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4098)
*Returns*: If the implementation employs a random number engine,
returns 0.0[.](#5.sentence-1)
Otherwise, returns an entropy estimate[244](#footnote-244 "If a device has n states whose respective probabilities are �…�, the device entropy S is defined as S = - ∑�.") for the random numbers returned by operator(),
in the range min() to log2(max()+1)[.](#5.sentence-2)
[🔗](#lib:operator(),random_device)
`result_type operator()();
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4123)
*Returns*: A nondeterministic random value,
uniformly distributed
between min() and max() (inclusive)[.](#6.sentence-1)
It is implementation-defined
how these values are generated[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4131)
*Throws*: A value of an implementation-defined
type derived from exception if a random number cannot be obtained[.](#7.sentence-1)
[243)](#footnote-243)[243)](#footnoteref-243)
The parameter is intended
to allow an implementation to differentiate
between different sources of randomness[.](#footnote-243.sentence-1)
[244)](#footnote-244)[244)](#footnoteref-244)
If a device has n states
whose respective probabilities are P0,…,Pn−1,
the device entropy S is defined as
S=−∑ˆ’1i=0Piâ‹logPi[.](#footnote-244.sentence-2)

1553
cppdraft/rand/dist.md Normal file

File diff suppressed because it is too large Load Diff

231
cppdraft/rand/dist/bern.md vendored Normal file
View File

@@ -0,0 +1,231 @@
[rand.dist.bern]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.bern)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#bern)
#### 29.5.9.3 Bernoulli distributions [rand.dist.bern]
#### [29.5.9.3.1](#bernoulli) Class bernoulli_distribution [[rand.dist.bern.bernoulli]](rand.dist.bern.bernoulli)
[1](#bernoulli-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4758)
A bernoulli_distribution random number distribution
produces bool values b distributed according to
the discrete probability function in Formula [29.4](#eq:rand.dist.bern.bernoulli)[.](#bernoulli-1.sentence-1)
P(b|p)={p if b=true1−p if b=false(29.4)
[🔗](#lib:bernoulli_distribution_)
namespace std {class bernoulli_distribution {public:// typesusing result_type = bool; using param_type = *unspecified*; // constructors and reset functions bernoulli_distribution() : bernoulli_distribution(0.5) {}explicit bernoulli_distribution(double p); explicit bernoulli_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const bernoulli_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, bernoulli_distribution& x); };}
[🔗](#lib:bernoulli_distribution,constructor)
`explicit bernoulli_distribution(double p);
`
[2](#bernoulli-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4820)
*Preconditions*: 0 ≤ p ≤ 1[.](#bernoulli-2.sentence-1)
[3](#bernoulli-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4824)
*Remarks*: p corresponds to the parameter of the distribution[.](#bernoulli-3.sentence-1)
[🔗](#lib:p,bernoulli_distribution)
`double p() const;
`
[4](#bernoulli-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4836)
*Returns*: The value of the p parameter
with which the object was constructed[.](#bernoulli-4.sentence-1)
#### [29.5.9.3.2](#bin) Class template binomial_distribution [[rand.dist.bern.bin]](rand.dist.bern.bin)
[1](#bin-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4848)
A binomial_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.5](#eq:rand.dist.bern.bin)[.](#bin-1.sentence-1)
P(i|t,p)=(ti)â‹piâ‹(1−p)t−i(29.5)
[🔗](#lib:binomial_distribution_)
namespace std {template<class IntType = int>class binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions binomial_distribution() : binomial_distribution(1) {}explicit binomial_distribution(IntType t, double p = 0.5); explicit binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const binomial_distribution& x, const binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType t() const; double p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, binomial_distribution& x); };}
[🔗](#lib:binomial_distribution,constructor)
`explicit binomial_distribution(IntType t, double p = 0.5);
`
[2](#bin-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4910)
*Preconditions*: 0 ≤ p ≤ 1 and 0 ≤ t[.](#bin-2.sentence-1)
[3](#bin-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4914)
*Remarks*: t and p correspond to the respective parameters of the distribution[.](#bin-3.sentence-1)
[🔗](#lib:t,binomial_distribution)
`IntType t() const;
`
[4](#bin-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4925)
*Returns*: The value of the t parameter
with which the object was constructed[.](#bin-4.sentence-1)
[🔗](#lib:p,binomial_distribution)
`double p() const;
`
[5](#bin-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4937)
*Returns*: The value of the p parameter
with which the object was constructed[.](#bin-5.sentence-1)
#### [29.5.9.3.3](#geo) Class template geometric_distribution [[rand.dist.bern.geo]](rand.dist.bern.geo)
[1](#geo-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4949)
A geometric_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.6](#eq:rand.dist.bern.geo)[.](#geo-1.sentence-1)
P(i|p)=pâ‹(1−p)i(29.6)
[🔗](#lib:geometric_distribution_)
namespace std {template<class IntType = int>class geometric_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions geometric_distribution() : geometric_distribution(0.5) {}explicit geometric_distribution(double p); explicit geometric_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const geometric_distribution& x, const geometric_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const geometric_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, geometric_distribution& x); };}
[🔗](#lib:geometric_distribution,constructor)
`explicit geometric_distribution(double p);
`
[2](#geo-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5009)
*Preconditions*: 0<p<1[.](#geo-2.sentence-1)
[3](#geo-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5013)
*Remarks*: p corresponds to the parameter of the distribution[.](#geo-3.sentence-1)
[🔗](#lib:p,geometric_distribution)
`double p() const;
`
[4](#geo-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5025)
*Returns*: The value of the p parameter
with which the object was constructed[.](#geo-4.sentence-1)
#### [29.5.9.3.4](#negbin) Class template negative_binomial_distribution [[rand.dist.bern.negbin]](rand.dist.bern.negbin)
[1](#negbin-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5038)
A negative_binomial_distribution random number distribution
produces random integers i ≥ 0 distributed according to
the discrete probability function in Formula [29.7](#eq:rand.dist.bern.negbin)[.](#negbin-1.sentence-1)
P(i|k,p)=(k+ˆ’1i)â‹pkâ‹(ˆ’p)i(29.7)
[*Note [1](#negbin-note-1)*:
This implies that P(i | k,p) is undefined when p == 1[.](#negbin-1.sentence-2)
— *end note*]
[🔗](#lib:negative_binomial_distribution_)
namespace std {template<class IntType = int>class negative_binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions negative_binomial_distribution() : negative_binomial_distribution(1) {}explicit negative_binomial_distribution(IntType k, double p = 0.5); explicit negative_binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const negative_binomial_distribution& x, const negative_binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType k() const; double p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const negative_binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, negative_binomial_distribution& x); };}
[🔗](#lib:negative_binomial_distribution,constructor)
`explicit negative_binomial_distribution(IntType k, double p = 0.5);
`
[2](#negbin-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5103)
*Preconditions*: 0<‰¤1 and 0<k[.](#negbin-2.sentence-1)
[3](#negbin-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5108)
*Remarks*: k and p correspond to the respective parameters of the distribution[.](#negbin-3.sentence-1)
[🔗](#lib:k,negative_binomial_distribution)
`IntType k() const;
`
[4](#negbin-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5120)
*Returns*: The value of the k parameter
with which the object was constructed[.](#negbin-4.sentence-1)
[🔗](#lib:p,negative_binomial_distribution)
`double p() const;
`
[5](#negbin-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5132)
*Returns*: The value of the p parameter
with which the object was constructed[.](#negbin-5.sentence-1)

57
cppdraft/rand/dist/bern/bernoulli.md vendored Normal file
View File

@@ -0,0 +1,57 @@
[rand.dist.bern.bernoulli]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.bern.bernoulli)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#bern.bernoulli)
#### 29.5.9.3 Bernoulli distributions [[rand.dist.bern]](rand.dist.bern#bernoulli)
#### 29.5.9.3.1 Class bernoulli_distribution [rand.dist.bern.bernoulli]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4758)
A bernoulli_distribution random number distribution
produces bool values b distributed according to
the discrete probability function in Formula [29.4](#eq:rand.dist.bern.bernoulli)[.](#1.sentence-1)
P(b|p)={p if b=true1−p if b=false(29.4)
[🔗](#lib:bernoulli_distribution_)
namespace std {class bernoulli_distribution {public:// typesusing result_type = bool; using param_type = *unspecified*; // constructors and reset functions bernoulli_distribution() : bernoulli_distribution(0.5) {}explicit bernoulli_distribution(double p); explicit bernoulli_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const bernoulli_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, bernoulli_distribution& x); };}
[🔗](#lib:bernoulli_distribution,constructor)
`explicit bernoulli_distribution(double p);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4820)
*Preconditions*: 0 ≤ p ≤ 1[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4824)
*Remarks*: p corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:p,bernoulli_distribution)
`double p() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4836)
*Returns*: The value of the p parameter
with which the object was constructed[.](#4.sentence-1)

69
cppdraft/rand/dist/bern/bin.md vendored Normal file
View File

@@ -0,0 +1,69 @@
[rand.dist.bern.bin]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.bern.bin)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#bern.bin)
#### 29.5.9.3 Bernoulli distributions [[rand.dist.bern]](rand.dist.bern#bin)
#### 29.5.9.3.2 Class template binomial_distribution [rand.dist.bern.bin]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4848)
A binomial_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.5](#eq:rand.dist.bern.bin)[.](#1.sentence-1)
P(i|t,p)=(ti)â‹piâ‹(1−p)t−i(29.5)
[🔗](#lib:binomial_distribution_)
namespace std {template<class IntType = int>class binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions binomial_distribution() : binomial_distribution(1) {}explicit binomial_distribution(IntType t, double p = 0.5); explicit binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const binomial_distribution& x, const binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType t() const; double p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, binomial_distribution& x); };}
[🔗](#lib:binomial_distribution,constructor)
`explicit binomial_distribution(IntType t, double p = 0.5);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4910)
*Preconditions*: 0 ≤ p ≤ 1 and 0 ≤ t[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4914)
*Remarks*: t and p correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:t,binomial_distribution)
`IntType t() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4925)
*Returns*: The value of the t parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:p,binomial_distribution)
`double p() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4937)
*Returns*: The value of the p parameter
with which the object was constructed[.](#5.sentence-1)

57
cppdraft/rand/dist/bern/geo.md vendored Normal file
View File

@@ -0,0 +1,57 @@
[rand.dist.bern.geo]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.bern.geo)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#bern.geo)
#### 29.5.9.3 Bernoulli distributions [[rand.dist.bern]](rand.dist.bern#geo)
#### 29.5.9.3.3 Class template geometric_distribution [rand.dist.bern.geo]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4949)
A geometric_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.6](#eq:rand.dist.bern.geo)[.](#1.sentence-1)
P(i|p)=pâ‹(1−p)i(29.6)
[🔗](#lib:geometric_distribution_)
namespace std {template<class IntType = int>class geometric_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions geometric_distribution() : geometric_distribution(0.5) {}explicit geometric_distribution(double p); explicit geometric_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const geometric_distribution& x, const geometric_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const geometric_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, geometric_distribution& x); };}
[🔗](#lib:geometric_distribution,constructor)
`explicit geometric_distribution(double p);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5009)
*Preconditions*: 0<p<1[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5013)
*Remarks*: p corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:p,geometric_distribution)
`double p() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5025)
*Returns*: The value of the p parameter
with which the object was constructed[.](#4.sentence-1)

75
cppdraft/rand/dist/bern/negbin.md vendored Normal file
View File

@@ -0,0 +1,75 @@
[rand.dist.bern.negbin]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.bern.negbin)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#bern.negbin)
#### 29.5.9.3 Bernoulli distributions [[rand.dist.bern]](rand.dist.bern#negbin)
#### 29.5.9.3.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5038)
A negative_binomial_distribution random number distribution
produces random integers i ≥ 0 distributed according to
the discrete probability function in Formula [29.7](#eq:rand.dist.bern.negbin)[.](#1.sentence-1)
P(i|k,p)=(k+i−1i)â‹pkâ‹(1−p)i(29.7)
[*Note [1](#note-1)*:
This implies that P(i | k,p) is undefined when p == 1[.](#1.sentence-2)
— *end note*]
[🔗](#lib:negative_binomial_distribution_)
namespace std {template<class IntType = int>class negative_binomial_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions negative_binomial_distribution() : negative_binomial_distribution(1) {}explicit negative_binomial_distribution(IntType k, double p = 0.5); explicit negative_binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const negative_binomial_distribution& x, const negative_binomial_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions IntType k() const; double p() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const negative_binomial_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, negative_binomial_distribution& x); };}
[🔗](#lib:negative_binomial_distribution,constructor)
`explicit negative_binomial_distribution(IntType k, double p = 0.5);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5103)
*Preconditions*: 0<‰¤1 and 0<k[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5108)
*Remarks*: k and p correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:k,negative_binomial_distribution)
`IntType k() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5120)
*Returns*: The value of the k parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:p,negative_binomial_distribution)
`double p() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5132)
*Returns*: The value of the p parameter
with which the object was constructed[.](#5.sentence-1)

45
cppdraft/rand/dist/general.md vendored Normal file
View File

@@ -0,0 +1,45 @@
[rand.dist.general]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.general)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#general)
#### 29.5.9.1 General [rand.dist.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4486)
Each type instantiated
from a class template specified in [[rand.dist]](rand.dist "29.5.9Random number distribution class templates") meets the requirements
of a [random number distribution](rand.req.dist "29.5.3.6Random number distribution requirements[rand.req.dist]") type[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4492)
Descriptions are provided in [[rand.dist]](rand.dist "29.5.9Random number distribution class templates") only for distribution operations
that are not described in [[rand.req.dist]](rand.req.dist "29.5.3.6Random number distribution requirements") or for operations where there is additional semantic information[.](#2.sentence-1)
In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4504)
The algorithms for producing each
of the specified distributions areimplementation-defined[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4509)
The value of each probability density function p(z) and of each discrete probability function P(zi) specified in this subclause
is 0 everywhere outside its stated domain[.](#4.sentence-1)

351
cppdraft/rand/dist/norm.md vendored Normal file
View File

@@ -0,0 +1,351 @@
[rand.dist.norm]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm)
#### 29.5.9.5 Normal distributions [rand.dist.norm]
#### [29.5.9.5.1](#normal) Class template normal_distribution [[rand.dist.norm.normal]](rand.dist.norm.normal)
[1](#normal-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5663)
A normal_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.13](#eq:rand.dist.norm.normal)[.](#normal-1.sentence-1)
p(x|μ,σ)=1σ√€â‹exp(−(x−μ)22σ2)(29.13)
The distribution parameters μ and σ are also known as this distribution's [*mean*](#def:mean) and [*standard deviation*](#def:standard_deviation)[.](#normal-1.sentence-2)
[🔗](#lib:normal_distribution_)
namespace std {template<class RealType = double>class normal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions normal_distribution() : normal_distribution(0.0) {}explicit normal_distribution(RealType mean, RealType stddev = 1.0); explicit normal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const normal_distribution& x, const normal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType mean() const;
RealType stddev() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const normal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, normal_distribution& x); };}
[🔗](#lib:normal_distribution,constructor)
`explicit normal_distribution(RealType mean, RealType stddev = 1.0);
`
[2](#normal-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5733)
*Preconditions*: 0<stddev[.](#normal-2.sentence-1)
[3](#normal-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5737)
*Remarks*: mean and stddev correspond to the respective parameters of the distribution[.](#normal-3.sentence-1)
[🔗](#lib:mean,normal_distribution)
`RealType mean() const;
`
[4](#normal-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5749)
*Returns*: The value of the mean parameter
with which the object was constructed[.](#normal-4.sentence-1)
[🔗](#lib:stddev,normal_distribution)
`RealType stddev() const;
`
[5](#normal-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5761)
*Returns*: The value of the stddev parameter
with which the object was constructed[.](#normal-5.sentence-1)
#### [29.5.9.5.2](#lognormal) Class template lognormal_distribution [[rand.dist.norm.lognormal]](rand.dist.norm.lognormal)
[1](#lognormal-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5774)
A lognormal_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.14](#eq:rand.dist.norm.lognormal)[.](#lognormal-1.sentence-1)
p(x|m,s)=1sx√€â‹exp(−(lnx−m)22s2)(29.14)
[🔗](#lib:lognormal_distribution_)
namespace std {template<class RealType = double>class lognormal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions lognormal_distribution() : lognormal_distribution(0.0) {}explicit lognormal_distribution(RealType m, RealType s = 1.0); explicit lognormal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
RealType s() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const lognormal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, lognormal_distribution& x); };}
[🔗](#lib:lognormal_distribution,constructor)
`explicit lognormal_distribution(RealType m, RealType s = 1.0);
`
[2](#lognormal-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5836)
*Preconditions*: 0<s[.](#lognormal-2.sentence-1)
[3](#lognormal-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5840)
*Remarks*: m and s correspond to the respective parameters of the distribution[.](#lognormal-3.sentence-1)
[🔗](#lib:m,lognormal_distribution)
`RealType m() const;
`
[4](#lognormal-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5852)
*Returns*: The value of the m parameter
with which the object was constructed[.](#lognormal-4.sentence-1)
[🔗](#lib:s,lognormal_distribution)
`RealType s() const;
`
[5](#lognormal-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5864)
*Returns*: The value of the s parameter
with which the object was constructed[.](#lognormal-5.sentence-1)
#### [29.5.9.5.3](#chisq) Class template chi_squared_distribution [[rand.dist.norm.chisq]](rand.dist.norm.chisq)
[1](#chisq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5877)
A chi_squared_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.15](#eq:rand.dist.norm.chisq)[.](#chisq-1.sentence-1)
p(x|n)=x(n/2)−‹ˆ’x/2Γ(n/2)â‹2n/2(29.15)
[🔗](#lib:chi_squared_distribution_)
namespace std {template<class RealType = double>class chi_squared_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions chi_squared_distribution() : chi_squared_distribution(1.0) {}explicit chi_squared_distribution(RealType n); explicit chi_squared_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const chi_squared_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, chi_squared_distribution& x); };}
[🔗](#lib:chi_squared_distribution,constructor)
`explicit chi_squared_distribution(RealType n);
`
[2](#chisq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5936)
*Preconditions*: 0<n[.](#chisq-2.sentence-1)
[3](#chisq-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5940)
*Remarks*: n corresponds to the parameter of the distribution[.](#chisq-3.sentence-1)
[🔗](#lib:n,chi_squared_distribution)
`RealType n() const;
`
[4](#chisq-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5951)
*Returns*: The value of the n parameter
with which the object was constructed[.](#chisq-4.sentence-1)
#### [29.5.9.5.4](#cauchy) Class template cauchy_distribution [[rand.dist.norm.cauchy]](rand.dist.norm.cauchy)
[1](#cauchy-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5964)
A cauchy_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.16](#eq:rand.dist.norm.cauchy)[.](#cauchy-1.sentence-1)
p(x|a,b)=(πb(1+(ˆ’ab)2))−1(29.16)
[🔗](#lib:cauchy_distribution_)
namespace std {template<class RealType = double>class cauchy_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions cauchy_distribution() : cauchy_distribution(0.0) {}explicit cauchy_distribution(RealType a, RealType b = 1.0); explicit cauchy_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const cauchy_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, cauchy_distribution& x); };}
[🔗](#lib:cauchy_distribution,constructor)
`explicit cauchy_distribution(RealType a, RealType b = 1.0);
`
[2](#cauchy-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6025)
*Preconditions*: 0<b[.](#cauchy-2.sentence-1)
[3](#cauchy-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6029)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#cauchy-3.sentence-1)
[🔗](#lib:a,cauchy_distribution)
`RealType a() const;
`
[4](#cauchy-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6041)
*Returns*: The value of the a parameter
with which the object was constructed[.](#cauchy-4.sentence-1)
[🔗](#lib:b,cauchy_distribution)
`RealType b() const;
`
[5](#cauchy-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6053)
*Returns*: The value of the b parameter
with which the object was constructed[.](#cauchy-5.sentence-1)
#### [29.5.9.5.5](#f) Class template fisher_f_distribution [[rand.dist.norm.f]](rand.dist.norm.f)
[1](#f-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6066)
A fisher_f_distribution random number distribution
produces random numbers x ≥ 0 distributed according to
the probability density function in Formula [29.17](#eq:rand.dist.norm.f)[.](#f-1.sentence-1)
p(x|m,n)=Γ((m+n)/2)Γ(m/2)Γ(n/2)â‹(mn)m/‹x(m/2)−‹(1+mxn)−(m+n)/2(29.17)
[🔗](#lib:fisher_f_distribution_)
namespace std {template<class RealType = double>class fisher_f_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions fisher_f_distribution() : fisher_f_distribution(1.0) {}explicit fisher_f_distribution(RealType m, RealType n = 1.0); explicit fisher_f_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const fisher_f_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, fisher_f_distribution& x); };}
[🔗](#lib:fisher_f_distribution,constructor)
`explicit fisher_f_distribution(RealType m, RealType n = 1);
`
[2](#f-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6129)
*Preconditions*: 0<m and 0<n[.](#f-2.sentence-1)
[3](#f-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6133)
*Remarks*: m and n correspond to the respective parameters of the distribution[.](#f-3.sentence-1)
[🔗](#lib:m,fisher_f_distribution)
`RealType m() const;
`
[4](#f-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6145)
*Returns*: The value of the m parameter
with which the object was constructed[.](#f-4.sentence-1)
[🔗](#lib:n,fisher_f_distribution)
`RealType n() const;
`
[5](#f-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6157)
*Returns*: The value of the n parameter
with which the object was constructed[.](#f-5.sentence-1)
#### [29.5.9.5.6](#t) Class template student_t_distribution [[rand.dist.norm.t]](rand.dist.norm.t)
[1](#t-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6170)
A student_t_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.18](#eq:rand.dist.norm.t)[.](#t-1.sentence-1)
p(x|n)=ˆš€â‹Î“((n+1)/2)Γ(n/2)â‹(1+x2n)−(n+1)/2(29.18)
[🔗](#lib:student_t_distribution_)
namespace std {template<class RealType = double>class student_t_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions student_t_distribution() : student_t_distribution(1.0) {}explicit student_t_distribution(RealType n); explicit student_t_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const student_t_distribution& x, const student_t_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const student_t_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, student_t_distribution& x); };}
[🔗](#lib:student_t_distribution,constructor)
`explicit student_t_distribution(RealType n);
`
[2](#t-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6231)
*Preconditions*: 0<n[.](#t-2.sentence-1)
[3](#t-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6235)
*Remarks*: n corresponds to the parameter of the distribution[.](#t-3.sentence-1)
[🔗](#lib:mean,student_t_distribution)
`RealType n() const;
`
[4](#t-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6246)
*Returns*: The value of the n parameter
with which the object was constructed[.](#t-4.sentence-1)

70
cppdraft/rand/dist/norm/cauchy.md vendored Normal file
View File

@@ -0,0 +1,70 @@
[rand.dist.norm.cauchy]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.cauchy)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.cauchy)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#cauchy)
#### 29.5.9.5.4 Class template cauchy_distribution [rand.dist.norm.cauchy]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5964)
A cauchy_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.16](#eq:rand.dist.norm.cauchy)[.](#1.sentence-1)
p(x|a,b)=(πb(1+(x−ab)2))−1(29.16)
[🔗](#lib:cauchy_distribution_)
namespace std {template<class RealType = double>class cauchy_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions cauchy_distribution() : cauchy_distribution(0.0) {}explicit cauchy_distribution(RealType a, RealType b = 1.0); explicit cauchy_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const cauchy_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, cauchy_distribution& x); };}
[🔗](#lib:cauchy_distribution,constructor)
`explicit cauchy_distribution(RealType a, RealType b = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6025)
*Preconditions*: 0<b[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6029)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:a,cauchy_distribution)
`RealType a() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6041)
*Returns*: The value of the a parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:b,cauchy_distribution)
`RealType b() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6053)
*Returns*: The value of the b parameter
with which the object was constructed[.](#5.sentence-1)

57
cppdraft/rand/dist/norm/chisq.md vendored Normal file
View File

@@ -0,0 +1,57 @@
[rand.dist.norm.chisq]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.chisq)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.chisq)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#chisq)
#### 29.5.9.5.3 Class template chi_squared_distribution [rand.dist.norm.chisq]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5877)
A chi_squared_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.15](#eq:rand.dist.norm.chisq)[.](#1.sentence-1)
p(x|n)=x(n/2)−‹ˆ’x/2Γ(n/2)â‹2n/2(29.15)
[🔗](#lib:chi_squared_distribution_)
namespace std {template<class RealType = double>class chi_squared_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions chi_squared_distribution() : chi_squared_distribution(1.0) {}explicit chi_squared_distribution(RealType n); explicit chi_squared_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const chi_squared_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, chi_squared_distribution& x); };}
[🔗](#lib:chi_squared_distribution,constructor)
`explicit chi_squared_distribution(RealType n);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5936)
*Preconditions*: 0<n[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5940)
*Remarks*: n corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:n,chi_squared_distribution)
`RealType n() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5951)
*Returns*: The value of the n parameter
with which the object was constructed[.](#4.sentence-1)

70
cppdraft/rand/dist/norm/f.md vendored Normal file
View File

@@ -0,0 +1,70 @@
[rand.dist.norm.f]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.f)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.f)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#f)
#### 29.5.9.5.5 Class template fisher_f_distribution [rand.dist.norm.f]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6066)
A fisher_f_distribution random number distribution
produces random numbers x ≥ 0 distributed according to
the probability density function in Formula [29.17](#eq:rand.dist.norm.f)[.](#1.sentence-1)
p(x|m,n)=Γ((m+n)/2)Γ(m/2)Γ(n/2)â‹(mn)m/2â‹x(m/2)−‹(1+mxn)−(m+n)/2(29.17)
[🔗](#lib:fisher_f_distribution_)
namespace std {template<class RealType = double>class fisher_f_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions fisher_f_distribution() : fisher_f_distribution(1.0) {}explicit fisher_f_distribution(RealType m, RealType n = 1.0); explicit fisher_f_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const fisher_f_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, fisher_f_distribution& x); };}
[🔗](#lib:fisher_f_distribution,constructor)
`explicit fisher_f_distribution(RealType m, RealType n = 1);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6129)
*Preconditions*: 0<m and 0<n[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6133)
*Remarks*: m and n correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:m,fisher_f_distribution)
`RealType m() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6145)
*Returns*: The value of the m parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:n,fisher_f_distribution)
`RealType n() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6157)
*Returns*: The value of the n parameter
with which the object was constructed[.](#5.sentence-1)

70
cppdraft/rand/dist/norm/lognormal.md vendored Normal file
View File

@@ -0,0 +1,70 @@
[rand.dist.norm.lognormal]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.lognormal)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.lognormal)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#lognormal)
#### 29.5.9.5.2 Class template lognormal_distribution [rand.dist.norm.lognormal]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5774)
A lognormal_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.14](#eq:rand.dist.norm.lognormal)[.](#1.sentence-1)
p(x|m,s)=1sx√€â‹exp(−(lnx−m)22s2)(29.14)
[🔗](#lib:lognormal_distribution_)
namespace std {template<class RealType = double>class lognormal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions lognormal_distribution() : lognormal_distribution(0.0) {}explicit lognormal_distribution(RealType m, RealType s = 1.0); explicit lognormal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const;
RealType s() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const lognormal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, lognormal_distribution& x); };}
[🔗](#lib:lognormal_distribution,constructor)
`explicit lognormal_distribution(RealType m, RealType s = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5836)
*Preconditions*: 0<s[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5840)
*Remarks*: m and s correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:m,lognormal_distribution)
`RealType m() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5852)
*Returns*: The value of the m parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:s,lognormal_distribution)
`RealType s() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5864)
*Returns*: The value of the s parameter
with which the object was constructed[.](#5.sentence-1)

72
cppdraft/rand/dist/norm/normal.md vendored Normal file
View File

@@ -0,0 +1,72 @@
[rand.dist.norm.normal]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.normal)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.normal)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#normal)
#### 29.5.9.5.1 Class template normal_distribution [rand.dist.norm.normal]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5663)
A normal_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.13](#eq:rand.dist.norm.normal)[.](#1.sentence-1)
p(x|μ,σ)=1σ√€â‹exp(−(x−μ)22σ2)(29.13)
The distribution parameters μ and σ are also known as this distribution's [*mean*](#def:mean) and [*standard deviation*](#def:standard_deviation)[.](#1.sentence-2)
[🔗](#lib:normal_distribution_)
namespace std {template<class RealType = double>class normal_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions normal_distribution() : normal_distribution(0.0) {}explicit normal_distribution(RealType mean, RealType stddev = 1.0); explicit normal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const normal_distribution& x, const normal_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType mean() const;
RealType stddev() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const normal_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, normal_distribution& x); };}
[🔗](#lib:normal_distribution,constructor)
`explicit normal_distribution(RealType mean, RealType stddev = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5733)
*Preconditions*: 0<stddev[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5737)
*Remarks*: mean and stddev correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:mean,normal_distribution)
`RealType mean() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5749)
*Returns*: The value of the mean parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:stddev,normal_distribution)
`RealType stddev() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5761)
*Returns*: The value of the stddev parameter
with which the object was constructed[.](#5.sentence-1)

57
cppdraft/rand/dist/norm/t.md vendored Normal file
View File

@@ -0,0 +1,57 @@
[rand.dist.norm.t]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.norm.t)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#norm.t)
#### 29.5.9.5 Normal distributions [[rand.dist.norm]](rand.dist.norm#t)
#### 29.5.9.5.6 Class template student_t_distribution [rand.dist.norm.t]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6170)
A student_t_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.18](#eq:rand.dist.norm.t)[.](#1.sentence-1)
p(x|n)=1√€â‹Î“((n+1)/2)Γ(n/2)â‹(1+x2n)−(n+1)/2(29.18)
[🔗](#lib:student_t_distribution_)
namespace std {template<class RealType = double>class student_t_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions student_t_distribution() : student_t_distribution(1.0) {}explicit student_t_distribution(RealType n); explicit student_t_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const student_t_distribution& x, const student_t_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const student_t_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, student_t_distribution& x); };}
[🔗](#lib:student_t_distribution,constructor)
`explicit student_t_distribution(RealType n);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6231)
*Preconditions*: 0<n[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6235)
*Remarks*: n corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:mean,student_t_distribution)
`RealType n() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6246)
*Returns*: The value of the n parameter
with which the object was constructed[.](#4.sentence-1)

301
cppdraft/rand/dist/pois.md vendored Normal file
View File

@@ -0,0 +1,301 @@
[rand.dist.pois]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois)
#### 29.5.9.4 Poisson distributions [rand.dist.pois]
#### [29.5.9.4.1](#poisson) Class template poisson_distribution [[rand.dist.pois.poisson]](rand.dist.pois.poisson)
[1](#poisson-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5157)
A poisson_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.8](#eq:rand.dist.pois.poisson)[.](#poisson-1.sentence-1)
P(i|μ)=e−μμii!(29.8)
The distribution parameter μ is also known as this distribution's [*mean*](#def:mean)[.](#poisson-1.sentence-2)
[🔗](#lib:poisson_distribution_)
namespace std {template<class IntType = int>class poisson_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions poisson_distribution() : poisson_distribution(1.0) {}explicit poisson_distribution(double mean); explicit poisson_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const poisson_distribution& x, const poisson_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble mean() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, poisson_distribution& x); };}
[🔗](#lib:poisson_distribution,constructor)
`explicit poisson_distribution(double mean);
`
[2](#poisson-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5218)
*Preconditions*: 0<mean[.](#poisson-2.sentence-1)
[3](#poisson-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5222)
*Remarks*: mean corresponds to the parameter of the distribution[.](#poisson-3.sentence-1)
[🔗](#lib:mean,poisson_distribution)
`double mean() const;
`
[4](#poisson-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5233)
*Returns*: The value of the mean parameter
with which the object was constructed[.](#poisson-4.sentence-1)
#### [29.5.9.4.2](#exp) Class template exponential_distribution [[rand.dist.pois.exp]](rand.dist.pois.exp)
[1](#exp-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5245)
An exponential_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.9](#eq:rand.dist.pois.exp)[.](#exp-1.sentence-1)
p(x|λ)=λe−λx(29.9)
[🔗](#lib:exponential_distribution_)
namespace std {template<class RealType = double>class exponential_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions exponential_distribution() : exponential_distribution(1.0) {}explicit exponential_distribution(RealType lambda); explicit exponential_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const exponential_distribution& x, const exponential_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType lambda() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const exponential_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, exponential_distribution& x); };}
[🔗](#lib:exponential_distribution,constructor)
`explicit exponential_distribution(RealType lambda);
`
[2](#exp-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5305)
*Preconditions*: 0<lambda[.](#exp-2.sentence-1)
[3](#exp-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5309)
*Remarks*: lambda corresponds to the parameter of the distribution[.](#exp-3.sentence-1)
[🔗](#lib:lambda,exponential_distribution)
`RealType lambda() const;
`
[4](#exp-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5320)
*Returns*: The value of the lambda parameter
with which the object was constructed[.](#exp-4.sentence-1)
#### [29.5.9.4.3](#gamma) Class template gamma_distribution [[rand.dist.pois.gamma]](rand.dist.pois.gamma)
[1](#gamma-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5332)
A gamma_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.10](#eq:rand.dist.pois.gamma)[.](#gamma-1.sentence-1)
p(x|α,β)=e−x/ββαâ‹Î“(α)â‹xα−1(29.10)
[🔗](#lib:gamma_distribution_)
namespace std {template<class RealType = double>class gamma_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions gamma_distribution() : gamma_distribution(1.0) {}explicit gamma_distribution(RealType alpha, RealType beta = 1.0); explicit gamma_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const gamma_distribution& x, const gamma_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType alpha() const;
RealType beta() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const gamma_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, gamma_distribution& x); };}
[🔗](#lib:gamma_distribution,constructor)
`explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
`
[2](#gamma-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5394)
*Preconditions*: 0<alpha and 0<beta[.](#gamma-2.sentence-1)
[3](#gamma-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5398)
*Remarks*: alpha and beta correspond to the parameters of the distribution[.](#gamma-3.sentence-1)
[🔗](#lib:alpha,gamma_distribution)
`RealType alpha() const;
`
[4](#gamma-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5410)
*Returns*: The value of the alpha parameter
with which the object was constructed[.](#gamma-4.sentence-1)
[🔗](#lib:beta,gamma_distribution)
`RealType beta() const;
`
[5](#gamma-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5422)
*Returns*: The value of the beta parameter
with which the object was constructed[.](#gamma-5.sentence-1)
#### [29.5.9.4.4](#weibull) Class template weibull_distribution [[rand.dist.pois.weibull]](rand.dist.pois.weibull)
[1](#weibull-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5435)
A weibull_distribution random number distribution
produces random numbers x ≥ 0 distributed according to
the probability density function in Formula [29.11](#eq:rand.dist.pois.weibull)[.](#weibull-1.sentence-1)
p(x|a,b)=abâ‹(xb)ˆ’‹exp(−(xb)a)(29.11)
[🔗](#lib:weibull_distribution_)
namespace std {template<class RealType = double>class weibull_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions weibull_distribution() : weibull_distribution(1.0) {}explicit weibull_distribution(RealType a, RealType b = 1.0); explicit weibull_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const weibull_distribution& x, const weibull_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const weibull_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, weibull_distribution& x); };}
[🔗](#lib:weibull_distribution,constructor)
`explicit weibull_distribution(RealType a, RealType b = 1.0);
`
[2](#weibull-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5497)
*Preconditions*: 0<a and 0<b[.](#weibull-2.sentence-1)
[3](#weibull-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5501)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#weibull-3.sentence-1)
[🔗](#lib:a,weibull_distribution)
`RealType a() const;
`
[4](#weibull-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5513)
*Returns*: The value of the a parameter
with which the object was constructed[.](#weibull-4.sentence-1)
[🔗](#lib:b,weibull_distribution)
`RealType b() const;
`
[5](#weibull-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5525)
*Returns*: The value of the b parameter
with which the object was constructed[.](#weibull-5.sentence-1)
#### [29.5.9.4.5](#extreme) Class template extreme_value_distribution [[rand.dist.pois.extreme]](rand.dist.pois.extreme)
[1](#extreme-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5538)
An extreme_value_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.12](#eq:rand.dist.pois.extreme)[.](#extreme-1.sentence-1)[246](#footnote-246 "The distribution corresponding to this probability density function is also known (with a possible change of variable) as the Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I distribution.")
p(x|a,b)=1bâ‹exp(ˆ’xb−exp(ˆ’xb))(29.12)
[🔗](#lib:extreme_value_distribution_)
namespace std {template<class RealType = double>class extreme_value_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions extreme_value_distribution() : extreme_value_distribution(0.0) {}explicit extreme_value_distribution(RealType a, RealType b = 1.0); explicit extreme_value_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const extreme_value_distribution& x, const extreme_value_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const extreme_value_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, extreme_value_distribution& x); };}
[🔗](#lib:extreme_value_distribution,constructor)
`explicit extreme_value_distribution(RealType a, RealType b = 1.0);
`
[2](#extreme-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5610)
*Preconditions*: 0<b[.](#extreme-2.sentence-1)
[3](#extreme-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5614)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#extreme-3.sentence-1)
[🔗](#lib:a,extreme_value_distribution)
`RealType a() const;
`
[4](#extreme-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5626)
*Returns*: The value of the a parameter
with which the object was constructed[.](#extreme-4.sentence-1)
[🔗](#lib:b,extreme_value_distribution)
`RealType b() const;
`
[5](#extreme-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5638)
*Returns*: The value of the b parameter
with which the object was constructed[.](#extreme-5.sentence-1)
[246)](#footnote-246)[246)](#footnoteref-246)
The distribution corresponding to
this probability density function
is also known
(with a possible change of variable)
as the Gumbel Type I,
the log-Weibull,
or the Fisher-Tippett Type I
distribution[.](#footnote-246.sentence-1)

57
cppdraft/rand/dist/pois/exp.md vendored Normal file
View File

@@ -0,0 +1,57 @@
[rand.dist.pois.exp]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois.exp)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois.exp)
#### 29.5.9.4 Poisson distributions [[rand.dist.pois]](rand.dist.pois#exp)
#### 29.5.9.4.2 Class template exponential_distribution [rand.dist.pois.exp]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5245)
An exponential_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.9](#eq:rand.dist.pois.exp)[.](#1.sentence-1)
p(x|λ)=λe−λx(29.9)
[🔗](#lib:exponential_distribution_)
namespace std {template<class RealType = double>class exponential_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions exponential_distribution() : exponential_distribution(1.0) {}explicit exponential_distribution(RealType lambda); explicit exponential_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const exponential_distribution& x, const exponential_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType lambda() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const exponential_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, exponential_distribution& x); };}
[🔗](#lib:exponential_distribution,constructor)
`explicit exponential_distribution(RealType lambda);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5305)
*Preconditions*: 0<lambda[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5309)
*Remarks*: lambda corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:lambda,exponential_distribution)
`RealType lambda() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5320)
*Returns*: The value of the lambda parameter
with which the object was constructed[.](#4.sentence-1)

81
cppdraft/rand/dist/pois/extreme.md vendored Normal file
View File

@@ -0,0 +1,81 @@
[rand.dist.pois.extreme]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois.extreme)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois.extreme)
#### 29.5.9.4 Poisson distributions [[rand.dist.pois]](rand.dist.pois#extreme)
#### 29.5.9.4.5 Class template extreme_value_distribution [rand.dist.pois.extreme]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5538)
An extreme_value_distribution random number distribution
produces random numbers x distributed according to
the probability density function in Formula [29.12](#eq:rand.dist.pois.extreme)[.](#1.sentence-1)[246](#footnote-246 "The distribution corresponding to this probability density function is also known (with a possible change of variable) as the Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I distribution.")
p(x|a,b)=1bâ‹exp(a−xb−exp(a−xb))(29.12)
[🔗](#lib:extreme_value_distribution_)
namespace std {template<class RealType = double>class extreme_value_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions extreme_value_distribution() : extreme_value_distribution(0.0) {}explicit extreme_value_distribution(RealType a, RealType b = 1.0); explicit extreme_value_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const extreme_value_distribution& x, const extreme_value_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const extreme_value_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, extreme_value_distribution& x); };}
[🔗](#lib:extreme_value_distribution,constructor)
`explicit extreme_value_distribution(RealType a, RealType b = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5610)
*Preconditions*: 0<b[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5614)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:a,extreme_value_distribution)
`RealType a() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5626)
*Returns*: The value of the a parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:b,extreme_value_distribution)
`RealType b() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5638)
*Returns*: The value of the b parameter
with which the object was constructed[.](#5.sentence-1)
[246)](#footnote-246)[246)](#footnoteref-246)
The distribution corresponding to
this probability density function
is also known
(with a possible change of variable)
as the Gumbel Type I,
the log-Weibull,
or the Fisher-Tippett Type I
distribution[.](#footnote-246.sentence-1)

70
cppdraft/rand/dist/pois/gamma.md vendored Normal file
View File

@@ -0,0 +1,70 @@
[rand.dist.pois.gamma]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois.gamma)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois.gamma)
#### 29.5.9.4 Poisson distributions [[rand.dist.pois]](rand.dist.pois#gamma)
#### 29.5.9.4.3 Class template gamma_distribution [rand.dist.pois.gamma]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5332)
A gamma_distribution random number distribution
produces random numbers x>0 distributed according to
the probability density function in Formula [29.10](#eq:rand.dist.pois.gamma)[.](#1.sentence-1)
p(x|α,β)=e−x/ββαâ‹Î“(α)â‹xα−1(29.10)
[🔗](#lib:gamma_distribution_)
namespace std {template<class RealType = double>class gamma_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions gamma_distribution() : gamma_distribution(1.0) {}explicit gamma_distribution(RealType alpha, RealType beta = 1.0); explicit gamma_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const gamma_distribution& x, const gamma_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType alpha() const;
RealType beta() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const gamma_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, gamma_distribution& x); };}
[🔗](#lib:gamma_distribution,constructor)
`explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5394)
*Preconditions*: 0<alpha and 0<beta[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5398)
*Remarks*: alpha and beta correspond to the parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:alpha,gamma_distribution)
`RealType alpha() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5410)
*Returns*: The value of the alpha parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:beta,gamma_distribution)
`RealType beta() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5422)
*Returns*: The value of the beta parameter
with which the object was constructed[.](#5.sentence-1)

59
cppdraft/rand/dist/pois/poisson.md vendored Normal file
View File

@@ -0,0 +1,59 @@
[rand.dist.pois.poisson]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois.poisson)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois.poisson)
#### 29.5.9.4 Poisson distributions [[rand.dist.pois]](rand.dist.pois#poisson)
#### 29.5.9.4.1 Class template poisson_distribution [rand.dist.pois.poisson]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5157)
A poisson_distribution random number distribution
produces integer values i ≥ 0 distributed according to
the discrete probability function in Formula [29.8](#eq:rand.dist.pois.poisson)[.](#1.sentence-1)
P(i|μ)=e−μμii!(29.8)
The distribution parameter μ is also known as this distribution's [*mean*](#def:mean)[.](#1.sentence-2)
[🔗](#lib:poisson_distribution_)
namespace std {template<class IntType = int>class poisson_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions poisson_distribution() : poisson_distribution(1.0) {}explicit poisson_distribution(double mean); explicit poisson_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const poisson_distribution& x, const poisson_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functionsdouble mean() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, poisson_distribution& x); };}
[🔗](#lib:poisson_distribution,constructor)
`explicit poisson_distribution(double mean);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5218)
*Preconditions*: 0<mean[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5222)
*Remarks*: mean corresponds to the parameter of the distribution[.](#3.sentence-1)
[🔗](#lib:mean,poisson_distribution)
`double mean() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5233)
*Returns*: The value of the mean parameter
with which the object was constructed[.](#4.sentence-1)

70
cppdraft/rand/dist/pois/weibull.md vendored Normal file
View File

@@ -0,0 +1,70 @@
[rand.dist.pois.weibull]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.pois.weibull)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#pois.weibull)
#### 29.5.9.4 Poisson distributions [[rand.dist.pois]](rand.dist.pois#weibull)
#### 29.5.9.4.4 Class template weibull_distribution [rand.dist.pois.weibull]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5435)
A weibull_distribution random number distribution
produces random numbers x ≥ 0 distributed according to
the probability density function in Formula [29.11](#eq:rand.dist.pois.weibull)[.](#1.sentence-1)
p(x|a,b)=abâ‹(xb)a−‹exp(−(xb)a)(29.11)
[🔗](#lib:weibull_distribution_)
namespace std {template<class RealType = double>class weibull_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions weibull_distribution() : weibull_distribution(1.0) {}explicit weibull_distribution(RealType a, RealType b = 1.0); explicit weibull_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const weibull_distribution& x, const weibull_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const;
RealType b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const weibull_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, weibull_distribution& x); };}
[🔗](#lib:weibull_distribution,constructor)
`explicit weibull_distribution(RealType a, RealType b = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5497)
*Preconditions*: 0<a and 0<b[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5501)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:a,weibull_distribution)
`RealType a() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5513)
*Returns*: The value of the a parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:b,weibull_distribution)
`RealType b() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L5525)
*Returns*: The value of the b parameter
with which the object was constructed[.](#5.sentence-1)

519
cppdraft/rand/dist/samp.md vendored Normal file
View File

@@ -0,0 +1,519 @@
[rand.dist.samp]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.samp)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#samp)
#### 29.5.9.6 Sampling distributions [rand.dist.samp]
#### [29.5.9.6.1](#discrete) Class template discrete_distribution [[rand.dist.samp.discrete]](rand.dist.samp.discrete)
[1](#discrete-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6273)
A discrete_distribution random number distribution
produces random integers i, 0≤i<n,
distributed according to
the discrete probability function in Formula [29.19](#eq:rand.dist.samp.discrete)[.](#discrete-1.sentence-1)
P(i|p0,…,pn−1)=pi(29.19)
[2](#discrete-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6282)
Unless specified otherwise,
the distribution parameters are calculated as:pk=wk/S for k=0,…,n−1,
in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#discrete-2.sentence-1)
Moreover, the following relation shall hold:0<S=w0+⋯+wn−1[.](#discrete-2.sentence-2)
[🔗](#lib:discrete_distribution_)
namespace std {template<class IntType = int>class discrete_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions discrete_distribution(); template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW);
discrete_distribution(initializer_list<double> wl); template<class UnaryOperation> discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw); explicit discrete_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const discrete_distribution& x, const discrete_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<double> probabilities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discrete_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discrete_distribution& x); };}
[🔗](#lib:discrete_distribution,constructor)
`discrete_distribution();
`
[3](#discrete-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6346)
*Effects*: Constructs a discrete_distribution object
with n=1 and p0=1[.](#discrete-3.sentence-1)
[*Note [1](#discrete-note-1)*:
Such an object will always deliver the value 0[.](#discrete-3.sentence-2)
— *end note*]
[🔗](#lib:discrete_distribution,constructor_)
`template<class InputIterator>
discrete_distribution(InputIterator firstW, InputIterator lastW);
`
[4](#discrete-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6363)
*Mandates*: is_convertible_v<iterator_traits<InputIterator>::value_type,double> is true[.](#discrete-4.sentence-1)
[5](#discrete-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6368)
*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#discrete-5.sentence-1)
If firstW == lastW,
let n=1 and w0=1[.](#discrete-5.sentence-2)
Otherwise, [firstW, lastW) forms a sequence w of length n>0[.](#discrete-5.sentence-3)
[6](#discrete-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6378)
*Effects*: Constructs a discrete_distribution object
with probabilities given by the Formula [29.19](#eq:rand.dist.samp.discrete)[.](#discrete-6.sentence-1)
[🔗](#lib:discrete_distribution,constructor__)
`discrete_distribution(initializer_list<double> wl);
`
[7](#discrete-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6391)
*Effects*: Same as discrete_distribution(wl.begin(), wl.end())[.](#discrete-7.sentence-1)
[🔗](#lib:discrete_distribution,constructor___)
`template<class UnaryOperation>
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
`
[8](#discrete-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6403)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#discrete-8.sentence-1)
[9](#discrete-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6407)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#discrete-9.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#discrete-9.sentence-2)
[10](#discrete-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6414)
*Effects*: Constructs a discrete_distribution object
with probabilities given by the formula above,
using the following values:
If nw=0,
let w0=1[.](#discrete-10.sentence-1)
Otherwise,
let wk=fw(xmin+kâ‹Î´+δ/2) for k=0,…,n−1[.](#discrete-10.sentence-2)
[11](#discrete-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6425)
*Complexity*: The number of invocations of fw does not exceed n[.](#discrete-11.sentence-1)
[🔗](#lib:probabilities,discrete_distribution)
`vector<double> probabilities() const;
`
[12](#discrete-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6436)
*Returns*: A vector<double> whose size member returns n and whose operator[] member returns pk when invoked with argument k for k=0,…,n−1[.](#discrete-12.sentence-1)
#### [29.5.9.6.2](#pconst) Class template piecewise_constant_distribution [[rand.dist.samp.pconst]](rand.dist.samp.pconst)
[1](#pconst-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6452)
A piecewise_constant_distribution random number distribution
produces random numbers x,b0≤x<bn,
uniformly distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.20](#eq:rand.dist.samp.pconst)[.](#pconst-1.sentence-1)
p(x|b0,…,bn,ρ0,…,ρˆ’1)=ρ , for bi≤x<bi+1(29.20)
[2](#pconst-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6464)
The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relationbi<bi+1 for i=0,…,n−1[.](#pconst-2.sentence-1)
Unless specified otherwise,
the remaining n distribution parameters are calculated as:
ρk=wkSâ‹(bk+1−bk) for k=0,…,n− , in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#pconst-2.sentence-2)
Moreover, the following relation shall hold: 0<S=w0+⋯+wn−1[.](#pconst-2.sentence-3)
[🔗](#lib:piecewise_constant_distribution_)
namespace std {template<class RealType = double>class piecewise_constant_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_constant_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW); template<class UnaryOperation> piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
UnaryOperation fw); explicit piecewise_constant_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_constant_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_constant_distribution& x); };}
[🔗](#lib:piecewise_constant_distribution,constructor)
`piecewise_constant_distribution();
`
[3](#pconst-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6538)
*Effects*: Constructs a piecewise_constant_distribution object
with n=1, ρ0=1, b0=0,
and b1=1[.](#pconst-3.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor_)
`template<class InputIteratorB, class InputIteratorW>
piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
`
[4](#pconst-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6556)
*Mandates*: Both of
- [(4.1)](#pconst-4.1)
is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>
- [(4.2)](#pconst-4.2)
is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>
are true[.](#pconst-4.sentence-1)
[5](#pconst-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6565)
*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#pconst-5.sentence-1)
If firstB == lastB or ++firstB == lastB,
let n=1, w0=1, b0=0,
and b1=1[.](#pconst-5.sentence-2)
Otherwise, [firstB, lastB) forms a sequence b of length n+1,
the length of the sequence w starting from firstW is at least n,
and any wk for k ≥ n are ignored by the distribution[.](#pconst-5.sentence-3)
[6](#pconst-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6583)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters as specified above[.](#pconst-6.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor__)
`template<class UnaryOperation>
piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`
[7](#pconst-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6597)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#pconst-7.sentence-1)
[8](#pconst-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6601)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters taken or calculated
from the following values:
If bl.size()<2,
let n=1, w0=1, b0=0,
and b1=1[.](#pconst-8.sentence-1)
Otherwise,
let [bl.begin(), bl.end()) form a sequence b0,…,bn,
and
let wk=fw((bk+1+bk)/2) for k=0,…,n−1[.](#pconst-8.sentence-2)
[9](#pconst-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6618)
*Complexity*: The number of invocations of fw does not exceed n[.](#pconst-9.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor___)
`template<class UnaryOperation>
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`
[10](#pconst-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6631)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#pconst-10.sentence-1)
[11](#pconst-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6635)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#pconst-11.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#pconst-11.sentence-2)
[12](#pconst-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6641)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters taken or calculated
from the following values:
Let bk=xmin+kâ‹Î´ for k=0,…,n,
and wk=fw(bk+δ/2) for k=0,…,n−1[.](#pconst-12.sentence-1)
[13](#pconst-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6649)
*Complexity*: The number of invocations of fw does not exceed n[.](#pconst-13.sentence-1)
[🔗](#lib:intervals,piecewise_constant_distribution)
`vector<result_type> intervals() const;
`
[14](#pconst-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6660)
*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n[.](#pconst-14.sentence-1)
[🔗](#lib:densities,piecewise_constant_distribution)
`vector<result_type> densities() const;
`
[15](#pconst-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6674)
*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns ρk when invoked with argument k for k=0,…,n−1[.](#pconst-15.sentence-1)
#### [29.5.9.6.3](#plinear) Class template piecewise_linear_distribution [[rand.dist.samp.plinear]](rand.dist.samp.plinear)
[1](#plinear-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6690)
A piecewise_linear_distribution random number distribution
produces random numbers x,b0≤x<bn,
distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.21](#eq:rand.dist.samp.plinear)[.](#plinear-1.sentence-1)
p(x|b0,…,bn,ρ0,…,ρn)=ρ‹bi+ˆ’xbi+ˆ’bi+ρi+‹ˆ’bibi+ˆ’bi , for bi≤x<bi+1.(29.21)
[2](#plinear-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6704)
The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relation bi<bi+1 for i=0,…,n−1[.](#plinear-2.sentence-1)
Unless specified otherwise,
the remaining n+1 distribution parameters are calculated asρk=wk/S for k=0,…,n, in which the values wk,
commonly known as the [*weights at boundaries*](#def:weights_at_boundaries), shall be non-negative, non-NaN, and non-infinity[.](#plinear-2.sentence-2)
Moreover, the following relation shall hold:
0<S=12⋈’ˆ‘k=0(wk+wk+1)â‹(bk+1−bk) [.](#plinear-2.sentence-3)
[🔗](#lib:piecewise_linear_distribution_)
namespace std {template<class RealType = double>class piecewise_linear_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_linear_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW); template<class UnaryOperation> piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); explicit piecewise_linear_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_linear_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_linear_distribution& x); };}
[🔗](#lib:piecewise_linear_distribution,constructor)
`piecewise_linear_distribution();
`
[3](#plinear-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6774)
*Effects*: Constructs a piecewise_linear_distribution object
with n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#plinear-3.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor_)
`template<class InputIteratorB, class InputIteratorW>
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
`
[4](#plinear-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6791)
*Mandates*: Both of
- [(4.1)](#plinear-4.1)
is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>
- [(4.2)](#plinear-4.2)
is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>
are true[.](#plinear-4.sentence-1)
[5](#plinear-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6800)
*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#plinear-5.sentence-1)
If firstB == lastB or ++firstB == lastB,
let n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#plinear-5.sentence-2)
Otherwise, [firstB, lastB) forms a sequence b of length n+1,
the length of the sequence w starting from firstW is at least n+1,
and any wk for k≥n+1 are ignored by the distribution[.](#plinear-5.sentence-3)
[6](#plinear-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6818)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters as specified above[.](#plinear-6.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor__)
`template<class UnaryOperation>
piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`
[7](#plinear-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6832)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#plinear-7.sentence-1)
[8](#plinear-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6836)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters taken or calculated
from the following values:
If bl.size()<2,
let n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#plinear-8.sentence-1)
Otherwise,
let [bl.begin(), bl.end()) form a sequence b0,…,bn,
and
let wk=fw(bk) for k=0,…,n[.](#plinear-8.sentence-2)
[9](#plinear-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6853)
*Complexity*: The number of invocations of fw does not exceed n+1[.](#plinear-9.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor___)
`template<class UnaryOperation>
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`
[10](#plinear-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6866)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#plinear-10.sentence-1)
[11](#plinear-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6870)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#plinear-11.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#plinear-11.sentence-2)
[12](#plinear-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6876)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters taken or calculated
from the following values:
Let bk=xmin+kâ‹Î´ for k=0,…,n,
and wk=fw(bk) for k=0,…,n[.](#plinear-12.sentence-1)
[13](#plinear-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6884)
*Complexity*: The number of invocations of fw does not exceed n+1[.](#plinear-13.sentence-1)
[🔗](#lib:intervals,piecewise_linear_distribution)
`vector<result_type> intervals() const;
`
[14](#plinear-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6895)
*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n[.](#plinear-14.sentence-1)
[🔗](#lib:densities,piecewise_linear_distribution)
`vector<result_type> densities() const;
`
[15](#plinear-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6909)
*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns ρk when invoked with argument k for k=0,…,n[.](#plinear-15.sentence-1)

150
cppdraft/rand/dist/samp/discrete.md vendored Normal file
View File

@@ -0,0 +1,150 @@
[rand.dist.samp.discrete]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.samp.discrete)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#samp.discrete)
#### 29.5.9.6 Sampling distributions [[rand.dist.samp]](rand.dist.samp#discrete)
#### 29.5.9.6.1 Class template discrete_distribution [rand.dist.samp.discrete]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6273)
A discrete_distribution random number distribution
produces random integers i, 0≤i<n,
distributed according to
the discrete probability function in Formula [29.19](#eq:rand.dist.samp.discrete)[.](#1.sentence-1)
P(i|p0,…,pn−1)=pi(29.19)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6282)
Unless specified otherwise,
the distribution parameters are calculated as:pk=wk/S for k=0,…,n−1,
in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#2.sentence-1)
Moreover, the following relation shall hold:0<S=w0+⋯+wn−1[.](#2.sentence-2)
[🔗](#lib:discrete_distribution_)
namespace std {template<class IntType = int>class discrete_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructor and reset functions discrete_distribution(); template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW);
discrete_distribution(initializer_list<double> wl); template<class UnaryOperation> discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw); explicit discrete_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const discrete_distribution& x, const discrete_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<double> probabilities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const discrete_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, discrete_distribution& x); };}
[🔗](#lib:discrete_distribution,constructor)
`discrete_distribution();
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6346)
*Effects*: Constructs a discrete_distribution object
with n=1 and p0=1[.](#3.sentence-1)
[*Note [1](#note-1)*:
Such an object will always deliver the value 0[.](#3.sentence-2)
— *end note*]
[🔗](#lib:discrete_distribution,constructor_)
`template<class InputIterator>
discrete_distribution(InputIterator firstW, InputIterator lastW);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6363)
*Mandates*: is_convertible_v<iterator_traits<InputIterator>::value_type,double> is true[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6368)
*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#5.sentence-1)
If firstW == lastW,
let n=1 and w0=1[.](#5.sentence-2)
Otherwise, [firstW, lastW) forms a sequence w of length n>0[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6378)
*Effects*: Constructs a discrete_distribution object
with probabilities given by the Formula [29.19](#eq:rand.dist.samp.discrete)[.](#6.sentence-1)
[🔗](#lib:discrete_distribution,constructor__)
`discrete_distribution(initializer_list<double> wl);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6391)
*Effects*: Same as discrete_distribution(wl.begin(), wl.end())[.](#7.sentence-1)
[🔗](#lib:discrete_distribution,constructor___)
`template<class UnaryOperation>
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6403)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6407)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#9.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6414)
*Effects*: Constructs a discrete_distribution object
with probabilities given by the formula above,
using the following values:
If nw=0,
let w0=1[.](#10.sentence-1)
Otherwise,
let wk=fw(xmin+kâ‹Î´+δ/2) for k=0,…,n−1[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6425)
*Complexity*: The number of invocations of fw does not exceed n[.](#11.sentence-1)
[🔗](#lib:probabilities,discrete_distribution)
`vector<double> probabilities() const;
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6436)
*Returns*: A vector<double> whose size member returns n and whose operator[] member returns pk when invoked with argument k for k=0,…,n−1[.](#12.sentence-1)

194
cppdraft/rand/dist/samp/pconst.md vendored Normal file
View File

@@ -0,0 +1,194 @@
[rand.dist.samp.pconst]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.samp.pconst)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#samp.pconst)
#### 29.5.9.6 Sampling distributions [[rand.dist.samp]](rand.dist.samp#pconst)
#### 29.5.9.6.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6452)
A piecewise_constant_distribution random number distribution
produces random numbers x,b0≤x<bn,
uniformly distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.20](#eq:rand.dist.samp.pconst)[.](#1.sentence-1)
p(x|b0,…,bn,ρ0,…,ρˆ’1)=ρ , for bi≤x<bi+1(29.20)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6464)
The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relationbi<bi+1 for i=0,…,n−1[.](#2.sentence-1)
Unless specified otherwise,
the remaining n distribution parameters are calculated as:
ρk=wkSâ‹(bk+1−bk) for k=0,…,n− , in which the values wk,
commonly known as the [*weights*](#def:weights), shall be non-negative, non-NaN, and non-infinity[.](#2.sentence-2)
Moreover, the following relation shall hold: 0<S=w0+⋯+wn−1[.](#2.sentence-3)
[🔗](#lib:piecewise_constant_distribution_)
namespace std {template<class RealType = double>class piecewise_constant_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_constant_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW); template<class UnaryOperation> piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
UnaryOperation fw); explicit piecewise_constant_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_constant_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_constant_distribution& x); };}
[🔗](#lib:piecewise_constant_distribution,constructor)
`piecewise_constant_distribution();
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6538)
*Effects*: Constructs a piecewise_constant_distribution object
with n=1, ρ0=1, b0=0,
and b1=1[.](#3.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor_)
`template<class InputIteratorB, class InputIteratorW>
piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6556)
*Mandates*: Both of
- [(4.1)](#4.1)
is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>
- [(4.2)](#4.2)
is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>
are true[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6565)
*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#5.sentence-1)
If firstB == lastB or ++firstB == lastB,
let n=1, w0=1, b0=0,
and b1=1[.](#5.sentence-2)
Otherwise, [firstB, lastB) forms a sequence b of length n+1,
the length of the sequence w starting from firstW is at least n,
and any wk for k ≥ n are ignored by the distribution[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6583)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters as specified above[.](#6.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor__)
`template<class UnaryOperation>
piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6597)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6601)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters taken or calculated
from the following values:
If bl.size()<2,
let n=1, w0=1, b0=0,
and b1=1[.](#8.sentence-1)
Otherwise,
let [bl.begin(), bl.end()) form a sequence b0,…,bn,
and
let wk=fw((bk+1+bk)/2) for k=0,…,n−1[.](#8.sentence-2)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6618)
*Complexity*: The number of invocations of fw does not exceed n[.](#9.sentence-1)
[🔗](#lib:piecewise_constant_distribution,constructor___)
`template<class UnaryOperation>
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6631)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6635)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#11.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6641)
*Effects*: Constructs a piecewise_constant_distribution object
with parameters taken or calculated
from the following values:
Let bk=xmin+kâ‹Î´ for k=0,…,n,
and wk=fw(bk+δ/2) for k=0,…,n−1[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6649)
*Complexity*: The number of invocations of fw does not exceed n[.](#13.sentence-1)
[🔗](#lib:intervals,piecewise_constant_distribution)
`vector<result_type> intervals() const;
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6660)
*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n[.](#14.sentence-1)
[🔗](#lib:densities,piecewise_constant_distribution)
`vector<result_type> densities() const;
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6674)
*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns ρk when invoked with argument k for k=0,…,n−1[.](#15.sentence-1)

193
cppdraft/rand/dist/samp/plinear.md vendored Normal file
View File

@@ -0,0 +1,193 @@
[rand.dist.samp.plinear]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.samp.plinear)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#samp.plinear)
#### 29.5.9.6 Sampling distributions [[rand.dist.samp]](rand.dist.samp#plinear)
#### 29.5.9.6.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6690)
A piecewise_linear_distribution random number distribution
produces random numbers x,b0≤x<bn,
distributed over each subinterval[bi,bi+1) according to the probability density function in Formula [29.21](#eq:rand.dist.samp.plinear)[.](#1.sentence-1)
p(x|b0,…,bn,ρ0,…,ρn)=ρ‹bi+ˆ’xbi+ˆ’bi+ρi+‹ˆ’bibi+ˆ’bi , for bi≤x<bi+1.(29.21)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6704)
The n+1 distribution parameters bi,
also known as this distribution's [*interval boundaries*](#def:interval_boundaries), shall satisfy the relation bi<bi+1 for i=0,…,n−1[.](#2.sentence-1)
Unless specified otherwise,
the remaining n+1 distribution parameters are calculated asρk=wk/S for k=0,…,n, in which the values wk,
commonly known as the [*weights at boundaries*](#def:weights_at_boundaries), shall be non-negative, non-NaN, and non-infinity[.](#2.sentence-2)
Moreover, the following relation shall hold:
0<S=12⋈’ˆ‘k=0(wk+wk+1)â‹(bk+1−bk) [.](#2.sentence-3)
[🔗](#lib:piecewise_linear_distribution_)
namespace std {template<class RealType = double>class piecewise_linear_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructor and reset functions piecewise_linear_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW); template<class UnaryOperation> piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw); template<class UnaryOperation> piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); explicit piecewise_linear_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const piecewise_linear_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, piecewise_linear_distribution& x); };}
[🔗](#lib:piecewise_linear_distribution,constructor)
`piecewise_linear_distribution();
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6774)
*Effects*: Constructs a piecewise_linear_distribution object
with n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#3.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor_)
`template<class InputIteratorB, class InputIteratorW>
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6791)
*Mandates*: Both of
- [(4.1)](#4.1)
is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>
- [(4.2)](#4.2)
is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>
are true[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6800)
*Preconditions*: InputIteratorB and InputIteratorW each meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#5.sentence-1)
If firstB == lastB or ++firstB == lastB,
let n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#5.sentence-2)
Otherwise, [firstB, lastB) forms a sequence b of length n+1,
the length of the sequence w starting from firstW is at least n+1,
and any wk for k≥n+1 are ignored by the distribution[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6818)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters as specified above[.](#6.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor__)
`template<class UnaryOperation>
piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6832)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6836)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters taken or calculated
from the following values:
If bl.size()<2,
let n=1, ρ0=ρ1=1, b0=0,
and b1=1[.](#8.sentence-1)
Otherwise,
let [bl.begin(), bl.end()) form a sequence b0,…,bn,
and
let wk=fw(bk) for k=0,…,n[.](#8.sentence-2)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6853)
*Complexity*: The number of invocations of fw does not exceed n+1[.](#9.sentence-1)
[🔗](#lib:piecewise_linear_distribution,constructor___)
`template<class UnaryOperation>
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6866)
*Mandates*: is_invocable_r_v<double, UnaryOperation&, double> is true[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6870)
*Preconditions*: If nw=0, let n=1, otherwise let n=nw[.](#11.sentence-1)
The relation 0<δ=(xmax−xmin)/n holds[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6876)
*Effects*: Constructs a piecewise_linear_distribution object
with parameters taken or calculated
from the following values:
Let bk=xmin+kâ‹Î´ for k=0,…,n,
and wk=fw(bk) for k=0,…,n[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6884)
*Complexity*: The number of invocations of fw does not exceed n+1[.](#13.sentence-1)
[🔗](#lib:intervals,piecewise_linear_distribution)
`vector<result_type> intervals() const;
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6895)
*Returns*: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n[.](#14.sentence-1)
[🔗](#lib:densities,piecewise_linear_distribution)
`vector<result_type> densities() const;
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6909)
*Returns*: A vector<result_type> whose size member returns n and whose operator[] member returns ρk when invoked with argument k for k=0,…,n[.](#15.sentence-1)

139
cppdraft/rand/dist/uni.md vendored Normal file
View File

@@ -0,0 +1,139 @@
[rand.dist.uni]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.uni)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#uni)
#### 29.5.9.2 Uniform distributions [rand.dist.uni]
#### [29.5.9.2.1](#int) Class template uniform_int_distribution [[rand.dist.uni.int]](rand.dist.uni.int)
[1](#int-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4532)
A uniform_int_distribution random number distribution
produces random integers i,a ≤ i ≤ b,
distributed according to
the constant discrete probability function in Formula [29.2](#eq:rand.dist.uni.int)[.](#int-1.sentence-1)
P(i|a,b)=1/(b−a+1)(29.2)
[🔗](#lib:uniform_int_distribution_)
namespace std {template<class IntType = int>class uniform_int_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions uniform_int_distribution() : uniform_int_distribution(0) {}explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max()); explicit uniform_int_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
result_type b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst uniform_int_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted uniform_int_distribution& x); };}
[🔗](#lib:uniform_int_distribution,constructor)
`explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
`
[2](#int-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4597)
*Preconditions*: a ≤ b[.](#int-2.sentence-1)
[3](#int-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4601)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#int-3.sentence-1)
[🔗](#lib:a,uniform_int_distribution)
`result_type a() const;
`
[4](#int-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4613)
*Returns*: The value of the a parameter
with which the object was constructed[.](#int-4.sentence-1)
[🔗](#lib:b,uniform_int_distribution)
`result_type b() const;
`
[5](#int-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4625)
*Returns*: The value of the b parameter
with which the object was constructed[.](#int-5.sentence-1)
#### [29.5.9.2.2](#real) Class template uniform_real_distribution [[rand.dist.uni.real]](rand.dist.uni.real)
[1](#real-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4637)
A uniform_real_distribution random number distribution
produces random numbers x,a≤x<b,
distributed according to
the constant probability density function in Formula [29.3](#eq:rand.dist.uni.real)[.](#real-1.sentence-1)
p(x|a,b)=1/(ˆ’a)(29.3)
[*Note [1](#real-note-1)*:
This implies that p(x | a,b) is undefined when a == b[.](#real-1.sentence-2)
— *end note*]
[🔗](#lib:uniform_real_distribution_)
namespace std {template<class RealType = double>class uniform_real_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions uniform_real_distribution() : uniform_real_distribution(0.0) {}explicit uniform_real_distribution(RealType a, RealType b = 1.0); explicit uniform_real_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_real_distribution& x, const uniform_real_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
result_type b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const uniform_real_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, uniform_real_distribution& x); };}
[🔗](#lib:uniform_real_distribution,constructor)
`explicit uniform_real_distribution(RealType a, RealType b = 1.0);
`
[2](#real-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4703)
*Preconditions*: a ≤ b andb−‰¤numeric_limits<RealType>::max()[.](#real-2.sentence-1)
[3](#real-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4709)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#real-3.sentence-1)
[🔗](#lib:a,uniform_real_distribution)
`result_type a() const;
`
[4](#real-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4721)
*Returns*: The value of the a parameter
with which the object was constructed[.](#real-4.sentence-1)
[🔗](#lib:b,uniform_real_distribution)
`result_type b() const;
`
[5](#real-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4733)
*Returns*: The value of the b parameter
with which the object was constructed[.](#real-5.sentence-1)

71
cppdraft/rand/dist/uni/int.md vendored Normal file
View File

@@ -0,0 +1,71 @@
[rand.dist.uni.int]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.uni.int)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#uni.int)
#### 29.5.9.2 Uniform distributions [[rand.dist.uni]](rand.dist.uni#int)
#### 29.5.9.2.1 Class template uniform_int_distribution [rand.dist.uni.int]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4532)
A uniform_int_distribution random number distribution
produces random integers i,a ≤ i ≤ b,
distributed according to
the constant discrete probability function in Formula [29.2](#eq:rand.dist.uni.int)[.](#1.sentence-1)
P(i|a,b)=1/(b−a+1)(29.2)
[🔗](#lib:uniform_int_distribution_)
namespace std {template<class IntType = int>class uniform_int_distribution {public:// typesusing result_type = IntType; using param_type = *unspecified*; // constructors and reset functions uniform_int_distribution() : uniform_int_distribution(0) {}explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max()); explicit uniform_int_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
result_type b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst uniform_int_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted uniform_int_distribution& x); };}
[🔗](#lib:uniform_int_distribution,constructor)
`explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4597)
*Preconditions*: a ≤ b[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4601)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:a,uniform_int_distribution)
`result_type a() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4613)
*Returns*: The value of the a parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:b,uniform_int_distribution)
`result_type b() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4625)
*Returns*: The value of the b parameter
with which the object was constructed[.](#5.sentence-1)

77
cppdraft/rand/dist/uni/real.md vendored Normal file
View File

@@ -0,0 +1,77 @@
[rand.dist.uni.real]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#dist.uni.real)
### 29.5.9 Random number distribution class templates [[rand.dist]](rand.dist#uni.real)
#### 29.5.9.2 Uniform distributions [[rand.dist.uni]](rand.dist.uni#real)
#### 29.5.9.2.2 Class template uniform_real_distribution [rand.dist.uni.real]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4637)
A uniform_real_distribution random number distribution
produces random numbers x,a≤x<b,
distributed according to
the constant probability density function in Formula [29.3](#eq:rand.dist.uni.real)[.](#1.sentence-1)
p(x|a,b)=1/(ˆ’a)(29.3)
[*Note [1](#note-1)*:
This implies that p(x | a,b) is undefined when a == b[.](#1.sentence-2)
— *end note*]
[🔗](#lib:uniform_real_distribution_)
namespace std {template<class RealType = double>class uniform_real_distribution {public:// typesusing result_type = RealType; using param_type = *unspecified*; // constructors and reset functions uniform_real_distribution() : uniform_real_distribution(0.0) {}explicit uniform_real_distribution(RealType a, RealType b = 1.0); explicit uniform_real_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_real_distribution& x, const uniform_real_distribution& y); // generating functionstemplate<class URBG> result_type operator()(URBG& g); template<class URBG> result_type operator()(URBG& g, const param_type& parm); // property functions result_type a() const;
result_type b() const;
param_type param() const; void param(const param_type& parm);
result_type min() const;
result_type max() const; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const uniform_real_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, uniform_real_distribution& x); };}
[🔗](#lib:uniform_real_distribution,constructor)
`explicit uniform_real_distribution(RealType a, RealType b = 1.0);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4703)
*Preconditions*: a ≤ b andb−‰¤numeric_limits<RealType>::max()[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4709)
*Remarks*: a and b correspond to the respective parameters of the distribution[.](#3.sentence-1)
[🔗](#lib:a,uniform_real_distribution)
`result_type a() const;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4721)
*Returns*: The value of the a parameter
with which the object was constructed[.](#4.sentence-1)
[🔗](#lib:b,uniform_real_distribution)
`result_type b() const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4733)
*Returns*: The value of the b parameter
with which the object was constructed[.](#5.sentence-1)

646
cppdraft/rand/eng.md Normal file
View File

@@ -0,0 +1,646 @@
[rand.eng]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng)
### 29.5.4 Random number engine class templates [rand.eng]
#### [29.5.4.1](#general) General [[rand.eng.general]](rand.eng.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2595)
Each type instantiated
from a class template specified in [rand.eng]
meets the requirements
of a [random number engine](rand.req.eng "29.5.3.4Random number engine requirements[rand.req.eng]") type[.](#general-1.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2601)
Except where specified otherwise,
the complexity of each function
specified in [rand.eng]
is constant[.](#general-2.sentence-1)
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2607)
Except where specified otherwise,
no function described in [rand.eng]
throws an exception[.](#general-3.sentence-1)
[4](#general-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2612)
Every function described in [rand.eng]
that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#general-4.sentence-1)
[5](#general-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2619)
Descriptions are provided in [rand.eng]
only for engine operations
that are not described in [[rand.req.eng]](rand.req.eng "29.5.3.4Random number engine requirements") or for operations where there is additional semantic information[.](#general-5.sentence-1)
In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#general-5.sentence-2)
[6](#general-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2631)
Each template specified in [rand.eng]
requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#general-6.sentence-1)
A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#general-6.sentence-2)
[7](#general-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2639)
For every random number engine and for every random number engine adaptor X defined in [rand.eng] and in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates"):
- [(7.1)](#general-7.1)
if the constructortemplate<class Sseq> explicit X(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
constructor shall not participate in overload resolution;
- [(7.2)](#general-7.2)
if the member functiontemplate<class Sseq> void seed(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
function shall not participate in overload resolution[.](#general-7.sentence-1)
The extent to which an implementation determines that a type cannot be a seed sequence
is unspecified, except that as a minimum a type shall not qualify as a seed sequence
if it is implicitly convertible to X::result_type[.](#general-7.sentence-2)
#### [29.5.4.2](#lcong) Class template linear_congruential_engine [[rand.eng.lcong]](rand.eng.lcong)
[1](#lcong-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2670)
A linear_congruential_engine random number engine
produces unsigned integer random numbers[.](#lcong-1.sentence-1)
The state xi of a linear_congruential_engine object x is of size 1 and consists of a single integer[.](#lcong-1.sentence-2)
The transition algorithm
is a modular linear function of the formTA(xi)=(aâ‹xi+c)modm;
the generation algorithm
is GA(xi)=xi+1[.](#lcong-1.sentence-3)
[🔗](#lib:linear_congruential_engine_)
namespace std {template<class UIntType, UIntType a, UIntType c, UIntType m>class linear_congruential_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type multiplier = a; static constexpr result_type increment = c; static constexpr result_type modulus = m; static constexpr result_type min() { return c == 0u ? 1u: 0u; }static constexpr result_type max() { return m - 1u; }static constexpr result_type default_seed = 1u; // constructors and seeding functions linear_congruential_engine() : linear_congruential_engine(default_seed) {}explicit linear_congruential_engine(result_type s); template<class Sseq> explicit linear_congruential_engine(Sseq& q); void seed(result_type s = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const linear_congruential_engine& x, const linear_congruential_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst linear_congruential_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted linear_congruential_engine& x); };}
[2](#lcong-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2729)
If the template parameterm is 0,
the modulus m used throughout [[rand.eng.lcong]](#lcong "29.5.4.2Class template linear_­congruential_­engine") is numeric_limits<result_type>::max() plus 1[.](#lcong-2.sentence-1)
[*Note [1](#lcong-note-1)*:
m need not be representable
as a value of type result_type[.](#lcong-2.sentence-2)
— *end note*]
[3](#lcong-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2740)
If the template parameterm is not 0,
the following relations shall hold: a < m and c < m[.](#lcong-3.sentence-1)
[4](#lcong-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2748)
The textual representation
consists of
the value of xi[.](#lcong-4.sentence-1)
[🔗](#lib:linear_congruential_engine,constructor)
`explicit linear_congruential_engine(result_type s);
`
[5](#lcong-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2759)
*Effects*: If cmodm is 0 and smodm is 0,
sets the engine's state to 1,
otherwise sets the engine's state to smodm[.](#lcong-5.sentence-1)
[🔗](#lib:linear_congruential_engine,constructor_)
`template<class Sseq> explicit linear_congruential_engine(Sseq& q);
`
[6](#lcong-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2772)
*Effects*: With k=⌈log2m32⌉ and a an array (or equivalent)
of length k+3,
invokes q.generate(a+0, a+k+3) and then computes S=ˆ‘ˆ’1j=0aj+3â‹232j)modm[.](#lcong-6.sentence-1)
If cmodm is 0 and S is 0,
sets the engine's state to 1,
else sets the engine's state
to S[.](#lcong-6.sentence-2)
#### [29.5.4.3](#mers) Class template mersenne_twister_engine [[rand.eng.mers]](rand.eng.mers)
[1](#mers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2793)
A mersenne_twister_engine random number
engine[242](#footnote-242 "The name of this engine refers, in part, to a property of its period: For properly-selected values of the parameters, the period is closely related to a large Mersenne prime number.") produces unsigned integer random numbers
in the closed interval [0,2w−1][.](#mers-1.sentence-1)
The
statexi of a mersenne_twister_engine object x is of size n and consists of a sequence X of n values of the type delivered by x;
all subscripts applied to X are to be taken modulo n[.](#mers-1.sentence-2)
[2](#mers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2812)
The transition algorithm
employs a twisted generalized feedback shift register
defined by shift values n and m, a twist value r,
and a conditional xor-mask a[.](#mers-2.sentence-1)
To improve the uniformity of the result,
the bits of the raw shift register are additionally [*tempered*](#def:tempered) (i.e., scrambled) according to a bit-scrambling matrix
defined by values u, d, s, b, t, c, and ℓ[.](#mers-2.sentence-2)
The state transition is performed as follows:
- [(2.1)](#mers-2.1)
Concatenate
the upper ˆ’r bits of Xi−n with
the lower r bits of Xi+ˆ’n to obtain an unsigned integer value Y[.](#mers-2.1.sentence-1)
- [(2.2)](#mers-2.2)
With α=‹(Ybitand1),
set Xi to Xi+ˆ’nxor(Yrshift1)xorα[.](#mers-2.2.sentence-1)
The sequence X is initialized
with the help of an initialization multiplier f[.](#mers-2.sentence-4)
[3](#mers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2838)
The generation algorithm
determines the unsigned integer values z1,z2,z3,z4 as follows,
then delivers z4 as its result:
- [(3.1)](#mers-3.1)
Let z1=Xixor((Xirshiftu)bitandd)[.](#mers-3.1.sentence-1)
- [(3.2)](#mers-3.2)
Let z2=z1xor((z1lshiftws)bitandb)[.](#mers-3.2.sentence-1)
- [(3.3)](#mers-3.3)
Let z3=z2xor((z2lshiftwt)bitandc)[.](#mers-3.3.sentence-1)
- [(3.4)](#mers-3.4)
Let z4=z3xor(z3rshiftℓ)[.](#mers-3.4.sentence-1)
[🔗](#lib:mersenne_twister_engine_)
namespace std {template<class UIntType, size_t w, size_t n, size_t m, size_t r,
UIntType a, size_t u, UIntType d, size_t s,
UIntType b, size_t t,
UIntType c, size_t l, UIntType f>class mersenne_twister_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t state_size = n; static constexpr size_t shift_size = m; static constexpr size_t mask_bits = r; static constexpr UIntType xor_mask = a; static constexpr size_t tempering_u = u; static constexpr UIntType tempering_d = d; static constexpr size_t tempering_s = s; static constexpr UIntType tempering_b = b; static constexpr size_t tempering_t = t; static constexpr UIntType tempering_c = c; static constexpr size_t tempering_l = l; static constexpr UIntType initialization_multiplier = f; static constexpr result_type min() { return 0; }static constexpr result_type max() { return 2w−1; }static constexpr result_type default_seed = 5489u; // constructors and seeding functions mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}explicit mersenne_twister_engine(result_type value); template<class Sseq> explicit mersenne_twister_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const mersenne_twister_engine& x, const mersenne_twister_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst mersenne_twister_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted mersenne_twister_engine& x); };}
[4](#mers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2911)
The following relations shall hold: 0 < m, m <= n, 2u < w, r <= w, u <= w, s <= w, t <= w, l <= w, w <= numeric_limits<UIntType>::digits, a <= (1u << w) - 1u, b <= (1u << w) - 1u, c <= (1u << w) - 1u, d <= (1u << w) - 1u,
and f <= (1u << w) - 1u[.](#mers-4.sentence-1)
[5](#mers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2929)
The textual representation
of xi consists of the values of Xi−n,…,Xi−1,
in that order[.](#mers-5.sentence-1)
[🔗](#lib:mersenne_twister_engine,constructor)
`explicit mersenne_twister_engine(result_type value);
`
[6](#mers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2941)
*Effects*: Sets ˆ’n to valuemod2w[.](#mers-6.sentence-1)
Then, iteratively for i=ˆ’n,…,−1, sets Xi to
[‹(Xi−1xor(Xi−1rshift(ˆ’2)))+imodn]mod2w[.](#mers-6.sentence-2)
[7](#mers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2954)
*Complexity*: O(n)[.](#mers-7.sentence-1)
[🔗](#lib:mersenne_twister_engine,constructor_)
`template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
`
[8](#mers-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2965)
*Effects*: With k=⌈w/32⌉ and a an array (or equivalent)
of length ‹k,
invokes q.generate(a+0, a+‹k) and then, iteratively for i=−n,…,−1,
sets Xi to (∑ˆ’1j=0ak(i+n)+jâ‹232j)mod2w[.](#mers-8.sentence-1)
Finally,
if the most significant ˆ’r bits of ˆ’n are zero,
and if each of the other resulting Xi is 0,
changes ˆ’n to 2w−1[.](#mers-8.sentence-2)
[242)](#footnote-242)[242)](#footnoteref-242)
The name of this engine refers, in part, to a property of its period:
For properly-selected values of the parameters,
the period is closely related to a large Mersenne prime number[.](#footnote-242.sentence-1)
#### [29.5.4.4](#sub) Class template subtract_with_carry_engine [[rand.eng.sub]](rand.eng.sub)
[1](#sub-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2989)
A subtract_with_carry_engine random number engine
produces unsigned integer random numbers[.](#sub-1.sentence-1)
[2](#sub-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2993)
The state xi of a subtract_with_carry_engine object x is of sizeO(r),
and consists of
a sequence X of r integer values ‰¤Xi<m=2w;
all subscripts applied to X are to be taken modulo r[.](#sub-2.sentence-1)
The state xi additionally consists of an integer c (known as the [*carry*](#def:carry))
whose value is either 0 or 1[.](#sub-2.sentence-2)
[3](#sub-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3006)
The state transition
is performed as follows:
- [(3.1)](#sub-3.1)
Let Y=Xi−ˆ’Xi−ˆ’c[.](#sub-3.1.sentence-1)
- [(3.2)](#sub-3.2)
Set Xi to y=Ymodm[.](#sub-3.2.sentence-1)
Set c to 1 if Y<0,
otherwise set c to 0[.](#sub-3.2.sentence-2)
[*Note [1](#sub-note-1)*:
This algorithm corresponds
to a modular linear function
of the form TA(xi)=(‹xi)modb,
where b is of the form mr−ms+1 and a=ˆ’(b−1)/m[.](#sub-3.sentence-2)
— *end note*]
[4](#sub-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3027)
The generation algorithm
is given by GA(xi)=y,
where y is the value produced as a result
of advancing the engine's state as described above[.](#sub-4.sentence-1)
[🔗](#lib:subtract_with_carry_engine_)
namespace std {template<class UIntType, size_t w, size_t s, size_t r>class subtract_with_carry_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t short_lag = s; static constexpr size_t long_lag = r; static constexpr result_type min() { return 0; }static constexpr result_type max() { return m−1; }static constexpr uint_least32_t default_seed = 19780503u; // constructors and seeding functions subtract_with_carry_engine() : subtract_with_carry_engine(0u) {}explicit subtract_with_carry_engine(result_type value); template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); void seed(result_type value = 0u); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const subtract_with_carry_engine& x, const subtract_with_carry_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst subtract_with_carry_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted subtract_with_carry_engine& x); };}
[5](#sub-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3079)
The following relations shall hold: 0u < s, s < r, 0 < w,
and w <= numeric_limits<UIntType>::digits[.](#sub-5.sentence-1)
[6](#sub-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3087)
The textual representation
consists of the values of Xi−r,…,Xi−1,
in that order, followed by c[.](#sub-6.sentence-1)
[🔗](#lib:subtract_with_carry_engine,constructor)
`explicit subtract_with_carry_engine(result_type value);
`
[7](#sub-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3099)
*Effects*: Sets the values of X−r,…,X−1,
in that order, as specified below[.](#sub-7.sentence-1)
If X−1 is then 0,
sets c to 1;
otherwise sets c to 0[.](#sub-7.sentence-2)
To set the values Xk,
first construct e, a linear_congruential_engine object,
as if by the following definition:linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u> e( value == 0u ? default_seed : static_cast<uint_least32_t>(value % 2147483563u));
Then, to set each Xk,
obtain new values z0,…,zn−1 from n=⌈w/32⌉ successive invocations
of e[.](#sub-7.sentence-4)
Set Xk to (∑ˆ’1j=0zjâ‹232j)modm[.](#sub-7.sentence-5)
[8](#sub-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3121)
*Complexity*: Exactly nâ‹r invocations
of e[.](#sub-8.sentence-1)
[🔗](#lib:subtract_with_carry_engine,constructor_)
`template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
`
[9](#sub-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3133)
*Effects*: With k=⌈w/32⌉ and a an array (or equivalent)
of length râ‹k,
invokes q.generate(a+0, a+râ‹k) and then, iteratively for i=−r,…,−1,
sets Xi to (∑ˆ’1j=0ak(i+r)+jâ‹232j)modm[.](#sub-9.sentence-1)
If X−1 is then 0,
sets c to 1;
otherwise sets c to 0[.](#sub-9.sentence-2)
#### [29.5.4.5](#philox) Class template philox_engine [[rand.eng.philox]](rand.eng.philox)
[1](#philox-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3154)
A philox_engine random number engine produces
unsigned integer random numbers in the interval [0, m),
where m=2w and
the template parameter w defines the range of the produced numbers[.](#philox-1.sentence-1)
The state of a philox_engine object consists of
a sequence X of n unsigned integer values of width w,
a sequence K of n/2 values of result_type,
a sequence Y of n values of result_type, and
a scalar i, where
- [(1.1)](#philox-1.1)
X is the interpretation of the unsigned integer [*counter*](#def:counter) valueZ:=∑ˆ’1j=0Xjâ‹2wj of nâ‹w bits,
- [(1.2)](#philox-1.2)
K are keys, which are generated once from the seed (see constructors below)
and remain constant unless the seed function ([[rand.req.eng]](rand.req.eng "29.5.3.4Random number engine requirements")) is invoked,
- [(1.3)](#philox-1.3)
Y stores a batch of output values, and
- [(1.4)](#philox-1.4)
i is an index for an element of the sequence Y[.](#philox-1.sentence-2)
[2](#philox-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3177)
The generation algorithm returns Yi,
the value stored in the ith element of Y after applying
the transition algorithm[.](#philox-2.sentence-1)
[3](#philox-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3182)
The state transition is performed as if by the following algorithm:i = i + 1if (i == n) {Y = Philox(K, X) // *see below*Z = Z + 1i = 0}
[4](#philox-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3193)
The Philox function maps the length-n/2 sequence K and
the length-n sequence X into a length-n output sequence Y[.](#philox-4.sentence-1)
Philox applies an r-round substitution-permutation network to the values in X[.](#philox-4.sentence-2)
A single round of the generation algorithm performs the following steps:
- [(4.1)](#philox-4.1)
The output sequence X′ of the previous round
(X in case of the first round)
is permuted to obtain the intermediate state V:Vj=X′fn(j) where j=0,…,n−1 andfn(j) is defined in Table [129](#tab:rand.eng.philox.f "Table 129: Values for the word permutation <b>f</b>�"). Table [129](#tab:rand.eng.philox.f) — Values for the word permutation fn(j) [[tab:rand.eng.philox.f]](./tab:rand.eng.philox.f)
| [🔗](#tab:rand.eng.philox.f-row-1)<br>fn(j) | | **j** | | | |
| --- | --- | --- | --- | --- | --- |
| [🔗](#tab:rand.eng.philox.f-row-2) | | 0 | 1 | 2 | 3 |
| [🔗](#tab:rand.eng.philox.f-row-3)<br>**n** | 2 | 0 | 1 | | |
| [🔗](#tab:rand.eng.philox.f-row-4)<br> | 4 | 2 | 1 | 0 | 3 |
| [🔗](#tab:rand.eng.philox.f-row-5)<br> |
[*Note [1](#philox-note-1)*:
For n=2 the sequence is not permuted[.](#philox-4.1.sentence-2)
— *end note*]
- [(4.2)](#philox-4.2)
The following computations are applied to the elements of the V sequence:X2k+0=mulhi(V2k,Mk,w)xorkeyqkxorV2k+1X2k+1=mullo(V2k,Mk,w) where:
* [(4.2.1)](#philox-4.2.1)
mullo(a, b, w) is
the low half of the modular multiplication of a and b: (aâ‹b)mod2w,
* [(4.2.2)](#philox-4.2.2)
mulhi(a, b, w) is
the high half of the modular multiplication of a and b: (⌊(aâ‹b)/2w⌋),
* [(4.2.3)](#philox-4.2.3)
k=0,…,n/2−1 is the index in the sequences,
* [(4.2.4)](#philox-4.2.4)
q=0,…,r−1 is the index of the round,
* [(4.2.5)](#philox-4.2.5)
keyqk is the kth round key for round q, keyqk:=(Kk+qâ‹Ck)mod2w,
* [(4.2.6)](#philox-4.2.6)
Kk are the elements of the key sequence K,
* [(4.2.7)](#philox-4.2.7)
Mk is multipliers[k], and
* [(4.2.8)](#philox-4.2.8)
Ck is round_consts[k].
[5](#philox-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3261)
After r applications of the single-round function,Philox returns the sequence Y=X′[.](#philox-5.sentence-1)
[🔗](#lib:philox_engine_)
namespace std {template<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>class philox_engine {static constexpr size_t *array-size* = n / 2; // *exposition only*public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t word_count = n; static constexpr size_t round_count = r; static constexpr array<result_type, *array-size*> multipliers; static constexpr array<result_type, *array-size>* round_consts; static constexpr result_type min() { return 0; }static constexpr result_type max() { return m - 1; }static constexpr result_type default_seed = 20111115u; // constructors and seeding functions philox_engine() : philox_engine(default_seed) {}explicit philox_engine(result_type value); template<class Sseq> explicit philox_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); void set_counter(const array<result_type, n>& counter); // equality operatorsfriend bool operator==(const philox_engine& x, const philox_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const philox_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, philox_engine& x); // hosted};}
[6](#philox-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3313)
*Mandates*:
- [(6.1)](#philox-6.1)
sizeof...(consts) == n is true, and
- [(6.2)](#philox-6.2)
n == 2 || n == 4 is true, and
- [(6.3)](#philox-6.3)
0 < r is true, and
- [(6.4)](#philox-6.4)
0 < w && w <= numeric_limits<UIntType>::digits is true[.](#philox-6.sentence-1)
[7](#philox-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3322)
The template parameter pack consts represents
the Mk and Ck constants which are grouped as follows:[M0,C0,M1,C1,M2,C2,…,Mn/2−1,Cn/2−1][.](#philox-7.sentence-1)
[8](#philox-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3327)
The textual representation consists of the values ofK0,…,Kn/2−1,X0,…,Xn−1,i, in that order[.](#philox-8.sentence-1)
[*Note [2](#philox-note-2)*:
The stream extraction operator can reconstruct Y from K and X, as needed[.](#philox-8.sentence-2)
— *end note*]
[🔗](#lib:philox_engine,constructor)
`explicit philox_engine(result_type value);
`
[9](#philox-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3340)
*Effects*: Sets the K0 element of sequence K to valuemod2w[.](#philox-9.sentence-1)
All elements of sequences X and K (except K0) are set to 0[.](#philox-9.sentence-2)
The value of i is set to n−1[.](#philox-9.sentence-3)
[🔗](#lib:philox_engine,constructor_)
`template<class Sseq> explicit philox_engine(Sseq& q);
`
[10](#philox-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3353)
*Effects*: With p=⌈w/32⌉ and
an array (or equivalent) a of length (n/2)â‹p,
invokes q.generate(a + 0, a + n / 2 * p) and
then iteratively for k=0,…,n/2−1,
sets Kk to(∑ˆ’1j=0akp+jâ‹232j)mod2w[.](#philox-10.sentence-1)
All elements of sequence X are set to 0[.](#philox-10.sentence-2)
The value of i is set to n−1[.](#philox-10.sentence-3)
[🔗](#lib:set_counter,philox_engine)
`void set_counter(const array<result_type, n>& c);
`
[11](#philox-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3371)
*Effects*: For j=0,…,n−1 sets Xj to Cn−ˆ’jmod2w[.](#philox-11.sentence-1)
The value of i is set to n−1[.](#philox-11.sentence-2)
[*Note [3](#philox-note-3)*:
The counter is the value Z introduced at the beginning of this subclause[.](#philox-11.sentence-3)
— *end note*]

View File

@@ -0,0 +1,83 @@
[rand.eng.general]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng.general)
### 29.5.4 Random number engine class templates [[rand.eng]](rand.eng#general)
#### 29.5.4.1 General [rand.eng.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2595)
Each type instantiated
from a class template specified in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") meets the requirements
of a [random number engine](rand.req.eng "29.5.3.4Random number engine requirements[rand.req.eng]") type[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2601)
Except where specified otherwise,
the complexity of each function
specified in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") is constant[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2607)
Except where specified otherwise,
no function described in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") throws an exception[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2612)
Every function described in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") that has a function parameter q of type Sseq& for a template type parameter named Sseq that is different from type seed_seq throws what and when the invocation of q.generate throws[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2619)
Descriptions are provided in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") only for engine operations
that are not described in [[rand.req.eng]](rand.req.eng "29.5.3.4Random number engine requirements") or for operations where there is additional semantic information[.](#5.sentence-1)
In particular,
declarations for copy constructors,
for copy assignment operators,
for streaming operators,
and for equality and inequality operators
are not shown in the synopses[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2631)
Each template specified in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") requires one or more relationships,
involving the value(s) of its constant template parameter(s), to hold[.](#6.sentence-1)
A program instantiating any of these templates
is ill-formed
if any such required relationship fails to hold[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2639)
For every random number engine and for every random number engine adaptor X defined in [[rand.eng]](rand.eng "29.5.4Random number engine class templates") and in [[rand.adapt]](rand.adapt "29.5.5Random number engine adaptor class templates"):
- [(7.1)](#7.1)
if the constructortemplate<class Sseq> explicit X(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
constructor shall not participate in overload resolution;
- [(7.2)](#7.2)
if the member functiontemplate<class Sseq> void seed(Sseq& q); is called with a type Sseq that does not qualify as a seed sequence, then this
function shall not participate in overload resolution[.](#7.sentence-1)
The extent to which an implementation determines that a type cannot be a seed sequence
is unspecified, except that as a minimum a type shall not qualify as a seed sequence
if it is implicitly convertible to X::result_type[.](#7.sentence-2)

View File

@@ -0,0 +1,88 @@
[rand.eng.lcong]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng.lcong)
### 29.5.4 Random number engine class templates [[rand.eng]](rand.eng#lcong)
#### 29.5.4.2 Class template linear_congruential_engine [rand.eng.lcong]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2670)
A linear_congruential_engine random number engine
produces unsigned integer random numbers[.](#1.sentence-1)
The state xi of a linear_congruential_engine object x is of size 1 and consists of a single integer[.](#1.sentence-2)
The transition algorithm
is a modular linear function of the formTA(xi)=(aâ‹xi+c)modm;
the generation algorithm
is GA(xi)=xi+1[.](#1.sentence-3)
[🔗](#lib:linear_congruential_engine_)
namespace std {template<class UIntType, UIntType a, UIntType c, UIntType m>class linear_congruential_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr result_type multiplier = a; static constexpr result_type increment = c; static constexpr result_type modulus = m; static constexpr result_type min() { return c == 0u ? 1u: 0u; }static constexpr result_type max() { return m - 1u; }static constexpr result_type default_seed = 1u; // constructors and seeding functions linear_congruential_engine() : linear_congruential_engine(default_seed) {}explicit linear_congruential_engine(result_type s); template<class Sseq> explicit linear_congruential_engine(Sseq& q); void seed(result_type s = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const linear_congruential_engine& x, const linear_congruential_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst linear_congruential_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted linear_congruential_engine& x); };}
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2729)
If the template parameterm is 0,
the modulus m used throughout [rand.eng.lcong]
is numeric_limits<result_type>::max() plus 1[.](#2.sentence-1)
[*Note [1](#note-1)*:
m need not be representable
as a value of type result_type[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2740)
If the template parameterm is not 0,
the following relations shall hold: a < m and c < m[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2748)
The textual representation
consists of
the value of xi[.](#4.sentence-1)
[🔗](#lib:linear_congruential_engine,constructor)
`explicit linear_congruential_engine(result_type s);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2759)
*Effects*: If cmodm is 0 and smodm is 0,
sets the engine's state to 1,
otherwise sets the engine's state to smodm[.](#5.sentence-1)
[🔗](#lib:linear_congruential_engine,constructor_)
`template<class Sseq> explicit linear_congruential_engine(Sseq& q);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2772)
*Effects*: With k=⌈log2m32⌉ and a an array (or equivalent)
of length k+3,
invokes q.generate(a+0, a+k+3) and then computes S=ˆ‘ˆ’1j=0aj+3â‹232j)modm[.](#6.sentence-1)
If cmodm is 0 and S is 0,
sets the engine's state to 1,
else sets the engine's state
to S[.](#6.sentence-2)

141
cppdraft/rand/eng/mers.md Normal file
View File

@@ -0,0 +1,141 @@
[rand.eng.mers]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng.mers)
### 29.5.4 Random number engine class templates [[rand.eng]](rand.eng#mers)
#### 29.5.4.3 Class template mersenne_twister_engine [rand.eng.mers]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2793)
A mersenne_twister_engine random number
engine[242](#footnote-242 "The name of this engine refers, in part, to a property of its period: For properly-selected values of the parameters, the period is closely related to a large Mersenne prime number.") produces unsigned integer random numbers
in the closed interval [0,2w−1][.](#1.sentence-1)
The
statexi of a mersenne_twister_engine object x is of size n and consists of a sequence X of n values of the type delivered by x;
all subscripts applied to X are to be taken modulo n[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2812)
The transition algorithm
employs a twisted generalized feedback shift register
defined by shift values n and m, a twist value r,
and a conditional xor-mask a[.](#2.sentence-1)
To improve the uniformity of the result,
the bits of the raw shift register are additionally [*tempered*](#def:tempered) (i.e., scrambled) according to a bit-scrambling matrix
defined by values u, d, s, b, t, c, and ℓ[.](#2.sentence-2)
The state transition is performed as follows:
- [(2.1)](#2.1)
Concatenate
the upper w−r bits of Xi−n with
the lower r bits of Xi+1−n to obtain an unsigned integer value Y[.](#2.1.sentence-1)
- [(2.2)](#2.2)
With α=aâ‹(Ybitand1),
set Xi to Xi+m−nxor(Yrshift1)xorα[.](#2.2.sentence-1)
The sequence X is initialized
with the help of an initialization multiplier f[.](#2.sentence-4)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2838)
The generation algorithm
determines the unsigned integer values z1,z2,z3,z4 as follows,
then delivers z4 as its result:
- [(3.1)](#3.1)
Let z1=Xixor((Xirshiftu)bitandd)[.](#3.1.sentence-1)
- [(3.2)](#3.2)
Let z2=z1xor((z1lshiftws)bitandb)[.](#3.2.sentence-1)
- [(3.3)](#3.3)
Let z3=z2xor((z2lshiftwt)bitandc)[.](#3.3.sentence-1)
- [(3.4)](#3.4)
Let z4=z3xor(z3rshiftℓ)[.](#3.4.sentence-1)
[🔗](#lib:mersenne_twister_engine_)
namespace std {template<class UIntType, size_t w, size_t n, size_t m, size_t r,
UIntType a, size_t u, UIntType d, size_t s,
UIntType b, size_t t,
UIntType c, size_t l, UIntType f>class mersenne_twister_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t state_size = n; static constexpr size_t shift_size = m; static constexpr size_t mask_bits = r; static constexpr UIntType xor_mask = a; static constexpr size_t tempering_u = u; static constexpr UIntType tempering_d = d; static constexpr size_t tempering_s = s; static constexpr UIntType tempering_b = b; static constexpr size_t tempering_t = t; static constexpr UIntType tempering_c = c; static constexpr size_t tempering_l = l; static constexpr UIntType initialization_multiplier = f; static constexpr result_type min() { return 0; }static constexpr result_type max() { return 2w−1; }static constexpr result_type default_seed = 5489u; // constructors and seeding functions mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}explicit mersenne_twister_engine(result_type value); template<class Sseq> explicit mersenne_twister_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const mersenne_twister_engine& x, const mersenne_twister_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst mersenne_twister_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted mersenne_twister_engine& x); };}
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2911)
The following relations shall hold: 0 < m, m <= n, 2u < w, r <= w, u <= w, s <= w, t <= w, l <= w, w <= numeric_limits<UIntType>::digits, a <= (1u << w) - 1u, b <= (1u << w) - 1u, c <= (1u << w) - 1u, d <= (1u << w) - 1u,
and f <= (1u << w) - 1u[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2929)
The textual representation
of xi consists of the values of Xi−n,…,Xi−1,
in that order[.](#5.sentence-1)
[🔗](#lib:mersenne_twister_engine,constructor)
`explicit mersenne_twister_engine(result_type value);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2941)
*Effects*: Sets ˆ’n to valuemod2w[.](#6.sentence-1)
Then, iteratively for i=ˆ’n,…,−1, sets Xi to
[‹(Xi−1xor(Xi−1rshift(ˆ’2)))+imodn]mod2w[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2954)
*Complexity*: O(n)[.](#7.sentence-1)
[🔗](#lib:mersenne_twister_engine,constructor_)
`template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2965)
*Effects*: With k=⌈w/32⌉ and a an array (or equivalent)
of length ‹k,
invokes q.generate(a+0, a+‹k) and then, iteratively for i=−n,…,−1,
sets Xi to (∑ˆ’1j=0ak(i+n)+jâ‹232j)mod2w[.](#8.sentence-1)
Finally,
if the most significant ˆ’r bits of ˆ’n are zero,
and if each of the other resulting Xi is 0,
changes ˆ’n to 2w−1[.](#8.sentence-2)
[242)](#footnote-242)[242)](#footnoteref-242)
The name of this engine refers, in part, to a property of its period:
For properly-selected values of the parameters,
the period is closely related to a large Mersenne prime number[.](#footnote-242.sentence-1)

224
cppdraft/rand/eng/philox.md Normal file
View File

@@ -0,0 +1,224 @@
[rand.eng.philox]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng.philox)
### 29.5.4 Random number engine class templates [[rand.eng]](rand.eng#philox)
#### 29.5.4.5 Class template philox_engine [rand.eng.philox]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3154)
A philox_engine random number engine produces
unsigned integer random numbers in the interval [0, m),
where m=2w and
the template parameter w defines the range of the produced numbers[.](#1.sentence-1)
The state of a philox_engine object consists of
a sequence X of n unsigned integer values of width w,
a sequence K of n/2 values of result_type,
a sequence Y of n values of result_type, and
a scalar i, where
- [(1.1)](#1.1)
X is the interpretation of the unsigned integer [*counter*](#def:counter) valueZ:=∑ˆ’1j=0Xjâ‹2wj of nâ‹w bits,
- [(1.2)](#1.2)
K are keys, which are generated once from the seed (see constructors below)
and remain constant unless the seed function ([[rand.req.eng]](rand.req.eng "29.5.3.4Random number engine requirements")) is invoked,
- [(1.3)](#1.3)
Y stores a batch of output values, and
- [(1.4)](#1.4)
i is an index for an element of the sequence Y[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3177)
The generation algorithm returns Yi,
the value stored in the ith element of Y after applying
the transition algorithm[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3182)
The state transition is performed as if by the following algorithm:i = i + 1if (i == n) {Y = Philox(K, X) // *see below*Z = Z + 1i = 0}
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3193)
The Philox function maps the length-n/2 sequence K and
the length-n sequence X into a length-n output sequence Y[.](#4.sentence-1)
Philox applies an r-round substitution-permutation network to the values in X[.](#4.sentence-2)
A single round of the generation algorithm performs the following steps:
- [(4.1)](#4.1)
The output sequence X′ of the previous round
(X in case of the first round)
is permuted to obtain the intermediate state V:Vj=X′fn(j) where j=0,…,n−1 andfn(j) is defined in Table [129](#tab:rand.eng.philox.f "Table 129: Values for the word permutation <b>f</b>�"). Table [129](#tab:rand.eng.philox.f) — Values for the word permutation fn(j) [[tab:rand.eng.philox.f]](./tab:rand.eng.philox.f)
| [🔗](#tab:rand.eng.philox.f-row-1)<br>fn(j) | | **j** | | | |
| --- | --- | --- | --- | --- | --- |
| [🔗](#tab:rand.eng.philox.f-row-2) | | 0 | 1 | 2 | 3 |
| [🔗](#tab:rand.eng.philox.f-row-3)<br>**n** | 2 | 0 | 1 | | |
| [🔗](#tab:rand.eng.philox.f-row-4)<br> | 4 | 2 | 1 | 0 | 3 |
| [🔗](#tab:rand.eng.philox.f-row-5)<br> |
[*Note [1](#note-1)*:
For n=2 the sequence is not permuted[.](#4.1.sentence-2)
— *end note*]
- [(4.2)](#4.2)
The following computations are applied to the elements of the V sequence:X2k+0=mulhi(V2k,Mk,w)xorkeyqkxorV2k+1X2k+1=mullo(V2k,Mk,w) where:
* [(4.2.1)](#4.2.1)
mullo(a, b, w) is
the low half of the modular multiplication of a and b: (aâ‹b)mod2w,
* [(4.2.2)](#4.2.2)
mulhi(a, b, w) is
the high half of the modular multiplication of a and b: (⌊(aâ‹b)/2w⌋),
* [(4.2.3)](#4.2.3)
k=0,…,n/2−1 is the index in the sequences,
* [(4.2.4)](#4.2.4)
q=0,…,r−1 is the index of the round,
* [(4.2.5)](#4.2.5)
keyqk is the kth round key for round q, keyqk:=(Kk+qâ‹Ck)mod2w,
* [(4.2.6)](#4.2.6)
Kk are the elements of the key sequence K,
* [(4.2.7)](#4.2.7)
Mk is multipliers[k], and
* [(4.2.8)](#4.2.8)
Ck is round_consts[k].
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3261)
After r applications of the single-round function,Philox returns the sequence Y=X′[.](#5.sentence-1)
[🔗](#lib:philox_engine_)
namespace std {template<class UIntType, size_t w, size_t n, size_t r, UIntType... consts>class philox_engine {static constexpr size_t *array-size* = n / 2; // *exposition only*public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t word_count = n; static constexpr size_t round_count = r; static constexpr array<result_type, *array-size*> multipliers; static constexpr array<result_type, *array-size>* round_consts; static constexpr result_type min() { return 0; }static constexpr result_type max() { return m - 1; }static constexpr result_type default_seed = 20111115u; // constructors and seeding functions philox_engine() : philox_engine(default_seed) {}explicit philox_engine(result_type value); template<class Sseq> explicit philox_engine(Sseq& q); void seed(result_type value = default_seed); template<class Sseq> void seed(Sseq& q); void set_counter(const array<result_type, n>& counter); // equality operatorsfriend bool operator==(const philox_engine& x, const philox_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const philox_engine& x); // hostedtemplate<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, philox_engine& x); // hosted};}
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3313)
*Mandates*:
- [(6.1)](#6.1)
sizeof...(consts) == n is true, and
- [(6.2)](#6.2)
n == 2 || n == 4 is true, and
- [(6.3)](#6.3)
0 < r is true, and
- [(6.4)](#6.4)
0 < w && w <= numeric_limits<UIntType>::digits is true[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3322)
The template parameter pack consts represents
the Mk and Ck constants which are grouped as follows:[M0,C0,M1,C1,M2,C2,…,Mn/2−1,Cn/2−1][.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3327)
The textual representation consists of the values ofK0,…,Kn/2−1,X0,…,Xn−1,i, in that order[.](#8.sentence-1)
[*Note [2](#note-2)*:
The stream extraction operator can reconstruct Y from K and X, as needed[.](#8.sentence-2)
— *end note*]
[🔗](#lib:philox_engine,constructor)
`explicit philox_engine(result_type value);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3340)
*Effects*: Sets the K0 element of sequence K to valuemod2w[.](#9.sentence-1)
All elements of sequences X and K (except K0) are set to 0[.](#9.sentence-2)
The value of i is set to n−1[.](#9.sentence-3)
[🔗](#lib:philox_engine,constructor_)
`template<class Sseq> explicit philox_engine(Sseq& q);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3353)
*Effects*: With p=⌈w/32⌉ and
an array (or equivalent) a of length (n/2)â‹p,
invokes q.generate(a + 0, a + n / 2 * p) and
then iteratively for k=0,…,n/2−1,
sets Kk to(∑ˆ’1j=0akp+jâ‹232j)mod2w[.](#10.sentence-1)
All elements of sequence X are set to 0[.](#10.sentence-2)
The value of i is set to n−1[.](#10.sentence-3)
[🔗](#lib:set_counter,philox_engine)
`void set_counter(const array<result_type, n>& c);
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3371)
*Effects*: For j=0,…,n−1 sets Xj to Cn−ˆ’jmod2w[.](#11.sentence-1)
The value of i is set to n−1[.](#11.sentence-2)
[*Note [3](#note-3)*:
The counter is the value Z introduced at the beginning of this subclause[.](#11.sentence-3)
— *end note*]

133
cppdraft/rand/eng/sub.md Normal file
View File

@@ -0,0 +1,133 @@
[rand.eng.sub]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#eng.sub)
### 29.5.4 Random number engine class templates [[rand.eng]](rand.eng#sub)
#### 29.5.4.4 Class template subtract_with_carry_engine [rand.eng.sub]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2989)
A subtract_with_carry_engine random number engine
produces unsigned integer random numbers[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2993)
The state xi of a subtract_with_carry_engine object x is of sizeO(r),
and consists of
a sequence X of r integer values 0≤Xi<m=2w;
all subscripts applied to X are to be taken modulo r[.](#2.sentence-1)
The state xi additionally consists of an integer c (known as the [*carry*](#def:carry))
whose value is either 0 or 1[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3006)
The state transition
is performed as follows:
- [(3.1)](#3.1)
Let Y=Xi−ˆ’Xi−ˆ’c[.](#3.1.sentence-1)
- [(3.2)](#3.2)
Set Xi to y=Ymodm[.](#3.2.sentence-1)
Set c to 1 if Y<0,
otherwise set c to 0[.](#3.2.sentence-2)
[*Note [1](#note-1)*:
This algorithm corresponds
to a modular linear function
of the form TA(xi)=(‹xi)modb,
where b is of the form mr−ms+1 and a=ˆ’(b−1)/m[.](#3.sentence-2)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3027)
The generation algorithm
is given by GA(xi)=y,
where y is the value produced as a result
of advancing the engine's state as described above[.](#4.sentence-1)
[🔗](#lib:subtract_with_carry_engine_)
namespace std {template<class UIntType, size_t w, size_t s, size_t r>class subtract_with_carry_engine {public:// typesusing result_type = UIntType; // engine characteristicsstatic constexpr size_t word_size = w; static constexpr size_t short_lag = s; static constexpr size_t long_lag = r; static constexpr result_type min() { return 0; }static constexpr result_type max() { return m−1; }static constexpr uint_least32_t default_seed = 19780503u; // constructors and seeding functions subtract_with_carry_engine() : subtract_with_carry_engine(0u) {}explicit subtract_with_carry_engine(result_type value); template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); void seed(result_type value = 0u); template<class Sseq> void seed(Sseq& q); // equality operatorsfriend bool operator==(const subtract_with_carry_engine& x, const subtract_with_carry_engine& y); // generating functions result_type operator()(); void discard(unsigned long long z); // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst subtract_with_carry_engine& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted subtract_with_carry_engine& x); };}
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3079)
The following relations shall hold: 0u < s, s < r, 0 < w,
and w <= numeric_limits<UIntType>::digits[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3087)
The textual representation
consists of the values of Xi−r,…,Xi−1,
in that order, followed by c[.](#6.sentence-1)
[🔗](#lib:subtract_with_carry_engine,constructor)
`explicit subtract_with_carry_engine(result_type value);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3099)
*Effects*: Sets the values of X−r,…,X−1,
in that order, as specified below[.](#7.sentence-1)
If X−1 is then 0,
sets c to 1;
otherwise sets c to 0[.](#7.sentence-2)
To set the values Xk,
first construct e, a linear_congruential_engine object,
as if by the following definition:linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u> e( value == 0u ? default_seed : static_cast<uint_least32_t>(value % 2147483563u));
Then, to set each Xk,
obtain new values z0,…,zn−1 from n=⌈w/32⌉ successive invocations
of e[.](#7.sentence-4)
Set Xk to (∑ˆ’1j=0zjâ‹232j)modm[.](#7.sentence-5)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3121)
*Complexity*: Exactly nâ‹r invocations
of e[.](#8.sentence-1)
[🔗](#lib:subtract_with_carry_engine,constructor_)
`template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3133)
*Effects*: With k=⌈w/32⌉ and a an array (or equivalent)
of length râ‹k,
invokes q.generate(a+0, a+râ‹k) and then, iteratively for i=−r,…,−1,
sets Xi to (∑ˆ’1j=0ak(i+r)+jâ‹232j)modm[.](#9.sentence-1)
If X−1 is then 0,
sets c to 1;
otherwise sets c to 0[.](#9.sentence-2)

96
cppdraft/rand/general.md Normal file
View File

@@ -0,0 +1,96 @@
[rand.general]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#general)
### 29.5.1 General [rand.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1279)
Subclause [[rand]](rand "29.5Random number generation") defines a facility
for generating (pseudo-)random numbers[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1283)
In addition to a few utilities,
four categories of entities are described:[*uniform random bit generators*](#def:uniform_random_bit_generators),[*random number engines*](#def:random_number_engines),[*random number engine adaptors*](#def:random_number_engine_adaptors),
and[*random number distributions*](#def:random_number_distributions)[.](#2.sentence-1)
These categorizations are applicable
to types that meet the corresponding requirements,
to objects instantiated from such types,
and to templates producing such types when instantiated[.](#2.sentence-2)
[*Note [1](#note-1)*:
These entities are specified in such a way
as to permit the binding
of any uniform random bit generator object e as the argument
to any random number distribution object d,
thus producing a zero-argument function object
such as given by bind(d,e)[.](#2.sentence-3)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1306)
Each of the entities specified in [[rand]](rand "29.5Random number generation") has an associated arithmetic type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))
identified as result_type[.](#3.sentence-1)
With T as the result_type thus associated with such an entity,
that entity is characterized:
- [(3.1)](#3.1)
as [*boolean*](#def:boolean) or equivalently as [*boolean-valued*](#def:boolean-valued),
if T is bool;
- [(3.2)](#3.2)
otherwise
as [*integral*](#def:integral) or equivalently as [*integer-valued*](#def:integer-valued),
if numeric_limits<T>::is_integer is true;
- [(3.3)](#3.3)
otherwise
as [*floating-point*](#def:floating-point) or equivalently as [*real-valued*](#def:real-valued)[.](#3.sentence-2)
If integer-valued,
an entity may optionally be further characterized as[*signed*](#def:signed) or [*unsigned*](#def:unsigned),
according to numeric_limits<T>::is_signed[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1331)
Unless otherwise specified,
all descriptions of calculations
in [[rand]](rand "29.5Random number generation") use mathematical real numbers[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1337)
Throughout [[rand]](rand "29.5Random number generation"),
the operatorsbitand, bitor, and xor denote the respective conventional bitwise operations[.](#5.sentence-1)
Further:
- [(5.1)](#5.1)
the operator rshift denotes a bitwise right shift
with zero-valued bits appearing in the high bits of the result, and
- [(5.2)](#5.2)
the operator lshiftw denotes a bitwise left shift
with zero-valued bits appearing in the low bits of the result,
and whose result is always taken modulo 2w[.](#5.sentence-2)

190
cppdraft/rand/predef.md Normal file
View File

@@ -0,0 +1,190 @@
[rand.predef]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#predef)
### 29.5.6 Engines and engine adaptors with predefined parameters [rand.predef]
[🔗](#lib:minstd_rand0)
`using minstd_rand0 =
linear_congruential_engine<uint_fast32_t, 16'807, 0, 2'147'483'647>;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3822)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type minstd_rand0 produces the value 1043618065[.](#1.sentence-1)
[🔗](#lib:minstd_rand)
`using minstd_rand =
linear_congruential_engine<uint_fast32_t, 48'271, 0, 2'147'483'647>;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3837)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type minstd_rand produces the value 399268537[.](#2.sentence-1)
[🔗](#lib:mt19937)
`using mt19937 =
mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
0x9908'b0df, 11, 0xffff'ffff, 7, 0x9d2c'5680, 15, 0xefc6'0000, 18, 1'812'433'253>;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3853)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type mt19937 produces the value 4123659995[.](#3.sentence-1)
[🔗](#lib:mt19937_64)
`using mt19937_64 =
mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
0xb502'6f5a'a966'19e9, 29, 0x5555'5555'5555'5555, 17,
0x71d6'7fff'eda6'0000, 37, 0xfff7'eee0'0000'0000, 43, 6'364'136'223'846'793'005>;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3870)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type mt19937_64 produces the value 9981545732273789042[.](#4.sentence-1)
[🔗](#lib:ranlux24_base)
`using ranlux24_base =
subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3885)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type ranlux24_base produces the value 7937952[.](#5.sentence-1)
[🔗](#lib:ranlux48_base)
`using ranlux48_base =
subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3901)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type ranlux48_base produces the value 61839128582725[.](#6.sentence-1)
[🔗](#lib:ranlux24)
`using ranlux24 = discard_block_engine<ranlux24_base, 223, 23>;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3916)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type ranlux24 produces the value 9901578[.](#7.sentence-1)
[🔗](#lib:ranlux48)
`using ranlux48 = discard_block_engine<ranlux48_base, 389, 11>;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3931)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type ranlux48 produces the value 249142670248501[.](#8.sentence-1)
[🔗](#lib:knuth_b)
`using knuth_b = shuffle_order_engine<minstd_rand0,256>;
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3946)
*Required behavior*: The 10000th consecutive invocation
of a default-constructed object
of type knuth_b produces the value 1112339016[.](#9.sentence-1)
[🔗](#lib:default_random_engine)
`using default_random_engine = implementation-defined;
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3960)
*Remarks*: The choice of engine type
named by this typedef is implementation-defined[.](#10.sentence-1)
[*Note [1](#note-1)*:
The implementation
can select this type
on the basis of performance,
size,
quality,
or any combination of such factors,
so as to provide at least acceptable engine behavior
for relatively casual, inexpert, and/or lightweight use[.](#10.sentence-2)
Because different implementations
can select different underlying engine types,
code that uses this typedef need not generate identical sequences across implementations[.](#10.sentence-3)
— *end note*]
[🔗](#lib:philox4x32)
`using philox4x32 =
philox_engine<uint_fast32_t, 32, 4, 10,
0xCD9E8D57, 0x9E3779B9, 0xD2511F53, 0xBB67AE85>;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L3989)
*Required behavior*: The 10000th consecutive invocation
a default-constructed object of type philox4x32 produces the value 1955073260[.](#11.sentence-1)
[🔗](#lib:philox4x64)
`using philox4x64 =
philox_engine<uint_fast64_t, 64, 4, 10,
0xCA5A826395121157, 0x9E3779B97F4A7C15, 0xD2E7470EE14C6C93, 0xBB67AE8584CAA73B>;
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4004)
*Required behavior*: The 10000th consecutive invocation
a default-constructed object of type philox4x64 produces the value 3409172418970261260[.](#12.sentence-1)

838
cppdraft/rand/req.md Normal file
View File

@@ -0,0 +1,838 @@
[rand.req]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req)
### 29.5.3 Requirements [rand.req]
#### [29.5.3.1](#genl) General requirements [[rand.req.genl]](rand.req.genl)
[1](#genl-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1557)
Throughout [[rand]](rand "29.5Random number generation"),
the effect of instantiating a template:
- [(1.1)](#genl-1.1)
that has a template type parameter
named Sseq is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [seed sequence](#seedseq "29.5.3.2Seed sequence requirements[rand.req.seedseq]")[.](#genl-1.1.sentence-1)
- [(1.2)](#genl-1.2)
that has a template type parameter
named URBG is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [uniform random bit generator](#urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")[.](#genl-1.2.sentence-1)
- [(1.3)](#genl-1.3)
that has a template type parameter
named Engine is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [random number engine](#eng "29.5.3.4Random number engine requirements[rand.req.eng]")[.](#genl-1.3.sentence-1)
- [(1.4)](#genl-1.4)
that has a template type parameter
named RealType is undefined unless the corresponding template argument
is cv-unqualified and
is one of float, double, or long double[.](#genl-1.4.sentence-1)
- [(1.5)](#genl-1.5)
that has a template type parameter
named IntType is undefined unless the corresponding template argument
is cv-unqualified and
is one of short, int, long, long long, unsigned short, unsigned int, unsigned long,
or unsigned long long[.](#genl-1.5.sentence-1)
- [(1.6)](#genl-1.6)
that has a template type parameter
named UIntType is undefined unless the corresponding template argument
is cv-unqualified and
is one of unsigned short, unsigned int, unsigned long,
or unsigned long long[.](#genl-1.6.sentence-1)
[2](#genl-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1617)
Throughout [[rand]](rand "29.5Random number generation"),
phrases of the form “x is an iterator of a specific kind”
shall be interpreted as equivalent to the more formal requirement that
“x is a value
of a type meeting the requirements
of the specified iterator type”[.](#genl-2.sentence-1)
[3](#genl-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1625)
Throughout [[rand]](rand "29.5Random number generation"),
any constructor that can be called with a single argument
and that meets a requirement specified in this subclause
shall be declared explicit[.](#genl-3.sentence-1)
#### [29.5.3.2](#seedseq) Seed sequence requirements [[rand.req.seedseq]](rand.req.seedseq)
[1](#seedseq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1638)
A [*seed sequence*](#def:seed_sequence "29.5.3.2Seed sequence requirements[rand.req.seedseq]") is an object
that consumes a sequence
of integer-valued data
and produces a requested number
of unsigned integer values i, 0≤i<232,
based on the consumed data[.](#seedseq-1.sentence-1)
[*Note [1](#seedseq-note-1)*:
Such an object provides a mechanism
to avoid replication of streams of random variates[.](#seedseq-1.sentence-2)
This can be useful, for example, in applications
requiring large numbers of random number engines[.](#seedseq-1.sentence-3)
— *end note*]
[2](#seedseq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1653)
A class S meets the requirements
of a seed sequence
if the expressions shown
in Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") are valid and have the indicated semantics,
and if S also meets all other requirements
of [[rand.req.seedseq]](#seedseq "29.5.3.2Seed sequence requirements")[.](#seedseq-2.sentence-1)
In Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") and throughout this subclause:
- [(2.1)](#seedseq-2.1)
T is the type named by S's associated result_type;
- [(2.2)](#seedseq-2.2)
q is a value of type S and r is a value of type S or const S;
- [(2.3)](#seedseq-2.3)
ib and ie are input iterators
with an unsigned integer value_type of at least 32 bits;
- [(2.4)](#seedseq-2.4)
rb and re are mutable random access iterators
with an unsigned integer value_type of at least 32 bits;
- [(2.5)](#seedseq-2.5)
ob is an output iterator;
and
- [(2.6)](#seedseq-2.6)
il is a value of type initializer_list<T>[.](#seedseq-2.sentence-2)
Table [126](#tab:rand.req.seedseq) — Seed sequence requirements [[tab:rand.req.seedseq]](./tab:rand.req.seedseq)
| [🔗](#tab:rand.req.seedseq-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.seedseq-row-2)<br>S::result_type | T | T is an [unsigned integer type](basic.fundamental#def:type,unsigned_integer "6.9.2Fundamental types[basic.fundamental]") of at least 32 bits[.](#tab:rand.req.seedseq-row-2-column-3-sentence-1) | |
| [🔗](#tab:rand.req.seedseq-row-3)<br>S() | | Creates a seed sequence with the same initial state as all other default-constructed seed sequences of type S[.](#tab:rand.req.seedseq-row-3-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.seedseq-row-4)<br>S(ib,ie) | | Creates a seed sequence having internal state that depends on some or all of the bits of the supplied sequence [ib,ie)[.](#tab:rand.req.seedseq-row-4-column-3-sentence-1) | O(ie−ib) |
| [🔗](#tab:rand.req.seedseq-row-5)<br>S(il) | | Same as S(il.begin(), il.end())[.](#tab:rand.req.seedseq-row-5-column-3-sentence-1) | same as S(il.begin(), il.end()) |
| [🔗](#tab:rand.req.seedseq-row-6)<br>q.generate(rb,re) | void | Does nothing if rb == re[.](#tab:rand.req.seedseq-row-6-column-3-sentence-1)<br>Otherwise, fills the supplied sequence [rb,re) with 32-bit quantities that depend on the sequence supplied to the constructor and possibly also depend on the history of generate's previous invocations[.](#tab:rand.req.seedseq-row-6-column-3-sentence-2) | O(re−rb) |
| [🔗](#tab:rand.req.seedseq-row-7)<br>r.size() | size_t | The number of 32-bit units that would be copied by a call to r.param[.](#tab:rand.req.seedseq-row-7-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.seedseq-row-8)<br>r.param(ob) | void | Copies to the given destination a sequence of 32-bit units that can be provided to the constructor of a second object of type S, and that would reproduce in that second object a state indistinguishable from the state of the first object[.](#tab:rand.req.seedseq-row-8-column-3-sentence-1) | O(r.size()) |
#### [29.5.3.3](#urng) Uniform random bit generator requirements [[rand.req.urng]](rand.req.urng)
[1](#urng-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1771)
A [*uniform random bit generator*](#def:uniform_random_bit_generator)g of type G is a function object
returning unsigned integer values
such that each value
in the range of possible results
has (ideally) equal probability
of being returned[.](#urng-1.sentence-1)
[*Note [1](#urng-note-1)*:
The degree to which g's results
approximate the ideal
is often determined statistically[.](#urng-1.sentence-2)
— *end note*]
template<class G>concept [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") =[invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<G&> && [unsigned_integral](concepts.arithmetic#concept:unsigned_integral "18.4.7Arithmetic concepts[concepts.arithmetic]")<invoke_result_t<G&>> &&requires {{ G::min() } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<invoke_result_t<G&>>; { G::max() } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<invoke_result_t<G&>>; requires bool_constant<(G::min() < G::max())>::value; };
[2](#urng-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1797)
Let g be an object of type G[.](#urng-2.sentence-1)
G models[uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") only if
- [(2.1)](#urng-2.1)
G::min() <= g(),
- [(2.2)](#urng-2.2)
g() <= G::max(), and
- [(2.3)](#urng-2.3)
g() has amortized constant complexity[.](#urng-2.sentence-2)
[3](#urng-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1808)
A class G meets the [*uniform random bit generator*](#def:uniform_random_bit_generator) requirements ifG models [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]"),invoke_result_t<G&> is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types")),
andG provides a nested [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]") result_type that denotes the same type as invoke_result_t<G&>[.](#urng-3.sentence-1)
#### [29.5.3.4](#eng) Random number engine requirements [[rand.req.eng]](rand.req.eng)
[1](#eng-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1824)
A [*random number engine*](#def:random_number_engine) (commonly shortened to [*engine*](#def:engine))e of type E is a uniform random bit generator
that additionally meets the requirements
(e.g., for seeding and for input/output)
specified in this subclause[.](#eng-1.sentence-1)
[2](#eng-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1833)
At any given time,e has a state ei for some integer i ≥ 0[.](#eng-2.sentence-1)
Upon construction,e has an initial state e0[.](#eng-2.sentence-2)
An engine's state may be established via
a constructor,
a seed function,
assignment,
or a suitable operator>>[.](#eng-2.sentence-3)
[3](#eng-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1846)
E's specification shall define:
- [(3.1)](#eng-3.1)
the size of E's state
in multiples of the size of result_type,
given as an integral constant expression;
- [(3.2)](#eng-3.2)
the [*transition algorithm*](#def:transition_algorithm)TA by which e's state ei is advanced to its [*successor state*](#def:successor_state)ei+1;
and
- [(3.3)](#eng-3.3)
the [*generation algorithm*](#def:generation_algorithm)GA by which an engine's state is mapped
to a value of type result_type[.](#eng-3.sentence-1)
[4](#eng-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1867)
A class E that meets the requirements
of a [uniform random bit generator](#urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") also meets the requirements
of a [*random number engine*](#def:random_number_engine) if the expressions shown
in Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") are valid and have the indicated semantics,
and if E also meets all other requirements
of [[rand.req.eng]](#eng "29.5.3.4Random number engine requirements")[.](#eng-4.sentence-1)
In Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") and throughout this subclause:
- [(4.1)](#eng-4.1)
T is the type named by E's associated result_type;
- [(4.2)](#eng-4.2)
e is a value of E, v is an lvalue of E, x and y are (possibly const) values of E;
- [(4.3)](#eng-4.3)
s is a value of T;
- [(4.4)](#eng-4.4)
q is an lvalue
meeting the requirements of a [seed sequence](#seedseq "29.5.3.2Seed sequence requirements[rand.req.seedseq]");
- [(4.5)](#eng-4.5)
z is a value
of type unsigned long long;
- [(4.6)](#eng-4.6)
os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
and
- [(4.7)](#eng-4.7)
is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;
where charT and traits are constrained
according to [[strings]](strings "27Strings library") and [[input.output]](input.output "31Input/output library")[.](#eng-4.sentence-2)
Table [127](#tab:rand.req.eng) — Random number engine requirements [[tab:rand.req.eng]](./tab:rand.req.eng)
| [🔗](#tab:rand.req.eng-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.eng-row-2)<br>E() | | Creates an engine with the same initial state as all other default-constructed engines of type E[.](#tab:rand.req.eng-row-2-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-3)<br>E(x) | | Creates an engine that compares equal to x[.](#tab:rand.req.eng-row-3-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-4)<br>E(s) | | Creates an engine with initial state determined by s[.](#tab:rand.req.eng-row-4-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-5)<br>E(q)[240](#footnote-240 "This constructor (as well as the subsequent corresponding seed() function) can be particularly useful to applications requiring a large number of independent random sequences.") | | Creates an engine with an initial state that depends on a sequence produced by one call to q.generate[.](#tab:rand.req.eng-row-5-column-3-sentence-1) | same as complexity of q.generate called on a sequence whose length is size of state |
| [🔗](#tab:rand.req.eng-row-6)<br>e.seed() | void | *Postconditions*: e == E()[.](#tab:rand.req.eng-row-6-column-3-sentence-1) | same as E() |
| [🔗](#tab:rand.req.eng-row-7)<br>e.seed(s) | void | *Postconditions*: e == E(s)[.](#tab:rand.req.eng-row-7-column-3-sentence-1) | same as E(s) |
| [🔗](#tab:rand.req.eng-row-8)<br>e.seed(q) | void | *Postconditions*: e == E(q)[.](#tab:rand.req.eng-row-8-column-3-sentence-1) | same as E(q) |
| [🔗](#tab:rand.req.eng-row-9)<br>e() | T | Advances e's state ei to ei+1 =TA(ei) and returns GA(ei)[.](#tab:rand.req.eng-row-9-column-3-sentence-1) | per [[rand.req.urng]](#urng "29.5.3.3Uniform random bit generator requirements") |
| [🔗](#tab:rand.req.eng-row-10)<br>e.discard(z)[241](#footnote-241 "This operation is common in user code, and can often be implemented in an engine-specific manner so as to provide significant performance improvements over an equivalent naive loop that makes z consecutive calls e().") | void | Advances e's state ei to ei+z by any means equivalent to z consecutive calls e()[.](#tab:rand.req.eng-row-10-column-3-sentence-1) | no worse than the complexity of z consecutive calls e() |
| [🔗](#tab:rand.req.eng-row-11)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.eng-row-11-column-3-sentence-1)<br>With Sx and Sy as the infinite sequences of values that would be generated by repeated future calls to x() and y(), respectively, returns true if Sx=Sy; else returns false[.](#tab:rand.req.eng-row-11-column-3-sentence-2) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-12)<br>x != y | bool | !(x == y)[.](#tab:rand.req.eng-row-12-column-3-sentence-1) | O(size of state) |
[5](#eng-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2026)
E shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#eng-5.sentence-1)
These operations shall each be of complexity
no worse than O(size of state)[.](#eng-5.sentence-2)
[6](#eng-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2033)
On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#eng-6.sentence-1)
[🔗](#eng-itemdecl:1)
`os << x
`
[7](#eng-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2042)
*Effects*: With os.*fmtflags* set toios_base::dec|ios_base::left and the fill character set to the space character,
writes to os the textual representation
of x's current state[.](#eng-7.sentence-1)
In the output,
adjacent numbers are separated
by one or more space characters[.](#eng-7.sentence-2)
[8](#eng-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2054)
*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#eng-8.sentence-1)
[9](#eng-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2058)
*Result*: reference to the type of os[.](#eng-9.sentence-1)
[10](#eng-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2062)
*Returns*: os[.](#eng-10.sentence-1)
[11](#eng-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2066)
*Complexity*: O(size of state)
[🔗](#eng-itemdecl:2)
`is >> v
`
[12](#eng-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2076)
*Preconditions*: is provides a textual representation
that was previously written
using an output stream
whose imbued locale
was the same as that of is,
and whose type's template specialization argumentscharT and traits were respectively the same as those of is[.](#eng-12.sentence-1)
[13](#eng-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2087)
*Effects*: With is.*fmtflags* set to ios_base::dec,
sets v's state
as determined by reading its textual representation from is[.](#eng-13.sentence-1)
If bad input is encountered,
ensures that v's state is unchanged by the operation
and
calls is.setstate(ios_base::failbit) (which may throw ios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4Flags functions")))[.](#eng-13.sentence-2)
If a textual representation written via os << x was subsequently read via is >> v,
then x == v provided that there have been no intervening invocations
of x or of v[.](#eng-13.sentence-3)
[14](#eng-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2104)
*Postconditions*: The is.*fmtflags* are unchanged[.](#eng-14.sentence-1)
[15](#eng-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2108)
*Result*: reference to the type of is[.](#eng-15.sentence-1)
[16](#eng-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2112)
*Returns*: is[.](#eng-16.sentence-1)
[17](#eng-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2116)
*Complexity*: O(size of state)
[240)](#footnote-240)[240)](#footnoteref-240)
This constructor
(as well as the subsequent corresponding seed() function)
can be particularly useful
to applications requiring
a large number of independent random sequences[.](#footnote-240.sentence-1)
[241)](#footnote-241)[241)](#footnoteref-241)
This operation is common
in user code,
and can often be implemented
in an engine-specific manner
so as to provide significant performance improvements
over an equivalent naive loop
that makes z consecutive calls e()[.](#footnote-241.sentence-1)
#### [29.5.3.5](#adapt) Random number engine adaptor requirements [[rand.req.adapt]](rand.req.adapt)
[1](#adapt-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2130)
A [*random number engine adaptor*](#def:random_number_engine_adaptor) (commonly shortened to [*adaptor*](#def:adaptor))a of type A is a random number engine
that takes values
produced by some other random number engine,
and applies an algorithm to those values
in order to deliver a sequence of values
with different randomness properties[.](#adapt-1.sentence-1)
An engine b of type B adapted in this way
is termed a [*base engine*](#def:base_engine) in this context[.](#adapt-1.sentence-2)
The expression a.base() shall be valid and shall return a
const reference to a's base engine[.](#adapt-1.sentence-3)
[2](#adapt-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2146)
The requirements of a random number engine type
shall be interpreted as follows
with respect to a random number engine adaptor type[.](#adapt-2.sentence-1)
[🔗](#adapt-itemdecl:1)
`A::A();
`
[3](#adapt-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2156)
*Effects*: The base engine is initialized
as if by its default constructor[.](#adapt-3.sentence-1)
[🔗](#adapt-itemdecl:2)
`bool operator==(const A& a1, const A& a2);
`
[4](#adapt-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2167)
*Returns*: true if a1's base engine is equal to a2's base engine[.](#adapt-4.sentence-1)
Otherwise returns false[.](#adapt-4.sentence-2)
[🔗](#adapt-itemdecl:3)
`A::A(result_type s);
`
[5](#adapt-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2178)
*Effects*: The base engine is initialized
with s[.](#adapt-5.sentence-1)
[🔗](#adapt-itemdecl:4)
`template<class Sseq> A::A(Sseq& q);
`
[6](#adapt-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2189)
*Effects*: The base engine is initialized
with q[.](#adapt-6.sentence-1)
[🔗](#adapt-itemdecl:5)
`void seed();
`
[7](#adapt-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2200)
*Effects*: With b as the base engine, invokes b.seed()[.](#adapt-7.sentence-1)
[🔗](#adapt-itemdecl:6)
`void seed(result_type s);
`
[8](#adapt-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2210)
*Effects*: With b as the base engine, invokes b.seed(s)[.](#adapt-8.sentence-1)
[🔗](#adapt-itemdecl:7)
`template<class Sseq> void seed(Sseq& q);
`
[9](#adapt-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2220)
*Effects*: With b as the base engine, invokes b.seed(q)[.](#adapt-9.sentence-1)
[10](#adapt-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2225)
A shall also meet
the following additional requirements:
- [(10.1)](#adapt-10.1)
The complexity
of each function
shall not exceed the complexity
of the corresponding function
applied to the base engine[.](#adapt-10.1.sentence-1)
- [(10.2)](#adapt-10.2)
The state
of A shall include the state
of its base engine[.](#adapt-10.2.sentence-1)
The size of A's state
shall be no less than the size of the base engine[.](#adapt-10.2.sentence-2)
- [(10.3)](#adapt-10.3)
Copying A's state
(e.g., during copy construction or copy assignment)
shall include copying
the state of the base engine of A[.](#adapt-10.3.sentence-1)
- [(10.4)](#adapt-10.4)
The textual representation
of A shall include
the textual representation of its base engine[.](#adapt-10.4.sentence-1)
#### [29.5.3.6](#dist) Random number distribution requirements [[rand.req.dist]](rand.req.dist)
[1](#dist-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2261)
A [*random number distribution*](#def:random_number_distribution) (commonly shortened to [*distribution*](#def:distribution))d of type D is a function object
returning values
that are distributed according to
an associated mathematical [*probability density function*](#def:probability_density_function)p(z) or according to
an associated [*discrete probability function*](#def:discrete_probability_function)P(zi)[.](#dist-1.sentence-1)
A distribution's specification
identifies its associated probability functionp(z) or P(zi)[.](#dist-1.sentence-2)
[2](#dist-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2277)
An associated probability function is typically expressed
using certain externally-supplied quantities
known as the [*parameters of the distribution*](#def:parameters_of_the_distribution)[.](#dist-2.sentence-1)
Such distribution parameters are identified
in this context by writing, for example, p(z | a,b) or P(zi|a,b),
to name specific parameters,
or by writing, for example, p(z |{p}) or P(zi|{p}),
to denote a distribution's parameters p taken as a whole[.](#dist-2.sentence-2)
[3](#dist-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2290)
A class D meets the requirements
of a [*random number distribution*](#def:random_number_distribution) if the expressions shown
in Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") are valid and have the indicated semantics,
and if D and its associated types
also meet all other requirements
of [[rand.req.dist]](#dist "29.5.3.6Random number distribution requirements")[.](#dist-3.sentence-1)
In Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") and throughout this subclause,
- [(3.1)](#dist-3.1)
T is the type named by D's associated result_type;
- [(3.2)](#dist-3.2)
P is the type named by D's associated param_type;
- [(3.3)](#dist-3.3)
d is a
value of D,
and x and y are (possibly const) values of D;
- [(3.4)](#dist-3.4)
glb and lub are values of T respectively corresponding to
the greatest lower bound and the least upper bound
on the values potentially returned by d's operator(),
as determined by the current values of d's parameters;
- [(3.5)](#dist-3.5)
p is a (possibly const) value of P;
- [(3.6)](#dist-3.6)
g, g1, and g2 are lvalues of a type
meeting the requirements
of a [uniform random bit generator](#urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]");
- [(3.7)](#dist-3.7)
os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
and
- [(3.8)](#dist-3.8)
is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;
where charT and traits are constrained
according to [[strings]](strings "27Strings library") and [[input.output]](input.output "31Input/output library")[.](#dist-3.sentence-2)
Table [128](#tab:rand.req.dist) — Random number distribution requirements [[tab:rand.req.dist]](./tab:rand.req.dist)
| [🔗](#tab:rand.req.dist-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.dist-row-2)<br>D::result_type | T | T is an [arithmetic type](basic.fundamental#def:type,arithmetic "6.9.2Fundamental types[basic.fundamental]")[.](#tab:rand.req.dist-row-2-column-3-sentence-1) | |
| [🔗](#tab:rand.req.dist-row-3)<br>D::param_type | P | | |
| [🔗](#tab:rand.req.dist-row-4)<br>D() | | Creates a distribution whose behavior is indistinguishable from that of any other newly default-constructed distribution of type D[.](#tab:rand.req.dist-row-4-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-5)<br>D(p) | | Creates a distribution whose behavior is indistinguishable from that of a distribution newly constructed directly from the values used to construct p[.](#tab:rand.req.dist-row-5-column-3-sentence-1) | same as p's construction |
| [🔗](#tab:rand.req.dist-row-6)<br>d.reset() | void | Subsequent uses of d do not depend on values produced by any engine prior to invoking reset[.](#tab:rand.req.dist-row-6-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-7)<br>x.param() | P | Returns a value p such that D(p).param() == p[.](#tab:rand.req.dist-row-7-column-3-sentence-1) | no worse than the complexity of D(p) |
| [🔗](#tab:rand.req.dist-row-8)<br>d.param(p) | void | *Postconditions*: d.param() == p[.](#tab:rand.req.dist-row-8-column-3-sentence-1) | no worse than the complexity of D(p) |
| [🔗](#tab:rand.req.dist-row-9)<br>d(g) | T | With p=d.param(), the sequence of numbers returned by successive invocations with the same object g is randomly distributed according to the associated p(z |{p}) or P(zi|{p}) function[.](#tab:rand.req.dist-row-9-column-3-sentence-1) | amortized constant number of invocations of g |
| [🔗](#tab:rand.req.dist-row-10)<br>d(g,p) | T | The sequence of numbers returned by successive invocations with the same objects g and p is randomly distributed according to the associated p(z |{p}) or P(zi|{p}) function[.](#tab:rand.req.dist-row-10-column-3-sentence-1) | amortized constant number of invocations of g |
| [🔗](#tab:rand.req.dist-row-11)<br>x.min() | T | Returns glb[.](#tab:rand.req.dist-row-11-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-12)<br>x.max() | T | Returns lub[.](#tab:rand.req.dist-row-12-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-13)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.dist-row-13-column-3-sentence-1)<br>Returns true if x.param() == y.param() and S1=S2, where S1 and S2 are the infinite sequences of values that would be generated, respectively, by repeated future calls to x(g1) and y(g2) whenever g1 == g2[.](#tab:rand.req.dist-row-13-column-3-sentence-2)<br>Otherwise returns false[.](#tab:rand.req.dist-row-13-column-3-sentence-3) | constant |
| [🔗](#tab:rand.req.dist-row-14)<br>x != y | bool | !(x == y)[.](#tab:rand.req.dist-row-14-column-3-sentence-1) | same as x == y[.](#tab:rand.req.dist-row-14-column-4-sentence-1) |
[4](#dist-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2455)
D shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#dist-4.sentence-1)
[5](#dist-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2460)
The sequence of numbers
produced by repeated invocations of d(g) shall be independent of any invocation ofos << d or of
any const member function of D between any of the invocations of d(g)[.](#dist-5.sentence-1)
[6](#dist-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2469)
If a textual representation is written using os << x and that representation is restored
into the same or a different object y of the same type using is >> y,
repeated invocations of y(g) shall produce the same sequence of numbers
as would repeated invocations of x(g)[.](#dist-6.sentence-1)
[7](#dist-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2478)
It is unspecified whether D::param_type is declared as a (nested) class or via a typedef[.](#dist-7.sentence-1)
In [[rand]](rand "29.5Random number generation"),
declarations of D::param_type are in the form of typedefs
for convenience of exposition only[.](#dist-7.sentence-2)
[8](#dist-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2487)
P shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")),[*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")),
and[*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#dist-8.sentence-1)
[9](#dist-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2494)
For each of the constructors of D taking arguments corresponding to parameters of the distribution,P shall have a corresponding constructor
subject to the same requirements
and taking arguments identical in number, type, and default values[.](#dist-9.sentence-1)
Moreover,
for each of the member functions of D that return values corresponding to parameters of the distribution,P shall have a corresponding member function
with the identical name, type, and semantics[.](#dist-9.sentence-2)
[10](#dist-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2506)
P shall have a declaration of the formusing distribution_type = D;
[11](#dist-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2512)
On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#dist-11.sentence-1)
[🔗](#dist-itemdecl:1)
`os << x
`
[12](#dist-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2521)
*Effects*: Writes to os a textual representation
for the parameters and the additional internal data of x[.](#dist-12.sentence-1)
[13](#dist-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2526)
*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#dist-13.sentence-1)
[14](#dist-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2530)
*Result*: reference to the type of os[.](#dist-14.sentence-1)
[15](#dist-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2534)
*Returns*: os[.](#dist-15.sentence-1)
[🔗](#dist-itemdecl:2)
`is >> d
`
[16](#dist-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2544)
*Preconditions*: is provides a textual representation
that was previously written
using an os whose imbued locale
and whose type's template specialization argumentscharT and traits were the same as those of is[.](#dist-16.sentence-1)
[17](#dist-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2553)
*Effects*: Restores from is the parameters and additional internal data of the lvalue d[.](#dist-17.sentence-1)
If bad input is encountered,
ensures that d is unchanged by the operation
and
calls is.setstate(ios_base::failbit) (which may throw ios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4Flags functions")))[.](#dist-17.sentence-2)
[18](#dist-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2563)
*Postconditions*: The is.*fmtflags* are unchanged[.](#dist-18.sentence-1)
[19](#dist-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2567)
*Result*: reference to the type of is[.](#dist-19.sentence-1)
[20](#dist-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2571)
*Returns*: is[.](#dist-20.sentence-1)

152
cppdraft/rand/req/adapt.md Normal file
View File

@@ -0,0 +1,152 @@
[rand.req.adapt]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.adapt)
### 29.5.3 Requirements [[rand.req]](rand.req#adapt)
#### 29.5.3.5 Random number engine adaptor requirements [rand.req.adapt]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2130)
A [*random number engine adaptor*](#def:random_number_engine_adaptor) (commonly shortened to [*adaptor*](#def:adaptor))a of type A is a random number engine
that takes values
produced by some other random number engine,
and applies an algorithm to those values
in order to deliver a sequence of values
with different randomness properties[.](#1.sentence-1)
An engine b of type B adapted in this way
is termed a [*base engine*](#def:base_engine) in this context[.](#1.sentence-2)
The expression a.base() shall be valid and shall return a
const reference to a's base engine[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2146)
The requirements of a random number engine type
shall be interpreted as follows
with respect to a random number engine adaptor type[.](#2.sentence-1)
[🔗](#itemdecl:1)
`A::A();
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2156)
*Effects*: The base engine is initialized
as if by its default constructor[.](#3.sentence-1)
[🔗](#itemdecl:2)
`bool operator==(const A& a1, const A& a2);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2167)
*Returns*: true if a1's base engine is equal to a2's base engine[.](#4.sentence-1)
Otherwise returns false[.](#4.sentence-2)
[🔗](#itemdecl:3)
`A::A(result_type s);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2178)
*Effects*: The base engine is initialized
with s[.](#5.sentence-1)
[🔗](#itemdecl:4)
`template<class Sseq> A::A(Sseq& q);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2189)
*Effects*: The base engine is initialized
with q[.](#6.sentence-1)
[🔗](#itemdecl:5)
`void seed();
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2200)
*Effects*: With b as the base engine, invokes b.seed()[.](#7.sentence-1)
[🔗](#itemdecl:6)
`void seed(result_type s);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2210)
*Effects*: With b as the base engine, invokes b.seed(s)[.](#8.sentence-1)
[🔗](#itemdecl:7)
`template<class Sseq> void seed(Sseq& q);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2220)
*Effects*: With b as the base engine, invokes b.seed(q)[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2225)
A shall also meet
the following additional requirements:
- [(10.1)](#10.1)
The complexity
of each function
shall not exceed the complexity
of the corresponding function
applied to the base engine[.](#10.1.sentence-1)
- [(10.2)](#10.2)
The state
of A shall include the state
of its base engine[.](#10.2.sentence-1)
The size of A's state
shall be no less than the size of the base engine[.](#10.2.sentence-2)
- [(10.3)](#10.3)
Copying A's state
(e.g., during copy construction or copy assignment)
shall include copying
the state of the base engine of A[.](#10.3.sentence-1)
- [(10.4)](#10.4)
The textual representation
of A shall include
the textual representation of its base engine[.](#10.4.sentence-1)

249
cppdraft/rand/req/dist.md Normal file
View File

@@ -0,0 +1,249 @@
[rand.req.dist]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.dist)
### 29.5.3 Requirements [[rand.req]](rand.req#dist)
#### 29.5.3.6 Random number distribution requirements [rand.req.dist]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2261)
A [*random number distribution*](#def:random_number_distribution) (commonly shortened to [*distribution*](#def:distribution))d of type D is a function object
returning values
that are distributed according to
an associated mathematical [*probability density function*](#def:probability_density_function)p(z) or according to
an associated [*discrete probability function*](#def:discrete_probability_function)P(zi)[.](#1.sentence-1)
A distribution's specification
identifies its associated probability functionp(z) or P(zi)[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2277)
An associated probability function is typically expressed
using certain externally-supplied quantities
known as the [*parameters of the distribution*](#def:parameters_of_the_distribution)[.](#2.sentence-1)
Such distribution parameters are identified
in this context by writing, for example, p(z | a,b) or P(zi|a,b),
to name specific parameters,
or by writing, for example, p(z |{p}) or P(zi|{p}),
to denote a distribution's parameters p taken as a whole[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2290)
A class D meets the requirements
of a [*random number distribution*](#def:random_number_distribution) if the expressions shown
in Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") are valid and have the indicated semantics,
and if D and its associated types
also meet all other requirements
of [rand.req.dist][.](#3.sentence-1)
In Table [128](#tab:rand.req.dist "Table 128: Random number distribution requirements") and throughout this subclause,
- [(3.1)](#3.1)
T is the type named by D's associated result_type;
- [(3.2)](#3.2)
P is the type named by D's associated param_type;
- [(3.3)](#3.3)
d is a
value of D,
and x and y are (possibly const) values of D;
- [(3.4)](#3.4)
glb and lub are values of T respectively corresponding to
the greatest lower bound and the least upper bound
on the values potentially returned by d's operator(),
as determined by the current values of d's parameters;
- [(3.5)](#3.5)
p is a (possibly const) value of P;
- [(3.6)](#3.6)
g, g1, and g2 are lvalues of a type
meeting the requirements
of a [uniform random bit generator](rand.req.urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]");
- [(3.7)](#3.7)
os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
and
- [(3.8)](#3.8)
is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;
where charT and traits are constrained
according to [[strings]](strings "27Strings library") and [[input.output]](input.output "31Input/output library")[.](#3.sentence-2)
Table [128](#tab:rand.req.dist) — Random number distribution requirements [[tab:rand.req.dist]](./tab:rand.req.dist)
| [🔗](#tab:rand.req.dist-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.dist-row-2)<br>D::result_type | T | T is an [arithmetic type](basic.fundamental#def:type,arithmetic "6.9.2Fundamental types[basic.fundamental]")[.](#tab:rand.req.dist-row-2-column-3-sentence-1) | |
| [🔗](#tab:rand.req.dist-row-3)<br>D::param_type | P | | |
| [🔗](#tab:rand.req.dist-row-4)<br>D() | | Creates a distribution whose behavior is indistinguishable from that of any other newly default-constructed distribution of type D[.](#tab:rand.req.dist-row-4-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-5)<br>D(p) | | Creates a distribution whose behavior is indistinguishable from that of a distribution newly constructed directly from the values used to construct p[.](#tab:rand.req.dist-row-5-column-3-sentence-1) | same as p's construction |
| [🔗](#tab:rand.req.dist-row-6)<br>d.reset() | void | Subsequent uses of d do not depend on values produced by any engine prior to invoking reset[.](#tab:rand.req.dist-row-6-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-7)<br>x.param() | P | Returns a value p such that D(p).param() == p[.](#tab:rand.req.dist-row-7-column-3-sentence-1) | no worse than the complexity of D(p) |
| [🔗](#tab:rand.req.dist-row-8)<br>d.param(p) | void | *Postconditions*: d.param() == p[.](#tab:rand.req.dist-row-8-column-3-sentence-1) | no worse than the complexity of D(p) |
| [🔗](#tab:rand.req.dist-row-9)<br>d(g) | T | With p=d.param(), the sequence of numbers returned by successive invocations with the same object g is randomly distributed according to the associated p(z |{p}) or P(zi|{p}) function[.](#tab:rand.req.dist-row-9-column-3-sentence-1) | amortized constant number of invocations of g |
| [🔗](#tab:rand.req.dist-row-10)<br>d(g,p) | T | The sequence of numbers returned by successive invocations with the same objects g and p is randomly distributed according to the associated p(z |{p}) or P(zi|{p}) function[.](#tab:rand.req.dist-row-10-column-3-sentence-1) | amortized constant number of invocations of g |
| [🔗](#tab:rand.req.dist-row-11)<br>x.min() | T | Returns glb[.](#tab:rand.req.dist-row-11-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-12)<br>x.max() | T | Returns lub[.](#tab:rand.req.dist-row-12-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.dist-row-13)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.dist-row-13-column-3-sentence-1)<br>Returns true if x.param() == y.param() and S1=S2, where S1 and S2 are the infinite sequences of values that would be generated, respectively, by repeated future calls to x(g1) and y(g2) whenever g1 == g2[.](#tab:rand.req.dist-row-13-column-3-sentence-2)<br>Otherwise returns false[.](#tab:rand.req.dist-row-13-column-3-sentence-3) | constant |
| [🔗](#tab:rand.req.dist-row-14)<br>x != y | bool | !(x == y)[.](#tab:rand.req.dist-row-14-column-3-sentence-1) | same as x == y[.](#tab:rand.req.dist-row-14-column-4-sentence-1) |
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2455)
D shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2460)
The sequence of numbers
produced by repeated invocations of d(g) shall be independent of any invocation ofos << d or of
any const member function of D between any of the invocations of d(g)[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2469)
If a textual representation is written using os << x and that representation is restored
into the same or a different object y of the same type using is >> y,
repeated invocations of y(g) shall produce the same sequence of numbers
as would repeated invocations of x(g)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2478)
It is unspecified whether D::param_type is declared as a (nested) class or via a typedef[.](#7.sentence-1)
In [[rand]](rand "29.5Random number generation"),
declarations of D::param_type are in the form of typedefs
for convenience of exposition only[.](#7.sentence-2)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2487)
P shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")),[*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")),
and[*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2494)
For each of the constructors of D taking arguments corresponding to parameters of the distribution,P shall have a corresponding constructor
subject to the same requirements
and taking arguments identical in number, type, and default values[.](#9.sentence-1)
Moreover,
for each of the member functions of D that return values corresponding to parameters of the distribution,P shall have a corresponding member function
with the identical name, type, and semantics[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2506)
P shall have a declaration of the formusing distribution_type = D;
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2512)
On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#11.sentence-1)
[🔗](#itemdecl:1)
`os << x
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2521)
*Effects*: Writes to os a textual representation
for the parameters and the additional internal data of x[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2526)
*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2530)
*Result*: reference to the type of os[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2534)
*Returns*: os[.](#15.sentence-1)
[🔗](#itemdecl:2)
`is >> d
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2544)
*Preconditions*: is provides a textual representation
that was previously written
using an os whose imbued locale
and whose type's template specialization argumentscharT and traits were the same as those of is[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2553)
*Effects*: Restores from is the parameters and additional internal data of the lvalue d[.](#17.sentence-1)
If bad input is encountered,
ensures that d is unchanged by the operation
and
calls is.setstate(ios_base::failbit) (which may throw ios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4Flags functions")))[.](#17.sentence-2)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2563)
*Postconditions*: The is.*fmtflags* are unchanged[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2567)
*Result*: reference to the type of is[.](#19.sentence-1)
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2571)
*Returns*: is[.](#20.sentence-1)

250
cppdraft/rand/req/eng.md Normal file
View File

@@ -0,0 +1,250 @@
[rand.req.eng]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.eng)
### 29.5.3 Requirements [[rand.req]](rand.req#eng)
#### 29.5.3.4 Random number engine requirements [rand.req.eng]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1824)
A [*random number engine*](#def:random_number_engine) (commonly shortened to [*engine*](#def:engine))e of type E is a uniform random bit generator
that additionally meets the requirements
(e.g., for seeding and for input/output)
specified in this subclause[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1833)
At any given time,e has a state ei for some integer i ≥ 0[.](#2.sentence-1)
Upon construction,e has an initial state e0[.](#2.sentence-2)
An engine's state may be established via
a constructor,
a seed function,
assignment,
or a suitable operator>>[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1846)
E's specification shall define:
- [(3.1)](#3.1)
the size of E's state
in multiples of the size of result_type,
given as an integral constant expression;
- [(3.2)](#3.2)
the [*transition algorithm*](#def:transition_algorithm)TA by which e's state ei is advanced to its [*successor state*](#def:successor_state)ei+1;
and
- [(3.3)](#3.3)
the [*generation algorithm*](#def:generation_algorithm)GA by which an engine's state is mapped
to a value of type result_type[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1867)
A class E that meets the requirements
of a [uniform random bit generator](rand.req.urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") also meets the requirements
of a [*random number engine*](#def:random_number_engine) if the expressions shown
in Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") are valid and have the indicated semantics,
and if E also meets all other requirements
of [rand.req.eng][.](#4.sentence-1)
In Table [127](#tab:rand.req.eng "Table 127: Random number engine requirements") and throughout this subclause:
- [(4.1)](#4.1)
T is the type named by E's associated result_type;
- [(4.2)](#4.2)
e is a value of E, v is an lvalue of E, x and y are (possibly const) values of E;
- [(4.3)](#4.3)
s is a value of T;
- [(4.4)](#4.4)
q is an lvalue
meeting the requirements of a [seed sequence](rand.req.seedseq "29.5.3.2Seed sequence requirements[rand.req.seedseq]");
- [(4.5)](#4.5)
z is a value
of type unsigned long long;
- [(4.6)](#4.6)
os is an lvalue of the type of some class template specialization basic_ostream<charT, traits>;
and
- [(4.7)](#4.7)
is is an lvalue of the type of some class template specialization basic_istream<charT, traits>;
where charT and traits are constrained
according to [[strings]](strings "27Strings library") and [[input.output]](input.output "31Input/output library")[.](#4.sentence-2)
Table [127](#tab:rand.req.eng) — Random number engine requirements [[tab:rand.req.eng]](./tab:rand.req.eng)
| [🔗](#tab:rand.req.eng-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.eng-row-2)<br>E() | | Creates an engine with the same initial state as all other default-constructed engines of type E[.](#tab:rand.req.eng-row-2-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-3)<br>E(x) | | Creates an engine that compares equal to x[.](#tab:rand.req.eng-row-3-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-4)<br>E(s) | | Creates an engine with initial state determined by s[.](#tab:rand.req.eng-row-4-column-3-sentence-1) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-5)<br>E(q)[240](#footnote-240 "This constructor (as well as the subsequent corresponding seed() function) can be particularly useful to applications requiring a large number of independent random sequences.") | | Creates an engine with an initial state that depends on a sequence produced by one call to q.generate[.](#tab:rand.req.eng-row-5-column-3-sentence-1) | same as complexity of q.generate called on a sequence whose length is size of state |
| [🔗](#tab:rand.req.eng-row-6)<br>e.seed() | void | *Postconditions*: e == E()[.](#tab:rand.req.eng-row-6-column-3-sentence-1) | same as E() |
| [🔗](#tab:rand.req.eng-row-7)<br>e.seed(s) | void | *Postconditions*: e == E(s)[.](#tab:rand.req.eng-row-7-column-3-sentence-1) | same as E(s) |
| [🔗](#tab:rand.req.eng-row-8)<br>e.seed(q) | void | *Postconditions*: e == E(q)[.](#tab:rand.req.eng-row-8-column-3-sentence-1) | same as E(q) |
| [🔗](#tab:rand.req.eng-row-9)<br>e() | T | Advances e's state ei to ei+1 =TA(ei) and returns GA(ei)[.](#tab:rand.req.eng-row-9-column-3-sentence-1) | per [[rand.req.urng]](rand.req.urng "29.5.3.3Uniform random bit generator requirements") |
| [🔗](#tab:rand.req.eng-row-10)<br>e.discard(z)[241](#footnote-241 "This operation is common in user code, and can often be implemented in an engine-specific manner so as to provide significant performance improvements over an equivalent naive loop that makes z consecutive calls e().") | void | Advances e's state ei to ei+z by any means equivalent to z consecutive calls e()[.](#tab:rand.req.eng-row-10-column-3-sentence-1) | no worse than the complexity of z consecutive calls e() |
| [🔗](#tab:rand.req.eng-row-11)<br>x == y | bool | This operator is an equivalence relation[.](#tab:rand.req.eng-row-11-column-3-sentence-1)<br>With Sx and Sy as the infinite sequences of values that would be generated by repeated future calls to x() and y(), respectively, returns true if Sx=Sy; else returns false[.](#tab:rand.req.eng-row-11-column-3-sentence-2) | O(size of state) |
| [🔗](#tab:rand.req.eng-row-12)<br>x != y | bool | !(x == y)[.](#tab:rand.req.eng-row-12-column-3-sentence-1) | O(size of state) |
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2026)
E shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#5.sentence-1)
These operations shall each be of complexity
no worse than O(size of state)[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2033)
On hosted implementations,
the following expressions are well-formed and have the specified semantics[.](#6.sentence-1)
[🔗](#itemdecl:1)
`os << x
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2042)
*Effects*: With os.*fmtflags* set toios_base::dec|ios_base::left and the fill character set to the space character,
writes to os the textual representation
of x's current state[.](#7.sentence-1)
In the output,
adjacent numbers are separated
by one or more space characters[.](#7.sentence-2)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2054)
*Postconditions*: The os.*fmtflags* and fill character are unchanged[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2058)
*Result*: reference to the type of os[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2062)
*Returns*: os[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2066)
*Complexity*: O(size of state)
[🔗](#itemdecl:2)
`is >> v
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2076)
*Preconditions*: is provides a textual representation
that was previously written
using an output stream
whose imbued locale
was the same as that of is,
and whose type's template specialization argumentscharT and traits were respectively the same as those of is[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2087)
*Effects*: With is.*fmtflags* set to ios_base::dec,
sets v's state
as determined by reading its textual representation from is[.](#13.sentence-1)
If bad input is encountered,
ensures that v's state is unchanged by the operation
and
calls is.setstate(ios_base::failbit) (which may throw ios_base::failure ([[iostate.flags]](iostate.flags "31.5.4.4Flags functions")))[.](#13.sentence-2)
If a textual representation written via os << x was subsequently read via is >> v,
then x == v provided that there have been no intervening invocations
of x or of v[.](#13.sentence-3)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2104)
*Postconditions*: The is.*fmtflags* are unchanged[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2108)
*Result*: reference to the type of is[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2112)
*Returns*: is[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L2116)
*Complexity*: O(size of state)
[240)](#footnote-240)[240)](#footnoteref-240)
This constructor
(as well as the subsequent corresponding seed() function)
can be particularly useful
to applications requiring
a large number of independent random sequences[.](#footnote-240.sentence-1)
[241)](#footnote-241)[241)](#footnoteref-241)
This operation is common
in user code,
and can often be implemented
in an engine-specific manner
so as to provide significant performance improvements
over an equivalent naive loop
that makes z consecutive calls e()[.](#footnote-241.sentence-1)

83
cppdraft/rand/req/genl.md Normal file
View File

@@ -0,0 +1,83 @@
[rand.req.genl]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.genl)
### 29.5.3 Requirements [[rand.req]](rand.req#genl)
#### 29.5.3.1 General requirements [rand.req.genl]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1557)
Throughout [[rand]](rand "29.5Random number generation"),
the effect of instantiating a template:
- [(1.1)](#1.1)
that has a template type parameter
named Sseq is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [seed sequence](rand.req.seedseq "29.5.3.2Seed sequence requirements[rand.req.seedseq]")[.](#1.1.sentence-1)
- [(1.2)](#1.2)
that has a template type parameter
named URBG is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [uniform random bit generator](rand.req.urng "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")[.](#1.2.sentence-1)
- [(1.3)](#1.3)
that has a template type parameter
named Engine is undefined unless the corresponding template argument
is cv-unqualified and
meets the requirements
of [random number engine](rand.req.eng "29.5.3.4Random number engine requirements[rand.req.eng]")[.](#1.3.sentence-1)
- [(1.4)](#1.4)
that has a template type parameter
named RealType is undefined unless the corresponding template argument
is cv-unqualified and
is one of float, double, or long double[.](#1.4.sentence-1)
- [(1.5)](#1.5)
that has a template type parameter
named IntType is undefined unless the corresponding template argument
is cv-unqualified and
is one of short, int, long, long long, unsigned short, unsigned int, unsigned long,
or unsigned long long[.](#1.5.sentence-1)
- [(1.6)](#1.6)
that has a template type parameter
named UIntType is undefined unless the corresponding template argument
is cv-unqualified and
is one of unsigned short, unsigned int, unsigned long,
or unsigned long long[.](#1.6.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1617)
Throughout [[rand]](rand "29.5Random number generation"),
phrases of the form “x is an iterator of a specific kind”
shall be interpreted as equivalent to the more formal requirement that
“x is a value
of a type meeting the requirements
of the specified iterator type”[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1625)
Throughout [[rand]](rand "29.5Random number generation"),
any constructor that can be called with a single argument
and that meets a requirement specified in this subclause
shall be declared explicit[.](#3.sentence-1)

View File

@@ -0,0 +1,82 @@
[rand.req.seedseq]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.seedseq)
### 29.5.3 Requirements [[rand.req]](rand.req#seedseq)
#### 29.5.3.2 Seed sequence requirements [rand.req.seedseq]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1638)
A [*seed sequence*](#def:seed_sequence "29.5.3.2Seed sequence requirements[rand.req.seedseq]") is an object
that consumes a sequence
of integer-valued data
and produces a requested number
of unsigned integer values i, 0≤i<232,
based on the consumed data[.](#1.sentence-1)
[*Note [1](#note-1)*:
Such an object provides a mechanism
to avoid replication of streams of random variates[.](#1.sentence-2)
This can be useful, for example, in applications
requiring large numbers of random number engines[.](#1.sentence-3)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1653)
A class S meets the requirements
of a seed sequence
if the expressions shown
in Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") are valid and have the indicated semantics,
and if S also meets all other requirements
of [rand.req.seedseq][.](#2.sentence-1)
In Table [126](#tab:rand.req.seedseq "Table 126: Seed sequence requirements") and throughout this subclause:
- [(2.1)](#2.1)
T is the type named by S's associated result_type;
- [(2.2)](#2.2)
q is a value of type S and r is a value of type S or const S;
- [(2.3)](#2.3)
ib and ie are input iterators
with an unsigned integer value_type of at least 32 bits;
- [(2.4)](#2.4)
rb and re are mutable random access iterators
with an unsigned integer value_type of at least 32 bits;
- [(2.5)](#2.5)
ob is an output iterator;
and
- [(2.6)](#2.6)
il is a value of type initializer_list<T>[.](#2.sentence-2)
Table [126](#tab:rand.req.seedseq) — Seed sequence requirements [[tab:rand.req.seedseq]](./tab:rand.req.seedseq)
| [🔗](#tab:rand.req.seedseq-row-1)<br>**Expression** | **Return type** | **Pre/post-condition** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:rand.req.seedseq-row-2)<br>S::result_type | T | T is an [unsigned integer type](basic.fundamental#def:type,unsigned_integer "6.9.2Fundamental types[basic.fundamental]") of at least 32 bits[.](#tab:rand.req.seedseq-row-2-column-3-sentence-1) | |
| [🔗](#tab:rand.req.seedseq-row-3)<br>S() | | Creates a seed sequence with the same initial state as all other default-constructed seed sequences of type S[.](#tab:rand.req.seedseq-row-3-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.seedseq-row-4)<br>S(ib,ie) | | Creates a seed sequence having internal state that depends on some or all of the bits of the supplied sequence [ib,ie)[.](#tab:rand.req.seedseq-row-4-column-3-sentence-1) | O(ie−ib) |
| [🔗](#tab:rand.req.seedseq-row-5)<br>S(il) | | Same as S(il.begin(), il.end())[.](#tab:rand.req.seedseq-row-5-column-3-sentence-1) | same as S(il.begin(), il.end()) |
| [🔗](#tab:rand.req.seedseq-row-6)<br>q.generate(rb,re) | void | Does nothing if rb == re[.](#tab:rand.req.seedseq-row-6-column-3-sentence-1)<br>Otherwise, fills the supplied sequence [rb,re) with 32-bit quantities that depend on the sequence supplied to the constructor and possibly also depend on the history of generate's previous invocations[.](#tab:rand.req.seedseq-row-6-column-3-sentence-2) | O(re−rb) |
| [🔗](#tab:rand.req.seedseq-row-7)<br>r.size() | size_t | The number of 32-bit units that would be copied by a call to r.param[.](#tab:rand.req.seedseq-row-7-column-3-sentence-1) | constant |
| [🔗](#tab:rand.req.seedseq-row-8)<br>r.param(ob) | void | Copies to the given destination a sequence of 32-bit units that can be provided to the constructor of a second object of type S, and that would reproduce in that second object a state indistinguishable from the state of the first object[.](#tab:rand.req.seedseq-row-8-column-3-sentence-1) | O(r.size()) |

57
cppdraft/rand/req/urng.md Normal file
View File

@@ -0,0 +1,57 @@
[rand.req.urng]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#req.urng)
### 29.5.3 Requirements [[rand.req]](rand.req#urng)
#### 29.5.3.3 Uniform random bit generator requirements [rand.req.urng]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1771)
A [*uniform random bit generator*](#def:uniform_random_bit_generator)g of type G is a function object
returning unsigned integer values
such that each value
in the range of possible results
has (ideally) equal probability
of being returned[.](#1.sentence-1)
[*Note [1](#note-1)*:
The degree to which g's results
approximate the ideal
is often determined statistically[.](#1.sentence-2)
— *end note*]
template<class G>concept [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") =[invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<G&> && [unsigned_integral](concepts.arithmetic#concept:unsigned_integral "18.4.7Arithmetic concepts[concepts.arithmetic]")<invoke_result_t<G&>> &&requires {{ G::min() } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<invoke_result_t<G&>>; { G::max() } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<invoke_result_t<G&>>; requires bool_constant<(G::min() < G::max())>::value; };
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1797)
Let g be an object of type G[.](#2.sentence-1)
G models[uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]") only if
- [(2.1)](#2.1)
G::min() <= g(),
- [(2.2)](#2.2)
g() <= G::max(), and
- [(2.3)](#2.3)
g() has amortized constant complexity[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1808)
A class G meets the [*uniform random bit generator*](#def:uniform_random_bit_generator) requirements ifG models [uniform_random_bit_generator](#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]"),invoke_result_t<G&> is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types")),
andG provides a nested [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]") result_type that denotes the same type as invoke_result_t<G&>[.](#3.sentence-1)

12
cppdraft/rand/synopsis.md Normal file

File diff suppressed because one or more lines are too long

301
cppdraft/rand/util.md Normal file
View File

@@ -0,0 +1,301 @@
[rand.util]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#util)
### 29.5.8 Utilities [rand.util]
#### [29.5.8.1](#seedseq) Class seed_seq [[rand.util.seedseq]](rand.util.seedseq)
[🔗](#lib:seed_seq)
namespace std {class seed_seq {public:// typesusing result_type = uint_least32_t; // constructors seed_seq() noexcept; template<class T> seed_seq(initializer_list<T> il); template<class InputIterator> seed_seq(InputIterator begin, InputIterator end); // generating functionstemplate<class RandomAccessIterator>void generate(RandomAccessIterator begin, RandomAccessIterator end); // property functions size_t size() const noexcept; template<class OutputIterator>void param(OutputIterator dest) const; // no copy functions seed_seq(const seed_seq&) = delete; void operator=(const seed_seq&) = delete; private: vector<result_type> v; // *exposition only*};}
[🔗](#lib:seed_seq,constructor)
`seed_seq() noexcept;
`
[1](#seedseq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4198)
*Postconditions*: v.empty() is true[.](#seedseq-1.sentence-1)
[🔗](#lib:seed_seq,constructor_)
`template<class T>
seed_seq(initializer_list<T> il);
`
[2](#seedseq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4211)
*Constraints*: T is an integer type[.](#seedseq-2.sentence-1)
[3](#seedseq-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4215)
*Effects*: Same as seed_seq(il.begin(), il.end())[.](#seedseq-3.sentence-1)
[🔗](#lib:seed_seq,constructor__)
`template<class InputIterator>
seed_seq(InputIterator begin, InputIterator end);
`
[4](#seedseq-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4228)
*Mandates*: iterator_traits<InputIterator>::value_type is an integer type[.](#seedseq-4.sentence-1)
[5](#seedseq-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4233)
*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#seedseq-5.sentence-1)
[6](#seedseq-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4238)
*Effects*: Initializes v by the following algorithm:for (InputIterator s = begin; s != end; ++s) v.push_back((*s)mod232);
[🔗](#lib:generate,seed_seq)
`template<class RandomAccessIterator>
void generate(RandomAccessIterator begin, RandomAccessIterator end);
`
[7](#seedseq-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4255)
*Mandates*: iterator_traits<RandomAccessIterator>::value_type is an unsigned integer type capable of accommodating 32-bit quantities[.](#seedseq-7.sentence-1)
[8](#seedseq-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4260)
*Preconditions*: RandomAccessIterator meets the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators"))
and the requirements of a mutable iterator[.](#seedseq-8.sentence-1)
[9](#seedseq-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4266)
*Effects*: Does nothing if begin == end[.](#seedseq-9.sentence-1)
Otherwise,
with s=v.size() and n=end−begin,
fills the supplied range [begin,end) according to the following algorithm
in which
each operation is to be carried out modulo 232,
each indexing operator applied to begin is to be taken modulo n,
and T(x) is defined as x xor(x rshift27):
- [(9.1)](#seedseq-9.1)
By way of initialization,
set each element of the range to the value 0x8b8b8b8b[.](#seedseq-9.1.sentence-1)
Additionally,
for use in subsequent steps,
let p=(n−t)/2 and let q=p+t,
where
t=(n≥623) ? 11 : (n≥68) ? 7 : (n≥39) ? 5 : (n≥7) ? 3 : (n−1)/2;
- [(9.2)](#seedseq-9.2)
With m as the larger of s+1 and n,
transform the elements of the range:
iteratively for k=0,…,m−1,
calculate values
r1=1664525â‹T(begin[k]xorbegin[k+p]xorbegin[k−1])r2=r1+⎧⎪⎨⎪⎩s, k=0kmodn+v[k−1], 0<‰¤skmodn, s<k and, in order,
increment begin[k+p] by r1,
increment begin[k+q] by r2,
and
set begin[k] to r2[.](#seedseq-9.2.sentence-1)
- [(9.3)](#seedseq-9.3)
Transform the elements of the range again,
beginning where the previous step ended:
iteratively for k=m,…,m+n−1,
calculate values
r3=1566083941â‹T(begin[k]+begin[k+p]+begin[k−1])r4=r3−(kmodn) and, in order,
update begin[k+p] by xoring it with r3,
update begin[k+q] by xoring it with r4,
and
set begin[k] to r4[.](#seedseq-9.3.sentence-1)
[10](#seedseq-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4339)
*Throws*: What and when RandomAccessIterator operations of begin and end throw[.](#seedseq-10.sentence-1)
[🔗](#lib:size,seed_seq)
`size_t size() const noexcept;
`
[11](#seedseq-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4351)
*Returns*: The number of 32-bit units
that would be returned
by a call to param()[.](#seedseq-11.sentence-1)
[12](#seedseq-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4357)
*Complexity*: Constant time[.](#seedseq-12.sentence-1)
[🔗](#lib:param,seed_seq)
`template<class OutputIterator>
void param(OutputIterator dest) const;
`
[13](#seedseq-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4369)
*Mandates*: Values of type result_type are writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to dest[.](#seedseq-13.sentence-1)
[14](#seedseq-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4373)
*Preconditions*: OutputIterator meets the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4Output iterators[output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4Output iterators"))[.](#seedseq-14.sentence-1)
[15](#seedseq-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4378)
*Effects*: Copies the sequence of prepared 32-bit units
to the given destination,
as if by executing the following statement:copy(v.begin(), v.end(), dest);
[16](#seedseq-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4387)
*Throws*: What and when OutputIterator operations of dest throw[.](#seedseq-16.sentence-1)
#### [29.5.8.2](#canonical) Function template generate_canonical [[rand.util.canonical]](rand.util.canonical)
[🔗](#lib:generate_canonical)
`template<class RealType, size_t digits, class URBG>
RealType generate_canonical(URBG& g);
`
[1](#canonical-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4404)
Let
- [(1.1)](#canonical-1.1)
r be numeric_limits<RealType>::radix,
- [(1.2)](#canonical-1.2)
R be g.max()−g.min()+1,
- [(1.3)](#canonical-1.3)
d be the smaller of digits and numeric_limits<RealType>::digits,[245](#footnote-245 "d is introduced to avoid any attempt to produce more bits of randomness than can be held in RealType.")
- [(1.4)](#canonical-1.4)
k be the smallest integer such that Rk≥rd, and
- [(1.5)](#canonical-1.5)
x be ⌊Rk/rd⌋[.](#canonical-1.sentence-1)
An [*attempt*](#def:attempt "29.5.8.2Function template generate_­canonical[rand.util.canonical]") is k invocations of g() to obtain values g0,…,gk−1, respectively,
and the calculation of a quantity S given by Formula [29.1](#eq:rand.gencanonical):
S=k−ˆ‘i=0(gi−g.min())â‹Ri(29.1)
[2](#canonical-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4426)
*Effects*: Attempts are made until S<xrd[.](#canonical-2.sentence-1)
[*Note [1](#canonical-note-1)*:
When R is a power of r, precisely one attempt is made[.](#canonical-2.sentence-2)
— *end note*]
[3](#canonical-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4433)
*Returns*: ⌊S/Œ‹/rd[.](#canonical-3.sentence-1)
[*Note [2](#canonical-note-2)*:
The return value c satisfies0≤c<1[.](#canonical-3.sentence-2)
— *end note*]
[4](#canonical-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4441)
*Throws*: What and when g throws[.](#canonical-4.sentence-1)
[5](#canonical-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4445)
*Complexity*: Exactly k invocations of g per attempt[.](#canonical-5.sentence-1)
[6](#canonical-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4449)
[*Note [3](#canonical-note-3)*:
If the values gi produced by g are uniformly distributed,
the instantiation's results are distributed as uniformly as possible[.](#canonical-6.sentence-1)
Obtaining a value in this way
can be a useful step
in the process of transforming
a value generated by a uniform random bit generator
into a value
that can be delivered by a random number distribution[.](#canonical-6.sentence-2)
— *end note*]
[7](#canonical-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4461)
[*Note [4](#canonical-note-4)*:
When R is a power of r,
an implementation can avoid using an arithmetic type that is wider
than the output when computing S[.](#canonical-7.sentence-1)
— *end note*]
[245)](#footnote-245)[245)](#footnoteref-245)
d is introduced to avoid any attempt
to produce more bits of randomness
than can be held in RealType[.](#footnote-245.sentence-1)

View File

@@ -0,0 +1,118 @@
[rand.util.canonical]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#util.canonical)
### 29.5.8 Utilities [[rand.util]](rand.util#canonical)
#### 29.5.8.2 Function template generate_canonical [rand.util.canonical]
[🔗](#lib:generate_canonical)
`template<class RealType, size_t digits, class URBG>
RealType generate_canonical(URBG& g);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4404)
Let
- [(1.1)](#1.1)
r be numeric_limits<RealType>::radix,
- [(1.2)](#1.2)
R be g.max()−g.min()+1,
- [(1.3)](#1.3)
d be the smaller of digits and numeric_limits<RealType>::digits,[245](#footnote-245 "d is introduced to avoid any attempt to produce more bits of randomness than can be held in RealType.")
- [(1.4)](#1.4)
k be the smallest integer such that Rk≥rd, and
- [(1.5)](#1.5)
x be ⌊Rk/rd⌋[.](#1.sentence-1)
An [*attempt*](#def:attempt "29.5.8.2Function template generate_­canonical[rand.util.canonical]") is k invocations of g() to obtain values g0,…,gk−1, respectively,
and the calculation of a quantity S given by Formula [29.1](#eq:rand.gencanonical):
S=k−ˆ‘i=0(gi−g.min())â‹Ri(29.1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4426)
*Effects*: Attempts are made until S<xrd[.](#2.sentence-1)
[*Note [1](#note-1)*:
When R is a power of r, precisely one attempt is made[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4433)
*Returns*: ⌊S/Œ‹/rd[.](#3.sentence-1)
[*Note [2](#note-2)*:
The return value c satisfies0≤c<1[.](#3.sentence-2)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4441)
*Throws*: What and when g throws[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4445)
*Complexity*: Exactly k invocations of g per attempt[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4449)
[*Note [3](#note-3)*:
If the values gi produced by g are uniformly distributed,
the instantiation's results are distributed as uniformly as possible[.](#6.sentence-1)
Obtaining a value in this way
can be a useful step
in the process of transforming
a value generated by a uniform random bit generator
into a value
that can be delivered by a random number distribution[.](#6.sentence-2)
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4461)
[*Note [4](#note-4)*:
When R is a power of r,
an implementation can avoid using an arithmetic type that is wider
than the output when computing S[.](#7.sentence-1)
— *end note*]
[245)](#footnote-245)[245)](#footnoteref-245)
d is introduced to avoid any attempt
to produce more bits of randomness
than can be held in RealType[.](#footnote-245.sentence-1)

View File

@@ -0,0 +1,190 @@
[rand.util.seedseq]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#util.seedseq)
### 29.5.8 Utilities [[rand.util]](rand.util#seedseq)
#### 29.5.8.1 Class seed_seq [rand.util.seedseq]
[🔗](#lib:seed_seq)
namespace std {class seed_seq {public:// typesusing result_type = uint_least32_t; // constructors seed_seq() noexcept; template<class T> seed_seq(initializer_list<T> il); template<class InputIterator> seed_seq(InputIterator begin, InputIterator end); // generating functionstemplate<class RandomAccessIterator>void generate(RandomAccessIterator begin, RandomAccessIterator end); // property functions size_t size() const noexcept; template<class OutputIterator>void param(OutputIterator dest) const; // no copy functions seed_seq(const seed_seq&) = delete; void operator=(const seed_seq&) = delete; private: vector<result_type> v; // *exposition only*};}
[🔗](#lib:seed_seq,constructor)
`seed_seq() noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4198)
*Postconditions*: v.empty() is true[.](#1.sentence-1)
[🔗](#lib:seed_seq,constructor_)
`template<class T>
seed_seq(initializer_list<T> il);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4211)
*Constraints*: T is an integer type[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4215)
*Effects*: Same as seed_seq(il.begin(), il.end())[.](#3.sentence-1)
[🔗](#lib:seed_seq,constructor__)
`template<class InputIterator>
seed_seq(InputIterator begin, InputIterator end);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4228)
*Mandates*: iterator_traits<InputIterator>::value_type is an integer type[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4233)
*Preconditions*: InputIterator meets the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4238)
*Effects*: Initializes v by the following algorithm:for (InputIterator s = begin; s != end; ++s) v.push_back((*s)mod232);
[🔗](#lib:generate,seed_seq)
`template<class RandomAccessIterator>
void generate(RandomAccessIterator begin, RandomAccessIterator end);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4255)
*Mandates*: iterator_traits<RandomAccessIterator>::value_type is an unsigned integer type capable of accommodating 32-bit quantities[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4260)
*Preconditions*: RandomAccessIterator meets the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators"))
and the requirements of a mutable iterator[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4266)
*Effects*: Does nothing if begin == end[.](#9.sentence-1)
Otherwise,
with s=v.size() and n=end−begin,
fills the supplied range [begin,end) according to the following algorithm
in which
each operation is to be carried out modulo 232,
each indexing operator applied to begin is to be taken modulo n,
and T(x) is defined as x xor(x rshift27):
- [(9.1)](#9.1)
By way of initialization,
set each element of the range to the value 0x8b8b8b8b[.](#9.1.sentence-1)
Additionally,
for use in subsequent steps,
let p=(n−t)/2 and let q=p+t,
where
t=(n≥623) ? 11 : (n≥68) ? 7 : (n≥39) ? 5 : (n≥7) ? 3 : (n−1)/2;
- [(9.2)](#9.2)
With m as the larger of s+1 and n,
transform the elements of the range:
iteratively for k=0,…,m−1,
calculate values
r1=1664525â‹T(begin[k]xorbegin[k+p]xorbegin[k−1])r2=r1+⎧⎪⎨⎪⎩s, k=0kmodn+v[k−1], 0<‰¤skmodn, s<k and, in order,
increment begin[k+p] by r1,
increment begin[k+q] by r2,
and
set begin[k] to r2[.](#9.2.sentence-1)
- [(9.3)](#9.3)
Transform the elements of the range again,
beginning where the previous step ended:
iteratively for k=m,…,m+n−1,
calculate values
r3=1566083941â‹T(begin[k]+begin[k+p]+begin[k−1])r4=r3−(kmodn) and, in order,
update begin[k+p] by xoring it with r3,
update begin[k+q] by xoring it with r4,
and
set begin[k] to r4[.](#9.3.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4339)
*Throws*: What and when RandomAccessIterator operations of begin and end throw[.](#10.sentence-1)
[🔗](#lib:size,seed_seq)
`size_t size() const noexcept;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4351)
*Returns*: The number of 32-bit units
that would be returned
by a call to param()[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4357)
*Complexity*: Constant time[.](#12.sentence-1)
[🔗](#lib:param,seed_seq)
`template<class OutputIterator>
void param(OutputIterator dest) const;
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4369)
*Mandates*: Values of type result_type are writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to dest[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4373)
*Preconditions*: OutputIterator meets the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4Output iterators[output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4Output iterators"))[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4378)
*Effects*: Copies the sequence of prepared 32-bit units
to the given destination,
as if by executing the following statement:copy(v.begin(), v.end(), dest);
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4387)
*Throws*: What and when OutputIterator operations of dest throw[.](#16.sentence-1)