lundi 25 avril 2016

Rand() and Seed()

Im currently using the Rand() function and along with this i Seed() by the current time.

1) When the user installs our module I set the Seed to the current Time. 2) Everytime there is an update I use the Rand() % 10

On my virtual machine it randomizes currently however on another it always returns 0. I cannot see why and was wondering if there is anything for me to look out for as to why this is happen?

Here is some code

So when you install our module (software) we have a function called initialize and inside there we call the srand function, THIS INITIALIZE FUNCTION IS ONLY CALLED ONCE.

srand(static_cast<unsigned int>(time(NULL)));

When there is an update we perform the randomizing by doing the following.

boost::posix_time::time_duration randomMinutes = boost::posix_time::minutes(rand() % 10);

Thanks,




Aucun commentaire:

Enregistrer un commentaire