subtract_with_carry_engine Class

Generates a random sequence by the subtract with carry algorithm.

template<class UIntType,
    int W, int S, int R>
    class subtract_with_carry_engine {
public:
    typedef UIntType result_type;
    static const int word_size = W;
    static const int short_lag = S;
    static const int long_lag = R;
    static const UIntType default_seed = 19780503U;
    explicit subtract_with_carry_engine(UIntType x0 = default_seed);
    explicit subtract_with_carry_engine(seed_seq& seq);
    void seed(UIntType 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)();
    };

Parameters

  • UIntType
    The integer result type.

  • W
    The M engine parameter.

  • S
    The S engine parameter.

  • R
    The R engine parameter.

Remarks

The template class decribes a simple engine that produces values of a user-specified unsigned 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, and M has the value 2W. (Note that the template parameter W here replaces the template parameter M for subtract_with_carry.) The engine's state is a carry indicator plus R values. These values consist of the last R values returned if operator() has been called at least R times, otherwise the N values that have been returned and the last R - N values of the seed.

The template argument UIntType 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.

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

subtract_with_carry_engine::discard

subtract_with_carry_engine::operator()

subtract_with_carry_engine::seed

subtract_with_carry_engine::subtract_with_carry_engine