I need some help regarding algorithm for randomness. So Problem is.
There are 50 events going to happen in 8 hours duration. Events can happen at random times. Now it means in each second there is a chance of event happening is 50/(8*60*60)= .001736. How can I do this with random generation algorithm?
I can get random number
int r = rand(); double chance = r/RAND_MAX; if(chance < 0.001736) then event happens else no event
But most of times rand() returns 0 and 0<0.001736 and I am getting more events than required.
Any suggestions?
sorry I forget to mention I calculated chance as double chance = (static_cast )(r) / (static_cast)(RAND_MAX);
It removed double from static_cast
double chance = (double)r/(double)(RAND_MAX);
And you have the 50 seconds.
Note that you can have duplicates.