How to generate random numbers between two doubles in c++ , these numbers should look like xxxxx,yyyyy .
Question&Answers:osHow to generate random numbers between two doubles in c++ , these numbers should look like xxxxx,yyyyy .
Question&Answers:osHere's how
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
Remember to call srand() with a proper seed each time your program starts.
[Edit] This answer is obsolete since C++ got it's native non-C based random library (see Alessandro Jacopsons answer) But, this still applies to C