public member function
<random>

std::linear_congruential_engine::operator()

result_type operator()();
Generate random number
Returns a new random number.

The function advances the internal state by one, which modifies the state value with the following transition algorithm:



Where x is the current state value, a and c are their respective class template parameters, and m is its respective class template parameter if this is greater than 0, or numeric_limits<UIntType>::max() plus 1, otherwise.

Parameters

None

Return value

A new random number.
result_type is a member type, defined as an alias of the first class template parameter (UIntType).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// linear_congruential_engine::operator()
#include <iostream>
#include <chrono>
#include <random>

int main ()
{
  // obtain a seed from the system clock:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  std::minstd_rand0 generator (seed);  // minstd_rand0 is a standard linear_congruential_engine
  std::cout << "Random value: " << generator() << std::endl;

  return 0;
}

Possible output:
Random value: 642968455


Complexity

Constant.

See also