Hi All,
I've seen that I can use rand() or srand() to generate randoms numbers but I don't understand how I can exactly set a limit to rand value.
For exemple, I want to get a random number between 0 - 640 ...
I can I proceed ?
I tried to create this function :
int Rnd( int RangeValue ){
float NewRandom = (float)( rand() & 0x7FFFFFFF );
float NewFACTOR = (float)( RangeValue / 2147483647 ) ; // 2147483647 = 0x7FFFFFFF
NewRANDOM = NewRANDOM * NewFACTOR;
return (int)NewRANDOM;
}
Thank you.
Edited by freddix on 2009/3/9 22:16:16