This documentation is archived and is not being maintained.

linear_congruential Class

Generates a random sequence by the linear congruential algorithm.

template<class UIntType,
   UIntType A, UIntType C, UIntType M>
   class linear_congruential {
   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()();
   result_type stored_value;    // exposition only


The unsigned integer result type.


The A engine parameter.


The C engine parameter.


The M engine parameter.

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

Header: <random>

Namespace: std::tr1