26 Numerics library [numerics]

26.6 Random number generation [rand]

26.6.4 Random number engine adaptor class templates [rand.adapt] Class template independent_­bits_­engine [rand.adapt.ibits]

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.
The state x of an independent_­bits_­engine engine adaptor object x consists 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 .
The relation always holds.
— end note]
The transition algorithm is carried out by invoking e() as often as needed to obtain values less than and values less than .
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 += 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 {
    // types
    using result_type = UIntType;

    // engine characteristics
    static constexpr result_type min() { return 0; }
    static constexpr result_type max() { return ; }

    // constructors and seeding functions
    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; };

    Engine e;   // exposition only
The following relations shall hold: 0 < w and w <= numeric_­limits<result_­type>​::​digits.
The textual representation consists of the textual representation of e.