...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_engine
// In header: <boost/random/xor_combine.hpp> template<typename URNG1, int s1, typename URNG2, int s2> class xor_combine_engine { public: // types typedef URNG1 base1_type; typedef URNG2 base2_type; typedef base1_type::result_type result_type; // public member functions xor_combine_engine(); xor_combine_engine(const base1_type &, const base2_type &); explicit xor_combine_engine(result_type); template<typename SeedSeq> explicit xor_combine_engine(SeedSeq &); template<typename It> xor_combine_engine(It &, It); void seed(); void seed(result_type); template<typename SeedSeq> void seed(SeedSeq &); template<typename It> void seed(It &, It); const base1_type & base1() const; const base2_type & base2() const; result_type operator()(); template<typename Iter> void generate(Iter, Iter); void discard(boost::uintmax_t); // public static functions static constexpr result_type min(); static constexpr result_type max(); // friend functions template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const xor_combine_engine &); template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, const xor_combine_engine &); bool operator==(const xor_combine_engine &, const xor_combine_engine &); bool operator!=(const xor_combine_engine &, const xor_combine_engine &); // public data members static const bool has_fixed_range; static const int shift1; static const int shift2; };
Instantiations of xor_combine_engine
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_engine
public member functionsxor_combine_engine();
Constructors a xor_combine_engine
by default constructing both base generators.
xor_combine_engine(const base1_type & rng1, const base2_type & rng2);
Constructs a xor_combine
by copying two base generators.
explicit xor_combine_engine(result_type v);
Constructs a xor_combine_engine
, seeding both base generators with v
.
Warning | |
---|---|
The exact algorithm used by this function may change in the future. |
template<typename SeedSeq> explicit xor_combine_engine(SeedSeq & seq);
Constructs a xor_combine_engine
, seeding both base generators with values produced by seq
.
template<typename It> xor_combine_engine(It & first, It last);
Constructs a xor_combine_engine
, 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
.
void seed();
Calls seed()
for both base generators.
void seed(result_type v);
seeds
both base generators with v
.
template<typename SeedSeq> void seed(SeedSeq & seq);
seeds
both base generators with values produced by seq
.
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() const;
Returns the first base generator.
const base2_type & base2() const;
Returns the second base generator.
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
.
xor_combine_engine
friend functionstemplate<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & os, const xor_combine_engine & s);
Writes the textual representation of the generator to a std::ostream
.
template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, const xor_combine_engine & s);
Reads the textual representation of the generator from a std::istream
.
bool operator==(const xor_combine_engine & x, const xor_combine_engine & y);
Returns true if the two generators will produce identical sequences.
bool operator!=(const xor_combine_engine & lhs, const xor_combine_engine & rhs);
Returns true if the two generators will produce different sequences.