rand()/RAND_MAX.
Not exactly working. Integer arithmetic here. :) -- modified at 14:13 Monday 10th October, 2005
S
seppo lahti
@seppo lahti
Posts
-
how to get a random number between 0 and 1 -
how to get a random number between 0 and 1std::rand() / (double)RAND_MAX gives a uniformly distributed random number in range [0...1]. Following function gives a uniformly distributed value in half-open range [lo…hi). template inline T random(T lo, T hi) { return (T)(lo + (__int64)std::rand() * (hi - lo) / (RAND_MAX + 1)); } Seppo -- modified at 9:09 Monday 10th October, 2005