<random>

Description
Synopsis
Classes
Types

Description

Include the TR1 header <random> to define a host of random number generators.

Note:
To enable this header file, you must define the macro __IBMCPP_TR1__ .

Synopsis

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

Classes

bernoulli_distribution
binomial_distribution
discard_block
exponential_distribution
gamma_distribution
geometric_distribution
linear_congruential
mersenne_twister
normal_distribution
poisson_distribution
random_device
subtract_with_carry
subtract_with_carry_01
uniform_int
uniform_real
variate_generator
xor_combine

bernoulli_distribution

Description
Synopsis
Constructor
bernoulli_distribution::bernoulli_distribution
Member functions
bernoulli_distribution::operator()
bernoulli_distribution::p
Description

The class describes a distribution that produces values of type bool, returning true with a probability given by the argument to the constructor.

Synopsis
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
    };
Constructor
bernoulli_distribution::bernoulli_distribution

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.

Member functions
bernoulli_distribution::operator()

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.

bernoulli_distribution::p

double p();

The member function returns the stored value stored_p.

binomial_distribution

Description
Synopsis
Constructor
binomial_distribution::binomial_distribution
Member functions
binomial_distribution::operator()
binomial_distribution::p
binomial_distribution::t
Description

The template class describes a distribution that produces values of a user-specified integral type distributed with a binomial distribution.

Synopsis
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
    };
Constructor
binomial_distribution::binomial_distribution

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.

Member functions
binomial_distribution::operator()

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.

binomial_distribution::p

RealType p();

The member function returns the stored value stored_p.

binomial_distribution::t

result_type t();

The member function returns the stored value stored_t.

discard_block

Description
Synopsis
Constructor
discard_block::discard_block
Member functions
discard_block::base
discard_block::operator()
discard_block::seed
Types
discard_block::base_type
Constants
discard_block::block_size
discard_block::used_block
Description

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.

Synopsis
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
    };
Constructor
discard_block::discard_block

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.

Member functions
discard_block::base

const base_type& base() const;

The member function returns a reference to the underlying engine object.

discard_block::operator()

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.

discard_block::seed

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.

Types
discard_block::base_type

typedef Engine base_type;

The is a synonym for the type of the underlying engine object.

Constants
discard_block::block_size

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.

discard_block::used_block

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.

exponential_distribution

Description
Synopsis
Constructor
exponential_distribution::exponential_distribution
Member functions
exponential_distribution::lambda
exponential_distribution::operator()
Description

The template class describes a distribution that produces values of a user-specified floating point type with an exponential distribution.

Synopsis
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
    };
Constructor
exponential_distribution::exponential_distribution

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.

Member functions
exponential_distribution::lambda

result_type lambda() const;

The member function returns the stored value stored_lambda.

exponential_distribution::operator()

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).

gamma_distribution

Description
Synopsis
Constructor
gamma_distribution::gamma_distribution
Member functions
gamma_distribution::alpha
gamma_distribution::operator()
Description

The template class describes a distribution that produces values of a user-specified floating point type with a gamma distribution.

Synopsis
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
    };
Constructor
gamma_distribution::gamma_distribution

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.

Member functions
gamma_distribution::alpha

result_type alpha();

The member function returns the stored value stored_alpha.

gamma_distribution::operator()

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.

geometric_distribution

Description
Synopsis
Constructor
geometric_distribution::geometric_distribution
Member functions
geometric_distribution::operator()
geometric_distribution::p
Description

The template class describes a distribution that produces values of a user-specified integral type with a geometric distribution.

Synopsis
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
    };
Constructor
geometric_distribution::geometric_distribution

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.

Member functions
geometric_distribution::operator()

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.

geometric_distribution::p

RealType p() const;

The member function returns the stored value stored_p.

linear_congruential

Description
Synopsis
Constructor
linear_congruential::linear_congruential
Member functions
linear_congruential::operator()
linear_congruential::seed
Constants
linear_congruential::increment
linear_congruential::modulus
linear_congruential::multiplier
Description

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.

Synopsis
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
    };
Constructor
linear_congruential::linear_congruential

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).

Member functions
linear_congruential::operator()

result_type operator()();

The member function generates a new stored_value by applying the recurrence relation to the old value of stored_value.

linear_congruential::seed

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()).

Constants
linear_congruential::increment

static const UIntType increment = C;

The static const variable holds the value of the template argument C.

linear_congruential::modulus

static const UIntType modulus = M;

The static const variable holds the value of the template argument M.

linear_congruential::multiplier

static const UIntType multiplier = A;

The static const variable holds the value of template argument A.

mersenne_twister

