independent_bits_engine Class
Generates a random sequence of numbers with a specified number of bits by repacking bits from the values returned by its base engine.
template<class Engine,
size_t W, class UIntType>
class independent_bits_engine {
public:
typedef Engine base_type;
typedef typename base_type::result_type result_type;
independent_bits_engine();
explicit independent_bits_engine(const base_type& eng);
explicit independent_bits_engine(result_type x0);
explicit independent_bits_engine(seed_seq& seq);
void seed();
void seed(result_type x0);
void seed(seed_seq& seq);
const base_type& base() const;
static const result_type min();
static const result_type max();
result_type operator()();
void discard(unsigned long long count);
private:
Engine stored_eng;
int count;
};
Parameters
Engine
The stored engine type.W
The W engine parameter.UIntType
The unsigned integer result type.
Remarks
This template class describes a <random> that produces values by repacking bits from the values returned by its base engine. Each resulting W-bit value consists of N fields combined as follows:
The first N0 fields consist of the low-order W0 bits of values returned by the base engine that are less than Y0, packed in descending order of significance. Values that are too large are discarded.
The remaining N - N0 fields consist of the low-order W0 + 1 bits of values returned by the base engine that are less than Y1, packed in descending order of significance. Values that are too large are discarded.
The parameters (other than W) are determined as follows:
R is the full range of values returned by the base engine (stored_eng.max() - stored_eng.min() + 1, assuming no wraparound occurs.)
M is floor(log2(R)).
N is initially W / M + (W % M != 0).
W0 is W / N.
N0 is N - W % N.
Y0 is (R >> W0) << W0.
Y1 is (R >> W0 + 1) << W0 + 1.
If Y0 / N < R - Y0 then N is incremented and the previous four parameters are redetermined.
The engine's state is the state of stored_eng. The value of the template argument W must be greater than zero and not greater than the number of bits representable in result_type.
Requirements
Header: <random>
Namespace: std
See Also
Reference
independent_bits_engine::base_type
independent_bits_engine::discard
independent_bits_engine::independent_bits_engine
independent_bits_engine::operator()