Reputation: 47945
I only found this, which says
Returns a pseudo-random integral number in the range between 0 and RAND_MAX.
But are 0 and RAND_MAX
included? I need values from 0 to 1 (included), so:
rand() / double(RAND_MAX)
will works only if rand()
can also returns 0
and RAND_MAX
.
Upvotes: 0
Views: 73
Reputation: 50053
Returns a pseudo-random integral value between
0
andRAND_MAX
(0
andRAND_MAX
included).
From cppr, emphasize mine.
However, rand
is old and bad, as for example described in this talk by STL. You should use the modern <random>
facilities instead, in your case
std::uniform_real_distribution(0, std::nextafter(1.,2.));
Upvotes: 4