73 lines
3.6 KiB
Markdown
73 lines
3.6 KiB
Markdown
[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.5 Random number engine adaptor requirements"),
|
||
each constructor that is not a copy constructor
|
||
sets n to 0[.](#6.sentence-1)
|