Answer the question
In order to leave comments, you need to log in
How to make real numbers using rand()?
How to make real numbers using rand()?
Answer the question
In order to leave comments, you need to log in
Divide by a constant
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
There are many ways to do this, the answer depends on what distribution you want and how many significant bits you need.
In the simplest case, if the distribution is uniform (like rand), and the number of bits is not important, then divide by RAND_MAX and bring the result to the desired range.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question