Re: Random Number Generation
Hi,
rand() % 6
will generate random number 0..5
Note that rand() is not useful for statistical purposes - and the modulo makes it worse (a bit). But if it just should 'look random', or it is for a game or something, it#s fine.
Peter
Re: Random Number Generation
// No such luck.
// Try this trick.
LONG SomeClass::Random(LONG nMin, LONG nMax)
{
// use modulus to return range then add nMin to move to offset.
return rand() % (nMax-nMin+1) + nMin;
}
Re: Random Number Generation
srand((unsigned)time(NULL));
// Generate random number within the range : 0 to iMax
int iMax = 250;
int newRan = rand() % (unsigned)(iMax+1);