[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to generate a random number?



On Thu, 4 Oct 2001, Thomas Hallaran wrote:

> On Thu, 4 Oct 2001, Liu Tao wrote:
> seed your random number generator like so:
>
> srand(time(NULL));
>
> before calling random.

That is an extraordinarily bad idea.  Any person will be able to guess the
sequence of random numbers simply by guessing the time at which your
program was started.

Use random data to seed the psuedo-random number generator.  Get that data
from /dev/random or /dev/urandom

-jwb



Reply to: