d (Adam Wysocki) writes:
> James Kuyper <> wrote:
>> If srand(time(NULL)) were used in that program, it would generate
>> the same exact sequence of random numbers for all requests received
>> during the same second.
>
> Maybe adding process ID to the seed calculation would do the job.
>
> Instead of:
>
> srand(time(NULL))
>
> Use:
>
> srand(time(NULL) ^ getpid())
>
> Or even:
>
> srand(time(NULL) ^ (getpid() << 16))
If it's worth going to that much trouble, it's probably worth using
a better random number generator than rand() (one provided by the
implementation but not specified by the C standard).
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"