Description
Synopsis
Constructor
mersenne_twister::mersenne_twister
Member functions
mersenne_twister::operator()
mersenne_twister::seed
Constants
mersenne_twister::mask_bits
mersenne_twister::output_b
mersenne_twister::output_c
mersenne_twister::output_l
mersenne_twister::output_s
mersenne_twister::output_t
mersenne_twister::output_u
mersenne_twister::parameter_a
mersenne_twister::shift_size
mersenne_twister::state_size
mersenne_twister::word_size
Description

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.

Synopsis
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()();
    };
Constructor
mersenne_twister::mersenne_twister

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).

Member functions
mersenne_twister::operator()

result_type operator()();

The member function extracts the next value in the sequence and returns it.

mersenne_twister::seed

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.

Constants
mersenne_twister::mask_bits

static const int mask_bits = R;

The static const variable holds the value of the template argument R.

mersenne_twister::output_b

static const UIntType output_b = B;

The static const variable holds the value of the template argument B.

mersenne_twister::output_c

static const UIntType output_c = C;

The static const variable holds the value of the template argument C.

mersenne_twister::output_l

static const int output_l = L;

The static const variable holds the value of the template argument L.

mersenne_twister::output_s

static const int output_s = S;

The static const variable holds the value of the template argument S.

mersenne_twister::output_t

static const int output_t = T;

The static const variable holds the value of the template argument T.

mersenne_twister::output_u

static const int output_u = U;

The static const variable holds the value of the template argument U.

mersenne_twister::parameter_a

static const int UIntType parameter_a = A;

The static const variable holds the value of the template argument A.

mersenne_twister::shift_size

static const int shift_size = M;

The static const variable holds the value of the template argument M.

mersenne_twister::state_size

static const int state_size = N;

The static const variable holds the value of the template argument N.

mersenne_twister::word_size

static const int word_size = W;

The static const variable holds the value of the template argument W.

normal_distribution

Description
Synopsis
Constructor
normal_distribution::normal_distribution
Member functions
normal_distribution::mean
normal_distribution::operator()
normal_distribution::sigma
Description

The template class describes a distribution that produces values of a user-specified floating point type with a normal distribution.

Synopsis
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
    };
Constructor
normal_distribution::normal_distribution

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.

Member functions
normal_distribution::mean

result_type mean() const;

The member function returns the stored value stored_mean.

normal_distribution::operator()

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).

normal_distribution::sigma

result_type sigma() const;

The member function returns the stored value stored_sigma.

poisson_distribution

Description
Synopsis
Constructor
poisson_distribution::poisson_distribution
Member functions
poisson_distribution::mean
poisson_distribution::operator()
Description

The template class describes a distribution that produces values of a user-specified integral type with a poisson distribution.

Synopsis
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
    };
Constructor
poisson_distribution::poisson_distribution

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.

Member functions
poisson_distribution::mean

RealType mean() const;

The member function returns the stored value stored_mean.

poisson_distribution::operator()

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!.

random_device

Description
Synopsis
Constructor
random_device::random_device
Member functions
random_device::entropy
random_device::max
random_device::min
random_device::operator()
Types
random_device::result_type
Description

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].

Synopsis
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
    };
Constructor
random_device::random_device

random_device(const std::string& str);

The constructor initializes the device (as needed) with str.

Member functions
random_device::entropy

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.)

random_device::max

result_type max() const;

The member function returns the largest value returned by the source.

random_device::min

result_type min() const;

The member function returns the smallest value returned by the source.

random_device::operator()

result_type operator()();

The member function returns values uniformly distributed in the closed interval [min(), max()].

Types
random_device::result_type

typedef unsigned int result_type;

The type is a synonym for unsigned int.

subtract_with_carry

Description
Synopsis
Constructor
subtract_with_carry::subtract_with_carry
Member functions
subtract_with_carry::operator()
Constants
subtract_with_carry::long_lag
subtract_with_carry::modulus
subtract_with_carry::short_lag
subtract_with_carry::seed
Description

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.

Synopsis
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()();
    };
Constructor
subtract_with_carry::subtract_with_carry

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).

Member functions
subtract_with_carry::operator()

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.

Constants
subtract_with_carry::long_lag

static const int long_lag = R;

The static const variable holds the value of the template argument R.

subtract_with_carry::modulus

static const IntType modulus = M;

The static const variable holds the value of the template argument M.

subtract_with_carry::short_lag

static const int short_lag = S;

The static const variable holds the value of the template argument S.

subtract_with_carry::seed

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);

subtract_with_carry_01

