We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

linear_congruential_engine Class

Generates a random sequence by the linear congruential algorithm.

template<class UIntType,
    UIntType A, UIntType C, UIntType M>
    class linear_congruential_engine {
    typedef UIntType result_type;
    static const UIntType multiplier = A;
    static const UIntType increment = C;
    static const UIntType modulus = M;
    static const UIntType default_seed = 1U;
    explicit linear_congruential_engine(result_type x0 = default_seed);
    explicit linear_congruential_engine(seed_seq& seq);
    void seed(result_type x0 = default_seed);
    void seed(seed_seq& seq);
    static const result_type min();
    static const result_type max();
    result_type operator()();
    void discard(unsigned long long count)();
    result_type stored_value;


The unsigned integer result type.


The A engine parameter.


The C engine parameter.


The M engine parameter.

The template class describes a <random> that produces values of a user-specified unsigned integral type using the recurrence relationrecurrence 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.

Header: <random>

Namespace: std