> can anyone tell me how I can generate a different seed if I
> srand(time(NULL)); more than one time in a second? I wrote an
> to print out a random number..if I run the application fast enough,
> it will print a same number until the next second.. anyone know how I
> fix this?
You should only recall srand once, at the beginning of the program. If
you call it multiple times, and your seeding algorithm is not well
chosen, then you could potentially be getting very nonrandom numbers.
A legitimate case where the problem you're mentioning can come about
when a program (which calls srand once at the start) must be run many
times in short successioon, such that the program might be run more than
once a second (and hence, time(0) would return the same value). The
solution is to either use a higher-resolution time function, like
gettimeofday, to build a seed which has sub-second resolution, or to
include other items in the seed, such as the process ID.
Alcyone Systems | web http://www.alcyone.com/max/
San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
USA | 397 days left | &tSftDotIotE
/ \ The more one is hated, I find, the happier one is.
\__/ Louis-Ferdinand Celine