[rand.adapt.ibits] (original) (raw)
26 Numerics library [numerics]
26.6 Random number generation [rand]
26.6.4 Random number engine adaptor class templates [rand.adapt]
26.6.4.3 Class template independent_bits_engine [rand.adapt.ibits]
An independent_bits_enginerandom 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.
The state xof an independent_bits_engineengine adaptor object xconsists of the state e of its base engine e; the size of the state is the size of e's state.
The transition and generation algorithms are described in terms of the following integral constants:
- Let and.
- With n as determined below, let,,, and.
- Let if and only if the relation holds as a result. Otherwise let.
[ Note
:
The relation always holds.
— end note
]
The transition algorithmis carried out by invoking e()as often as needed to obtain values less than and values less than .
The generation algorithmuses the values produced while advancing the state as described above to yield a quantity Sobtained as if by the following algorithm:
S = 0; for (k = 0; ; k += 1) { do u = e() - e.min(); while (); S = ; } for (k = ; ; k += 1) { do u = e() - e.min(); while (); S = ; }
template<class Engine, size_t w, class UIntType> class independent_bits_engine { public: // types using result_type = UIntType;
// engine characteristics
static constexpr result_type min() { return 0; }
static constexpr result_type max() { return ; }
// 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);
// generating functions
result_type operator()();
void discard(unsigned long long z);
// property functions
const Engine& base() const noexcept { return e; };private: Engine e; // exposition only };
The following relations shall hold:0 < wandw <= numeric_limits<result_type>::digits.
The textual representationconsists of the textual representation of e.