std::mersenne_twister_engine and range of values generated

21 hours ago 1
ARTICLE AD BOX

is it correct to assume that this range is taken from the range prescribed for std::uniform_int_distribution?

No, w is simply the second template parameter:

template< class UIntType, std::size_t w, std::size_t n, std::size_t m, std::size_t r, // ^^^^^^^^^^^^^ UIntType a, std::size_t u, UIntType d, std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f > class mersenne_twister_engine;

As seen in the two predefined specializations:

In std::mt19937, the second parameter is 32, resulting in the range [0, 232).

std::mersenne_twister_engine<std::uint_fast32_t, 32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253>

In std::mt19937_64, the second parameter is 64, resulting in the range [0, 264).

std::mersenne_twister_engine<std::uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9, 29, 0x5555555555555555, 17, 0x71d67fffeda60000, 37, 0xfff7eee000000000, 43, 6364136223846793005>

When it comes to the distributions, like std::uniform_int_distribution, they acquire entropy by calling the supplied generator. The width of the generator may very well be less than the required to produce all numbers in the range of the distribution. Distributions have state can call a generator more than once to produce a number in the distribution's range.

Read Entire Article