Possible Duplicate:
Generating random numbers effectively
I need to generate random numbers
in my C++
application. I know from reading these two articles --
http://www.cprogramming.com/tutorial/random.html
-- that random numbers can be generated using srand()
and rand()
but in both cases the current time according to the system clock
is used as a seed
. But I read in the first article that rand()
will create the same random numbers if the seed is the same. So if two different users ran my application at the same time then they would have the same random numbers. Which would be pointless because I need the random numbers to be unique for the most part. (I know they cant be truly 100% unique if they are generated randomly)
So my question is can I create a random seed not based on system time and if so how, why does rand()
produce the same numbers with the same seed and is there a way to make rand()
produce different numbers with the same seed, or is there any other way to generate random numbers?