Only with closed ranges can you create a uniform_int_distribution
that produces any integer:
uniform_int_distribution<int> dist(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
If this is a half-open range, you will never reach std::numeric_limits<int>::max()
, but only std::numeric_limits<int>::max() - 1
.
This is the same situation for std::uniform_int_distribution
in the C ++ 11 standard library.
Half-open ranges for iterators are common because empty ranges can be easily expressed (by setting begin == end
). This does not make sense for distributions.
Ref: Stefan T. Loveaway mentions this exact reason in his conversation “rand () is considered harmful” in Going Native 2013 (about 14 minutes). This talk is about C ++ 11 <random>
, but, of course, the same reasoning applies to boost as well.
source share