...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::subtract_with_carry_engine
// In header: <boost/random/subtract_with_carry.hpp> template<typename IntType, std::size_t w, std::size_t s, std::size_t r> class subtract_with_carry_engine { public: // types typedef IntType result_type; // construct/copy/destruct subtract_with_carry_engine(); explicit subtract_with_carry_engine(IntType); template<typename SeedSeq> explicit subtract_with_carry_engine(SeedSeq &); template<typename It> subtract_with_carry_engine(It &, It); // public member functions void seed(); void seed(IntType); template<typename SeedSeq> void seed(SeedSeq &); template<typename It> void seed(It &, It); result_type operator()(); void discard(boost::uintmax_t); template<typename It> void generate(It, It); // public static functions static result_type min(); static result_type max(); // friend functions template<typename CharT, typename Traits> friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &, const subtract_with_carry_engine &); template<typename CharT, typename Traits> friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &, const subtract_with_carry_engine &); friend bool operator==(const subtract_with_carry_engine &, const subtract_with_carry_engine &); friend bool operator!=(const subtract_with_carry_engine &, const subtract_with_carry_engine &); // public data members static const std::size_t word_size; static const std::size_t long_lag; static const std::size_t short_lag; static const uint32_t default_seed; static const bool has_fixed_range; static const result_type modulus; };
Instantiations of subtract_with_carry_engine
model a pseudo-random number generator . The algorithm is described in
"A New Class of Random Number Generators", George Marsaglia and Arif Zaman, Annals of Applied Probability, Volume 1, Number 3 (1991), 462-480.
subtract_with_carry_engine
public
construct/copy/destructsubtract_with_carry_engine();
Constructs a new
and seeds it with the default seed. subtract_with_carry_engine
explicit subtract_with_carry_engine(IntType value);
Constructs a new
and seeds it with subtract_with_carry_engine
value
.
template<typename SeedSeq> explicit subtract_with_carry_engine(SeedSeq & seq);
Constructs a new
and seeds it with values produced by subtract_with_carry_engine
seq.generate()
.
template<typename It> subtract_with_carry_engine(It & first, It last);
Constructs a new
and seeds it with values from a range. first is updated to point one past the last value consumed. If there are not enough elements in the range to fill the entire state of the generator, throws subtract_with_carry_engine
std::invalid_argument
.
subtract_with_carry_engine
public member functionsvoid seed();
Seeds the generator with the default seed.
void seed(IntType value);
template<typename SeedSeq> void seed(SeedSeq & seq);
Seeds the generator with values produced by seq.generate()
.
template<typename It> void seed(It & first, It last);
Seeds the generator with values from a range. Updates first
to point one past the last consumed value. If the range does not contain enough elements to fill the entire state of the generator, throws std::invalid_argument
.
result_type operator()();
Returns the next value of the generator.
void discard(boost::uintmax_t z);
Advances the state of the generator by z
.
template<typename It> void generate(It first, It last);
Fills a range with random values.
subtract_with_carry_engine
friend functionstemplate<typename CharT, typename Traits> friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & os, const subtract_with_carry_engine & f);
Writes a
to a subtract_with_carry_engine
std::ostream
.
template<typename CharT, typename Traits> friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & is, const subtract_with_carry_engine & f);
Reads a
from a subtract_with_carry_engine
std::istream
.
friend bool operator==(const subtract_with_carry_engine & x, const subtract_with_carry_engine & y);
Returns true if the two generators will produce identical sequences of values.
friend bool operator!=(const subtract_with_carry_engine & lhs, const subtract_with_carry_engine & rhs);
Returns true if the two generators will produce different sequences of values.