public member function
explicit linear_congruential_engine ( result_type val = default_seed );
template <class Sseq>
explicit linear_congruential_engine ( Sseq& q );
Construct linear congruential engine
Constructs a linear_congruential_engine object, and initializes its internal state value:
- For version (1), the state value is set to val%modulus (unless both val and increment are multiples of modulus, in which case the state value is set to default_seed).
- For version (2), the function calls q.generate on a temporary array to construct a single value of type result_type, which is used to initialize the engine as if version (1) was called with it.
- A seeding value.
result_type is a member type, defined as an alias of the first class template parameter (UIntType).
default_seed is a member constant, defined as 1u.
- A seed sequence object, such as an object of type seed_seq.
Sseq shall be a seed sequence class, with a generate member function.
// linear_congruential_engine constructor
int main ()
// obtain a seed from the system clock:
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
// obtain a seed from the user:
std::cout << "Please, enter a seed: ";
std::seed_seq seed2 (str.begin(),str.end());
std::minstd_rand0 g1 (seed1); // minstd_rand0 is a standard linear_congruential_engine
std::cout << "A time seed produced: " << g1() << std::endl;
std::minstd_rand0 g2 (seed2);
std::cout << "Your seed produced: " << g2() << std::endl;
Please, enter a seed: Park-Miller
A time seed produced: 1227992885
Your seed produced: 1296106123