...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::xor_combine
// In header: <boost/random/xor_combine.hpp> template<typename URNG1, int s1, typename URNG2, int s2> class xor_combine { public: // types typedef URNG1 base1_type; typedef URNG2 base2_type; typedef base1_type::result_type result_type; // construct/copy/destruct xor_combine(); xor_combine(const base1_type &, const base2_type &); xor_combine(const result_type &); template<typename It> xor_combine(It &, It); // public member functions void seed(); void seed(const result_type &); template<typename It> void seed(It &, It); const base1_type & base1(); const base2_type & base2(); result_type operator()(); result_type min() const; result_type max() const; // public static functions static bool validation(result_type); static const bool has_fixed_range; static const int shift1; static const int shift2; };
Instantiations of xor_combine
model a pseudo-random number generator . To produce its output it invokes each of the base generators, shifts their results and xors them together.
xor_combine
public
construct/copy/destructxor_combine();
Constructors a xor_combine
by default constructing both base generators.
xor_combine(const base1_type & rng1, const base2_type & rng2);
Constructs a xor_combine
by copying two base generators.
xor_combine(const result_type & v);
Constructs a xor_combine
, seeding both base generators with v
.
template<typename It> xor_combine(It & first, It last);
Constructs a xor_combine
, seeding both base generators with values from the iterator range [first, last) and changes first to point to the element after the last one used. If there are not enough elements in the range to seed both generators, throws std::invalid_argument
.
xor_combine
public member functionsvoid seed();
Calls seed()
for both base generators.
void seed(const result_type & v);
seeds
both base generators with v
.
template<typename It> void seed(It & first, It last);
seeds both base generators with values from the iterator range [first, last) and changes first to point to the element after the last one used. If there are not enough elements in the range to seed both generators, throws std::invalid_argument
.
const base1_type & base1();
Returns the first base generator.
const base2_type & base2();
Returns the second base generator.
result_type operator()();
Returns the next value of the generator.
result_type min() const;
Returns the smallest value that the generator can produce.
result_type max() const;
Returns the largest value that the generator can produce.