Include the TR1 header <random> to define a host of random number generators.
namespace std {
namespace tr1 {
// UTILITIES
template<class Engine,
class Dist>
class variate_generator;
// SIMPLE ENGINES
template<class UIntType,
UIntType A, UIntType C, UIntType M>
class linear_congruential;
template<class UIntType,
int W, int N, int M, int R,
UIntType A, int U, int S,
UIntType B, int T, UIntType C, int L>
class mersenne_twister;
template<class IntType,
IntType M, int S, int R>
class subtract_with_carry;
template<class RealType,
int W, int S, int R>
class subtract_with_carry_01;
class random_device;
// COMPOUND ENGINES
template<class Engine,
int P, int R>
class discard_block;
template<class Engine1, int S1,
class Engine2, int S2>
class xor_combine;
// ENGINES WITH PREDEFINED PARAMETERS
typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0;
typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand;
typedef mersenne_twister<ui-type, 32, 624,
397, 31,0x9908b0df, 11, 7, 0x9d2c5680, 15, 0xefc60000, 18> mt19937;
typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01;
typedef discard_block<subtract_with_carry<i-type,
1 << 24, 10, 24>, 223, 24> ranlux3;
typedef discard_block<subtract_with_carry<i-type,
1 << 24, 10, 24>, 389, 24> ranlux4;
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>,
223, 24> ranlux3_01;
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>,
389, 24> ranlux4_01;
// DISTRIBUTIONS
template<class IntType = int>
class uniform_int;
template<class RealType = double>
class bernoulli_distribution;
template<class IntType = int, class RealType = double>
class geometric_distribution;
template<class IntType = int, class RealType = double>
class poisson_distribution;
template<class IntType = int, class RealType = double>
class binomial_distribution;
template<class RealType = double>
class uniform_real;
template<class RealType = double>
class exponential_distribution;
template<class RealType = double>
class normal_distribution;
template<class RealType = double>
class gamma_distribution;
} // namespace tr1
} // namespace std
The class describes a distribution that produces values of type bool, returning true with a probability given by the argument to the constructor.
class bernoulli_distribution {
public:
typedef int input_type;
typedef bool result_type;
explicit bernoulli_distribution(double p0 = 0.5);
double p() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
const double stored_p; // exposition only
};
bernoulli_distribution(double p0 = 0.5);
Precondition: 0.0 ≤ p0 && p0 ≤ 1.0
The constructor constructs an object whose stored value stored_p holds the value p0.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed random integer values and returns true with probability given by the stored value stored_p.
double p();
The member function returns the stored value stored_p.
The template class describes a distribution that produces values of a user-specified integral type distributed with a binomial distribution.
template<class IntType = int, class RealType = double>
class binomial_distribution {
public:
typedef /* implementation defined */ input_type;
typedef IntType result_type;
explicit binomial_distribution(result_type t0 = 1,
const RealType& p0 = RealType(0.5));
result_type t() const;
RealType p() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
const result_type stored_t; // exposition only
const RealType stored_p; // exposition only
};
binomial_distribution(result_type t0 = 1, const RealType& p0 = RealType(0.5));
Precondition: 0.0 <= t0 && 0.0 <= p0 && p0 <= 1.0
The constructor constructs an object whose stored value stored_p holds the value p0 and whose stored value stored_t holds the value t0.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed random integral values and returns integral values with each value i occuring with probability pr(i) = comb(stored_t, i) * stored_pi * (1 - stored_p)stored_t-i, where comb(t, i) is the number of possible combinations of t objects taken i at a time.
RealType p();
The member function returns the stored value stored_p.
result_type t();
The member function returns the stored value stored_t.
The template class describes a compound engine that produces values by discarding some of the values returned by its base engine. Each cycle of the compound engine begins by returning R values successively produced by the base engine and ends by discarding P - R such values. The engine's state is the state of stored_eng followed by the number of calls to operator() that have occurred since the beginning of the current cycle.
The value of the template argument R must be less than or equal to the value of the template argument P.
template<class Engine,
int P, int R>
class discard_block {
public:
typedef Engine base_type;
typedef typename base_type::result_type result_type;
static const int block_size = P;
static const int used_block = R;
discard_block();
explicit discard_block(const base_type& eng);
template<class Gen>
discard_block(Gen& gen);
void seed()
{eng.seed(); }
template<class Gen>
void seed(Gen& gen)
{eng.seed(gen); }
const base_type& base() const;
result_type min() const;
result_type max() const;
result_type operator()();
private:
Engine stored_eng; // exposition only
int count; // exposition only
};
discard_block()
: count(0) {}
explicit discard_block(const base_type& eng)
: stored_eng(eng), count(0) {}
template<class Gen>
discard_block(Gen& gen)
: stored_eng(gen), count(0) {}
The first constructor constructs a discard_block object with a default-initialized engine. The second constructor constructs a discard_block object with a copy of an engine object. The third constructor constructs a discard_block object with an engine initialized from a generator.
const base_type& base() const;
The member function returns a reference to the underlying engine object.
result_type operator()()
{
if (R <= count)
{
while (count++ < P)
stored_eng();
count = 0;
}
++count;
return stored_eng();
}
The member function returns the next value in the sequence.
void seed()
{stored_eng.seed(); count = 0; }
template<class Gen>
void seed(Gen& gen)
{stored_eng.seed(gen); count = 0; }
The first seed function calls stored_eng.seed() and sets count to 0. The second seed function calls stored_eng.seed(gen) and sets count to 0.
typedef Engine base_type;
The is a synonym for the type of the underlying engine object.
static const int block_size = P;
The static const variable holds the value of the template argument P, the number of values in each cycle.
static const int block_size = R;
The static const variable holds the value of the template argument R, the number of values to return at the beginning of each cycle.
The template class describes a distribution that produces values of a user-specified floating point type with an exponential distribution.
template<class RealType = double>
class exponential_distribution {
public:
typedef RealType input_type;
typedef RealType result_type;
explicit exponential_distribution(const result_type& lambda0 = result_type(1));
result_type lambda() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
result_type stored_lambda; // exposition only
};
exponential_distribution(const result_type& lambda0 = result_type(1));
Precondition: 0.0 <= lambda0
The constructor constructs an object whose stored value stored_lambda holds the value lambda0.
result_type lambda() const;
The member function returns the stored value stored_lambda.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed random values and returns values with a probability density of pr(x) = stored_lambda * e(-stored_lambda * x).
The template class describes a distribution that produces values of a user-specified floating point type with a gamma distribution.
template<class RealType = double>
class gamma_distribution {
public:
typedef RealType input_type;
typedef RealType result_type;
explicit gamma_distribution(const result_type& alpha0 = result_type(1));
result_type alpha() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
result_type stored_alpha; // exposition only
};
gamma_distribution(const result_type& alpha0 = result_type(1));
Precondition: 0.0 < alpha0
The constructor constructs an object whose stored value stored_alpha holds the value alpha0.
result_type alpha();
The member function returns the stored value stored_alpha.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed random values and returns values with a probability density of pr(x) = 1 / gamma(stored_alpha) * xstored_alpha - 1 * e-x.
The template class describes a distribution that produces values of a user-specified integral type with a geometric distribution.
template<class IntType = int, class RealType = double>
class geometric_distribution {
public:
typedef RealType input_type;
typedef IntType result_type;
explicit geometric_distribution(const RealType& p0 = RealType(0.5));
RealType p() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
RealType stored_p; // exposition only
};
geometric_distribution(const RealType& p0 = RealType(0.5));
Precondition: 0.0 < p0 && p0 < 1.0
The constructor constructs an object whose stored value stored_p holds the value p0.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed integral values and returns integral values with each value i occurring with probability pr(i) = (1 - stored_p) * stored_pi - 1.
RealType p() const;
The member function returns the stored value stored_p.
The template class describes a simple engine that produces values of a user-specified integral type using the recurrence relation x(i) = (A * x(i-1) + C) mod M. The engine's state is the last value returned, or the seed value if no call has been made to operator().
The template argument UIntType must be large enough to hold values up to M - 1. The values of the template arguments A and C must be less than M.
template<class UIntType,
UIntType A, UIntType C, UIntType M>
class linear_congruential {
public:
typedef UIntType result_type;
static const UIntType multiplier = A;
static const UIntType increment = C;
static const UIntType modulus = M;
linear_congruential();
explicit linear_congruential(unsigned long x0);
template<class Gen>
linear_congruential(Gen& gen);
void seed(unsigned long x0 = 1);
template<class Gen>
void seed(Gen& gen);
result_type min() const;
result_type max() const;
result_type operator()();
private:
result_type stored_value; // exposition only
};
linear_congruential();
explicit linear_congruential(unsigned long x0);
template<class Gen>
linear_congruential(Gen& gen);
The first constructor constructs an object and initializes it by calling seed(). The second constructor constructs an object and initializes it by calling seed(x0). The third constructor constructs an object and initializes it by calling seed(gen).
result_type operator()();
The member function generates a new stored_value by applying the recurrence relation to the old value of stored_value.
void seed(unsigned long x0 = 1);
template<class Gen>
void seed(Gen& gen);
The first seed function sets the stored value stored_value to 1 if c mod M == 0 and x0 mod M == 0, otherwise it sets the stored value to x0 mod M. The second seed function calls seed(gen()).
static const UIntType increment = C;
The static const variable holds the value of the template argument C.
static const UIntType modulus = M;
The static const variable holds the value of the template argument M.
static const UIntType multiplier = A;
The static const variable holds the value of template argument A.
The template class describes a simple engine. It holds a large integral value with W * (N - 1) + R bits. It extracts W bits at a time from this large value, and when it has used all the bits it twists the large value by shifting and mixing the bits so that it has a new set of bits to extract from. The engine's state is the last N W-bit values used if operator() has been called at least N times, otherwise the M W-bit values that have been used and the last N - M values of the seed.
The template argument UIntType must be large enough to hold values up to 2W - 1. The values of the other template arguments must satisfy the following requirements:
The generator twists the large value that it holds by executing the following code:
for (int i = 0; i < N; ++i)
{
temp = (x[i] & LMASK) << (W - 1) | (x[i + 1] & HMASK) >> 1;
if (temp & 1)
y[i] = (temp >> 1) ^ A ^ x[(i + R) % N];
else
y[i] = (temp >> 1) ^ x[(i + R) % N];
}
for (int i = 0; i < N; ++i)
x[i] = y[i];
where LMASK is an unsigned W-bit value with its low R bits set to 1 and the rest of its bits set to 0, and HMASK is the complement of LMASK.
The generator holds a current index idx initialized to 0. It extracts bits by executing the following code:
temp = x[idx++];
temp = temp ^ (temp >> U);
temp = temp ^ ((temp << S) & B);
temp = temp ^ ((temp << T) & C);
temp = temp ^ (temp >> L);
When idx reaches N the generator twists the stored value and sets idx back to 0.
template<class UIntType,
int W, int N, int R,
UIntType A, int U, int S,
UIntType B, int T, UIntType C, int L>
class mersenne_twister {
public:
typedef UIntType result_type;
static const int word_size = W;
static const int state_size = N;
static const int shift_size = M;
static const int mask_bits = R;
static const int UIntType parameter_a = A;
static const int output_u = U;
static const int output_s = S;
static const UIntType output_b = B;
static const int output_t = T;
static const UIntType output_c = C;
static const int output_l = L;
mersenne_twister();
explicit mersenne_twister(unsigned long x0);
template<class Gen>
mersenne_twister(Gen& gen);
void seed()
{seed(5489); }
void seed(unsigned long x0);
template<class Gen>
void seed(Gen& gen);
result_type min() const;
result_type max() const;
result_type operator()();
};
mersenne_twister();
explicit mersenne_twister(unsigned long x0);
template<class Gen>
mersenne_twister(Gen& gen);
The first constructor constructs an object and initializes it by calling seed(). The second constructor constructs an object and initializes it by calling seed(x0). The third constructor constructs an object and initializes it by calling seed(gen).
result_type operator()();
The member function extracts the next value in the sequence and returns it.
template<class Gen>
void seed(Gen& gen);
void seed()
{seed(5489); }
void seed(unsigned long x0);
Precondition: 0 < x0
The first seed function generates N values from the values of type unsigned long returned by successive invocations of gen and then twists the resulting large integer value. Each value is gen() % 2W.
The second seed function calls seed(4357).
The third seed function sets the oldest historical value h[0] to x0 mod 2W, then iteratively sets each successive historical value h[i] to (i + 1812433253 * (h[i - 1] >> (W - 2))) mod 2W, for i ranging from 1 to N - 1.
static const int mask_bits = R;
The static const variable holds the value of the template argument R.
static const UIntType output_b = B;
The static const variable holds the value of the template argument B.
static const UIntType output_c = C;
The static const variable holds the value of the template argument C.
static const int output_l = L;
The static const variable holds the value of the template argument L.
static const int output_s = S;
The static const variable holds the value of the template argument S.
static const int output_t = T;
The static const variable holds the value of the template argument T.
static const int output_u = U;
The static const variable holds the value of the template argument U.
static const int UIntType parameter_a = A;
The static const variable holds the value of the template argument A.
static const int shift_size = M;
The static const variable holds the value of the template argument M.
static const int state_size = N;
The static const variable holds the value of the template argument N.
static const int word_size = W;
The static const variable holds the value of the template argument W.
The template class describes a distribution that produces values of a user-specified floating point type with a normal distribution.
template<class RealType = double>
class normal_distribution {
public:
typedef RealType input_type;
typedef RealType result_type;
explicit normal_distribution(const result_type& mean0 = 0,
const result_type& sigma0 = 1);
result_type mean() const;
result_type sigma() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
result_type stored_mean; // exposition only
result_type stored_sigma; // exposition only
};
normal_distribution(const result_type& mean0 = 0,
const result_type& sigma0 = 1);
Precondition: 0.0 <= sigma0
The constructor constructs an object whose stored value stored_mean holds the value mean0 and whose stored value stored_sigma holds the value sigma0.
result_type mean() const;
The member function returns the stored value stored_mean.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed random values and returns returns values with a probability density of pr(x) = 1 / ((2 * pi)1/2 * stored_sigma) * e-(x - stored_mean)2 / (2 * stored_sigma2).
result_type sigma() const;
The member function returns the stored value stored_sigma.
The template class describes a distribution that produces values of a user-specified integral type with a poisson distribution.
template<class IntType = int, class RealType = double>
class poisson_distribution {
public:
typedef RealType input_type;
typedef IntType result_type;
explicit poisson_distribution(const RealType& mean0 = RealType(1));
RealType mean() const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
RealType stored_mean; // exposition only
};
poisson_distribution(const RealType& mean0 = RealType(1));
Precondition: 0.0 < mean0
The constructor constructs an object whose stored value stored_mean holds the value mean0.
RealType mean() const;
The member function returns the stored value stored_mean.
template<class Engine> result_type operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed integral values and returns integral values with each value i occuring with probability pr(i) = e-stored_mean * stored_meani / i!.
The class describes a source of non-deterministic random numbers. In this implementation the values produced are not non-deterministic. They are uniformly distributed in the closed range [0, 65535].
class random_device {
public:
typedef unsigned int result_type;
explicit random_device(const std::string& token = /* implementation defined */);
result_type min() const;
result_type max() const;
double entropy() const;
result_type operator()();
private:
random_device(const random_device&); // exposition only
void operator=(const random_device&); // exposition only
};
random_device(const std::string& str);
The constructor initializes the device (as needed) with str.
double entropy() const;
The member function returns an estimate of the randomness of the source, as measured in bits. (In the extreme, a non-random source has an entropy of zero.)
result_type max() const;
The member function returns the largest value returned by the source.
result_type min() const;
The member function returns the smallest value returned by the source.
result_type operator()();
The member function returns values uniformly distributed in the closed interval [min(), max()].
typedef unsigned int result_type;
The type is a synonym for unsigned int.
The template class describes a simple engine that produces values of a user-specified integral type using the recurrence relation x(i) = (x(i - R) - x(i - S) - cy(i - 1)) mod M, where cy(i) has the value 1 if x(i - S) - x(i - R) - cy(i - 1) < 0, otherwise 0. The engine's state is the last R values returned if operator() has been called at least R times, otherwise the M values that have been returned and the last R - M values of the seed.
The template argument IntType must be large enough to hold values up to M - 1. The values of the template arguments S and R must be greater than 0 and S must be less than R.
template<class IntType,
IntType M, int S, int R>
class subtract_with_carry {
public:
typedef IntType result_type;
static const IntType modulus = M;
static const int short_lag = S;
static const int long_lag = R;
subtract_with_carry();
explicit subtract_with_carry(unsigned long x0);
template<class Gen>
subtract_with_carry(Gen& gen);
void seed(unsigned long x0 = 19780503UL);
template<class Gen>
void seed(Gen& gen);
result_type min() const;
result_type max() const;
result_type operator()();
};
subtract_with_carry();
explicit subtract_with_carry(unsigned long x0);
template<class Gen>
subtract_with_carry(Gen& gen);
The first constructor constructs an object and initializes it by calling seed(). The second constructor constructs an object and initializes it by calling seed(x0). The third constructor constructs an object and initializes it by calling seed(gen).
result_type operator()();
The member function generates the next value in the pseudo-random sequence by applying the recurrence relation to the stored historical values, stores the generated value, and returns it.
static const int long_lag = R;
The static const variable holds the value of the template argument R.
static const IntType modulus = M;
The static const variable holds the value of the template argument M.
static const int short_lag = S;
The static const variable holds the value of the template argument S.
void seed(result_type x0 = 19780503UL);
template<class Gen>
void seed(Gen& gen);
Precondition: 0 < x0
The first seed function generates long_lag historical values from the values of type unsigned long returned by successive invocations of gen. Each historical value is gen() % modulus.
The second seed function effectively executes the following code:
linear_congruential<unsigned long, 40014, 0, 2147483563> gen(x0);
seed(gen);
The template class describes a simple engine that produces values of a user-specified floating point type using the recurrence relation x(i) = (x(i - R) - x(i - S) - cy(i - 1)) mod 1, where cy(i) has the value 2-W if x(i - S) - x(i - R) - cy(i - 1) < 0, otherwise 0. The engine's state is the last R values returned if operator() has been called at least R times, otherwise the M values that have been returned and the last R - M values of the seed.
The template argument RealType must be large enough to hold values with W fraction bits. The values of the template arguments S and R must be greater than 0 and S must be less than R.
template<class RealType,
int W, int S, int R>
class subtract_with_carry_01 {
public:
typedef RealType result_type;
static const int word_size = W;
static const int short_lag = S;
static const int long_lag = R;
subtract_with_carry_01();
explicit subtract_with_carry_01(unsigned long x0);
template<class Gen>
subtract_with_carry_01(Gen& gen);
void seed(unsigned long x0 = 19780503UL);
template<class Gen>
void seed(Gen& gen);
result_type min() const;
result_type max() const;
result_type operator()();
};
subtract_with_carry_01();
explicit subtract_with_carry_01(IntType x0);
template<class In>
subtract_with_carry_01(InIt& first, InIt last);
The first constructor constructs an object and initializes it by calling seed(). The second constructor constructs an object and initializes it by calling seed(x0). The third constructor constructs an object and initializes it by calling seed(first, last).
result_type operator()();
The member function generates the next value in the pseudo-random sequence by applying the recurrence relation to the stored historical values, stores the generated value, and returns it.
template<class Gen>
void seed(Gen& gen);
void seed(result_type x0 = 19780503UL);
Precondition: 0 < x0
The first seed function generates long_lag historical values from the values of type unsigned long returned by successive invocations of gen. Each historical value is generated by concatenating the low 32 bits from each of long_lag * (word_size + 31) / 32 values from the initialization sequence; the resulting value is then divided by 2.0word_size and the integral part discarded. Thus, each historical value is a floating point value greater than or equal to 0.0 and less than 1.0, with word_size significant bits.
The second seed function effectively executes the following code:
linear_congruential<unsigned long, 40014, 0, 2147483563> gen(x0);
seed(gen);
static const int long_lag = R;
The static const variable holds the value of the template argument R.
static const int short_lag = S;
The static const variable holds the value of the template argument S.
static const int word_size = W;
The static const variable holds the value of the template argument W.
The template class describes a distribution that produces values of a user-specified integral type with a uniform distribution.
template<class IntType = int>
class uniform_int {
public:
typedef IntType input_type;
tpyedef IntType result_type;
explicit uniform_int(result_type min0 = 0, result_type max0 = 9);
result_type min() const
{return stored_min; }
result_type max() const;
{return stored_max; }
void reset();
template<class Engine>
result_type operator()(Engine& eng);
template<class Engine>
result_type operator()(Engine& eng, result_type n);
private:
result_type stored_min; // exposition only
result_type stored_max; // exposition only
};
explicit uniform_int(result_type min0 = 0, result_type max0 = 9);
Precondition: min0 < max0
The constructor constructs an object whose stored value stored_min holds the value min0 and whose stored value stored_max holds the value max0.
template<class Engine>
result_type operator()(Engine& eng);
template<class Engine>
result_type operator()(Engine& eng, result_type n);
The first member function uses the engine eng as a source of uniformly distributed integral values and returns integral values with each value i in the closed range [min(), max()] occurring with equal probability and values outside that range occurring with probability 0.
The second member function uses the engine eng as a source of uniformly distributed integral values and returns integral values with each value i in the closed range [min(), n] occurring with equal probability and values outside that range occurring with probability 0.
The template class describes a distribution that produces values of a user-specified floating point type with a uniform distribution.
template<class RealType = double>
class uniform_real {
public:
typedef RealType input_type;
tpyedef RealType result_type;
explicit uniform_real(result_type min0 = result_type(0),
result_type max0 = result_type(1));
result_type min() const
{return stored_min; }
result_type max() const
{return stored_max; }
void reset();
template<class Engine>
result_type operator()(Engine& eng);
private:
result_type stored_min; // exposition only
result_type stored_max; // exposition only
};
explicit uniform_real(result_type min0 = result_type(0),
result_type max0 = result_type(1));
Precondition: min0 < max0
The constructor constructs an object whose stored value stored_min holds the value min0 and whose stored value stored_max holds the value max0.
template<class Engine> bool operator()(Engine& eng);
The member function uses the engine eng as a source of uniformly distributed floating point values and returns floating point values with each value x in the half open range [min(), max()] occurring with equal probability and values outside that range occurring with probability 0.
The template class describes an object that holds an engine and a distribution and produces values by passing the wrapped engine object to the distribution object's operator().
The template argument Engine can be a type Eng, Eng*, or Eng&, where Eng is an engine. The type Eng is the underlying engine type. The corresponding object of type Eng is the the underlying engine object.
The template uses a wrapped engine to match the type of the values produced by the engine object to the type of values required by the distribution object. The wrapped engine's operator() returns values of type Dist::input_type, generated as follows:
template<class Engine, class Dist>
class variate_generator {
public:
typedef Engine engine_type;
typedef engine-type engine_value_type;
typedef Dist distribution_type;
typedef typename Dist::result_type result_type;
variate_generator(engine_type eng0, distribution_type dist0);
result_type operator()();
template<class T>
result_type operator()(T value);
engine_value_type& engine();
const engine_value_type& engine() const;
distribution_type& distribution();
const distribution_type& distribution() const;
result_type min() const
{return dist.min(); }
result_type max() const
{return dist.max(); }
private:
Engine eng; // exposition only
Dist dist; // exposition only
};
variate_generator(engine_type eng0, distribution_type dist0);
The constructor constructs an object whose stored value eng holds eng0 and whose stored value dist holds dist0.
distribution_type& distribution(); const distribution_type& distribution() const;
The member functions return a reference to the stored distribution object dist.
engine_value_type engine(); const engine_value_type& engine() const;
The member functions return a reference to the underlying engine object.
result_type max() const
{return dist.max(); }
The member function returns dist.max().
result_type min() const
{return dist.min(); }
The member function returns dist.min().
result_type operator()();
template<class T>
result_type operator()(T value);
The first member function returns dist(wr_eng), where wr_eng is the object's wrapped engine.
The second member function returns dist(wr_eng, value), where wr_eng is the object's wrapped engine.
typedef Dist distribution_type;
The type is a synonym for the template parameter Dist.
typedef Engine engine_type;
The type is a synonym for the template parameter Engine.
typedef engine-type engine_value_type;
The type is a synonym for the underlying engine type.
typedef typename Dist::result_type result_type;
The type is a synonym for Dist::result_type.
The template class describes a compound engine that produces values by combining values produced by two engines. The engine's state is the state of stored_eng1 followed by the state of stored_eng2.
template<class Engine1, int S1,
class Engine2, int S2>
class xor_combine {
public:
typedef Engine1 base1_type;
typedef Engine2 base2_type;
typedef xxx result_type;
static const int shift1 = S1;
static const int shift2 = S2;
xor_combine()
{}
xor_combine(const base1_type& eng1, const base2_type& eng2)
: stored_eng1(eng1), stored_eng2(eng2) {}
template<class Gen>
xor_combine(Gen& gen)
: stored_eng1(gen), stored_eng2(gen) {}
void seed()
{stored_eng1.seed(); stored_eng2.seed(); }
template<class Gen>
void seed(Gen& gen);
{stored_eng1.seed(gen); stored_eng2.seed(gen); }
const base1_type& base1() const;
const base2_type& base2() const;
result_type min() const;
result_type max() const;
result_type operator()();
private:
base1_type stored_eng1; // exposition only
base2_type stored_eng2; // exposition only
};
xor_combine()
{}
xor_combine(const base1_type& eng1, const base2_type& eng2);
: stored_eng1(eng1), stored_eng2(eng2)
{}
template<class Gen>
xor_combine(Gen& gen)
: stored_eng1(gen), stored_eng2(gen)
{}
The first constructor constructs an object with stored values stored_eng1 and stored_eng2 constructed with their respective default constructors. The second constructor constructs an object whose stored value stored_eng1 holds a copy of eng1 and whose stored value stored_eng2 holds a copy of eng2. The third constructor constructs an object and calls seed(gen).
const base1_type& base1() const;
The member function returns a reference to the stored value stored_eng1.
const base2_type& base2() const;
The member function returns a reference to the stored value stored_eng2.
void seed()
{stored_eng1.seed(); stored_eng2.seed(); }
template<class Gen>
void seed(Gen& gen);
{stord_eng1.seed(gen); stored_eng2.seed(gen); }
The first member function calls stored_eng1.seed() and then calls stored_eng2.seed(). The second member function calls stored_eng1.seed(gen) and then calls stored_eng2.seed(gen).
typedef Engine1 base1_type;
The type names the template parameter Engine1.
typedef Engine1 base2_type;
The type names the template parameter Engine2.
static const int shift1 = S1;
The static const variable holds the value of the template argument S1.
static const int shift2 = S2;
The static const variable holds the value of the template argument S2.
result_type operator()();
The member operator returns (stored_eng1() << shift1) ^ (stored_eng2() << shift2).
typedef linear_congruential< i-type, 16807, 0, 2147483647> minstd_rand0;
The type is a synonym for a specialization of the template linear_congruential.
typedef linear_congruential< i-type, 48271, 0, 2147483647> minstd_rand;
The type is a synonym for a specialization of the template linear_congruential.
typedef mersenne_twister< ui-type, 32, 624, 397, 31,
0x9908b0df, 11, 7, 0x9d2c5680, 15, 0xefc60000, 18> mt19937;
The type is a synonym for a specialization of the template mersenne_twister.
typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
The type is a synonym for a specialization of the template subtract_with_carry_01.
typedef discard_block<subtract_with_carry< i-type, 1 << 24, 10, 24>, 223, 24> ranlux3;
The type is a synonym for a specialization of the template discard_block with a specialization of the template subtract_with_carry.
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 223, 24> ranlux3_01;
The type is a synonym for a specialization of the template discard_block with a specialization of the template subtract_with_carry_01.
typedef discard_block<subtract_with_carry< i-type, 1 << 24, 10, 24>, 389, 24> ranlux4;
The type is a synonym for a specialization of the template discard_block with a specialization of the template subtract_with_carry.
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 389, 24> ranlux4_01;
The type is a synonym for a specialization of the template discard_block with a specialization of the template subtract_with_carry_01.
typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01;
The type is a synonym for a specialization of the template subtract_with_carry_01.
Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.
Notwithstanding the meta-data for this document, copyright information for this document is as follows:
Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.