Partager via


linear_congruential Class

Generates a random sequence by the linear congruential algorithm. Retained for TR1 compatibility. Use linear_congruential_engine Class instead.

template<class UIntType,
   UIntType A, UIntType C, UIntType M>
   class linear_congruential {
public:
   typedef linear_congruential<UIntType, A, C, M> _MyT;
   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(UIntType x0 = default_seed)
   linear_congruential(const linear_congruential& right);
   linear_congruential(linear_congruential& right);
   template<class Gen>
      linear_congruential(Gen& gen);
   void seed(UIntType x0 = default_seed);
   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
   };

Parameters

  • UIntType
    The unsigned integer result type.

  • A
    The A engine parameter.

  • C
    The C engine parameter.

  • M
    The M engine parameter.

Remarks

This template class describes a simple engine that produces values of a user-specified unsigned 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.

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

linear_congruential::linear_congruential

linear_congruential::operator()

linear_congruential::seed

Other Resources

<random> Members