...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::random::independent_bits_engine
// In header: <boost/random/independent_bits.hpp> template<typename Engine, std::size_t w, typename UIntType> class independent_bits_engine { public: // types typedef Engine base_type; typedef UIntType result_type; typedef Engine::result_type base_result_type; // public static functions static constexpr result_type min(); static constexpr result_type max(); // public member functions independent_bits_engine(); explicit independent_bits_engine(base_result_type); template<typename SeedSeq> explicit independent_bits_engine(SeedSeq &); independent_bits_engine(const base_type &); template<typename It> independent_bits_engine(It &, It); void seed(); void seed(base_result_type); template<typename SeedSeq> void seed(SeedSeq &); template<typename It> void seed(It &, It); result_type operator()(); template<typename Iter> void generate(Iter, Iter); void discard(boost::uintmax_t); const base_type & base() const; // friend functions template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const independent_bits_engine &); template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, const independent_bits_engine &); bool operator==(const independent_bits_engine &, const independent_bits_engine &); bool operator!=(const independent_bits_engine &, const independent_bits_engine &); // public data members static const bool has_fixed_range; };
An instantiation of class template independent_bits_engine
model a pseudo-random number generator . It generates random numbers distributed between [0, 2^w) by combining one or more invocations of the base engine.
Requires: 0 < w <= std::numeric_limits<UIntType>::digits
independent_bits_engine
public member functionsindependent_bits_engine();
Constructs an independent_bits_engine
using the default constructor of the base generator.
explicit independent_bits_engine(base_result_type seed);
Constructs an independent_bits_engine
, using seed as the constructor argument for both base generators.
template<typename SeedSeq> explicit independent_bits_engine(SeedSeq & seq);
Constructs an independent_bits_engine
, using seq as the constructor argument for the base generator.
independent_bits_engine(const base_type & base_arg);
Constructs an independent_bits_engine
by copying base
.
template<typename It> independent_bits_engine(It & first, It last);
Contructs an independent_bits_engine
with values from the range defined by the input iterators first and last. first will be modified to point to the element after the last one used.
Throws: std::invalid_argument
if the input range is too small.
Exception Safety: Basic
void seed();
Seeds an independent_bits_engine
using the default seed of the base generator.
void seed(base_result_type seed);
Seeds an independent_bits_engine
, using seed
as the seed for the base generator.
template<typename SeedSeq> void seed(SeedSeq & seq);
Seeds an independent_bits_engine
, using seq
to seed the base generator.
template<typename It> void seed(It & first, It last);
Seeds an independent_bits_engine
with values from the range defined by the input iterators first and last. first will be modified to point to the element after the last one used.
Throws: std::invalid_argument
if the input range is too small.
Exception Safety: Basic
result_type operator()();
Returns the next value of the generator.
template<typename Iter> void generate(Iter first, Iter last);
Fills a range with random values
void discard(boost::uintmax_t z);
Advances the state of the generator by z
.
const base_type & base() const;
independent_bits_engine
friend functionstemplate<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & os, const independent_bits_engine & r);
Writes the textual representation if the generator to a std::ostream
. The textual representation of the engine is the textual representation of the base engine.
template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, const independent_bits_engine & r);
Reads the state of an independent_bits_engine
from a std::istream
.
bool operator==(const independent_bits_engine & x, const independent_bits_engine & y);
Returns: true iff the two independent_bits_engines
will produce the same sequence of values.
bool operator!=(const independent_bits_engine & lhs, const independent_bits_engine & rhs);
Returns: true iff the two independent_bits_engines
will produce different sequences of values.