...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::rand48
// In header: <boost/random/linear_congruential.hpp> class rand48 { public: // types typedef boost::uint32_t result_type; // public static functions static constexpr uint32_t min(); static constexpr uint32_t max(); // public member functions rand48(); explicit rand48(result_type); template<typename SeedSeq> explicit rand48(SeedSeq &); template<typename It> rand48(It &, It); void seed(); void seed(result_type); template<typename It> void seed(It &, It); template<typename SeedSeq> void seed(SeedSeq &); uint32_t operator()(); void discard(boost::uintmax_t); template<typename Iter> void generate(Iter, Iter); // friend functions template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const rand48 &); template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, rand48 &); bool operator==(const rand48 &, const rand48 &); bool operator!=(const rand48 &, const rand48 &); // public data members static const bool has_fixed_range; };
Class rand48
models a pseudo-random number generator . It uses the linear congruential algorithm with the parameters a = 0x5DEECE66D, c = 0xB, m = 2**48. It delivers identical results to the lrand48()
function available on some systems (assuming lcong48 has not been called).
It is only available on systems where uint64_t
is provided as an integral type, so that for example static in-class constants and/or enum definitions with large uint64_t
numbers work.
rand48
public member functionsrand48();
Seeds the generator with the default seed.
explicit rand48(result_type x0);
Constructs a rand48
generator with x(0) := (x0 << 16) | 0x330e.
template<typename SeedSeq> explicit rand48(SeedSeq & seq);
Seeds the generator with values produced by seq.generate()
.
template<typename It> rand48(It & first, It last);
Seeds the generator using values from an iterator range, and updates first to point one past the last value consumed.
void seed();
Seeds the generator with the default seed.
void seed(result_type x0);
Changes the current value x(n) of the generator to (x0 << 16) | 0x330e.
template<typename It> void seed(It & first, It last);
Seeds the generator using values from an iterator range, and updates first to point one past the last value consumed.
template<typename SeedSeq> void seed(SeedSeq & seq);
Seeds the generator with values produced by seq.generate()
.
uint32_t operator()();
Returns the next value of the generator.
void discard(boost::uintmax_t z);
Advances the state of the generator by z
.
template<typename Iter> void generate(Iter first, Iter last);
Fills a range with random values
rand48
friend functionstemplate<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & os, const rand48 & r);
Writes a rand48
to a std::ostream
.
template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, rand48 & r);
Reads a rand48
from a std::istream
.
bool operator==(const rand48 & x, const rand48 & y);
Returns true if the two generators will produce identical sequences of values.
bool operator!=(const rand48 & x, const rand48 & y);
Returns true if the two generators will produce different sequences of values.