Question about linear_congruential_engine::min()

Viewed 106

The standard C++ library provides class template linear_congruential_engine. Given the template parameters a, c, m, this engine produces unsigned integer numbers by using the following formula:

x_{i+1} = (a * x_{i} + c) % m

For instance, the execution of

#define _a 2
#define _c 0
#define _m 16

typedef std::linear_congruential_engine<unsigned int, _a, _c, _m> T;
T lce; // Default seed equals 1

for (int i=0; i<10; i++)
   std::cout << lce() << " ";
std::cout << std::endl;

unsurprisingly produces the following output:

2 4 8 0 0 0 0 0 0 0

So, the minimum of this sequence equals 0. However, according to ISO-IEC-14882-2017-5 [rand.eng.lcong], lce.min() shall return 1 if c == 0:

static constexpr result_type min() { return c == 0u ? 1u: 0u; }

Could anybody explain to me why lce.min() is greater than the actual minimal value in this case?

0 Answers
Related