Description
Synopsis
Constructor
subtract_with_carry_01::subtract_with_carry_01
Member functions
subtract_with_carry_01::operator()
subtract_with_carry_01::seed
Constants
subtract_with_carry_01::long_lag
subtract_with_carry_01::short_lag
subtract_with_carry_01::word_size
Description

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.

Synopsis
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()();
    };
Constructor
subtract_with_carry_01::subtract_with_carry_01

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).

Member functions
subtract_with_carry_01::operator()

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.

subtract_with_carry_01::seed

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);
Constants
subtract_with_carry_01::long_lag

static const int long_lag = R;

The static const variable holds the value of the template argument R.

subtract_with_carry_01::short_lag

static const int short_lag = S;

The static const variable holds the value of the template argument S.

subtract_with_carry_01::word_size

static const int word_size = W;

The static const variable holds the value of the template argument W.

uniform_int

Description
Synopsis
Constructor
uniform_int::uniform_int
Member functions
uniform_int::operator()
Description

The template class describes a distribution that produces values of a user-specified integral type with a uniform distribution.

Synopsis
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
    };
Constructor
uniform_int::uniform_int

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.

Member functions
uniform_int::operator()

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.

uniform_real

Description
Synopsis
Constructor
uniform_real::uniform_real
Member functions
uniform_real::operator()
Description

The template class describes a distribution that produces values of a user-specified floating point type with a uniform distribution.

Synopsis
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
    };
Constructor
uniform_real::uniform_real

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.

Member functions
uniform_real::operator()

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.

variate_generator

Description
Synopsis
Constructor
variate_generator::variate_generator
Member functions
variate_generator::distribution
variate_generator::engine
variate_generator::max
variate_generator::min
variate_generator::operator()
Types
variate_generator::distribution_type
variate_generator::engine_type
variate_generator::engine_value_type
variate_generator::result_type
Description

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:

Synopsis
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
    };
Constructor
variate_generator::variate_generator

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.

Member functions
variate_generator::distribution

distribution_type& distribution();
const distribution_type& distribution() const;

The member functions return a reference to the stored distribution object dist.

variate_generator::engine

engine_value_type engine();
const engine_value_type& engine() const;

The member functions return a reference to the underlying engine object.

variate_generator::max

result_type max() const
    {return dist.max(); }

The member function returns dist.max().

variate_generator::min

result_type min() const
    {return dist.min(); }

The member function returns dist.min().

variate_generator::operator()

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.

Types
variate_generator::distribution_type

typedef Dist distribution_type;

The type is a synonym for the template parameter Dist.

variate_generator::engine_type

typedef Engine engine_type;

The type is a synonym for the template parameter Engine.

variate_generator::engine_value_type

typedef engine-type engine_value_type;

The type is a synonym for the underlying engine type.

variate_generator::result_type

typedef typename Dist::result_type result_type;

The type is a synonym for Dist::result_type.

xor_combine

Description
Synopsis
Constructor
xor_combine::xor_combine
Member functions
xor_combine::base1
xor_combine::base2
xor_combine::seed
Types
xor_combine::base1_type
xor_combine::base2_type
Constants
xor_combine::shift1
xor_combine::shift2
Operators
operator()
Description

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.

Synopsis
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
    };
Constructor
xor_combine::xor_combine

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).

Member functions
xor_combine::base1

const base1_type& base1() const;

The member function returns a reference to the stored value stored_eng1.

xor_combine::base2

const base2_type& base2() const;

The member function returns a reference to the stored value stored_eng2.

xor_combine::seed

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).

Types
xor_combine::base1_type

typedef Engine1 base1_type;

The type names the template parameter Engine1.

xor_combine::base2_type

typedef Engine1 base2_type;

The type names the template parameter Engine2.

Constants
xor_combine::shift1

static const int shift1 = S1;

The static const variable holds the value of the template argument S1.

xor_combine::shift2

static const int shift2 = S2;

The static const variable holds the value of the template argument S2.

Operators
operator()

result_type operator()();

The member operator returns (stored_eng1() << shift1) ^ (stored_eng2() << shift2).

Types

minstd_rand0
minstd_rand
mt19937
ranlux_base_01
ranlux3
ranlux3_01
ranlux4
ranlux4_01
ranlux64_base_01

minstd_rand0

typedef linear_congruential< i-type, 16807, 0, 2147483647> minstd_rand0;

The type is a synonym for a specialization of the template linear_congruential.

minstd_rand

typedef linear_congruential< i-type, 48271, 0, 2147483647> minstd_rand;

The type is a synonym for a specialization of the template linear_congruential.

mt19937

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.

ranlux_base_01

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.

ranlux3

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.

ranlux3_01

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.

ranlux4

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.

ranlux4_01

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.

ranlux64_base_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.

Copyright note

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.