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

Re: How to generate a random number?



On Thu, Oct 04, 2001 at 09:21:34PM +0800, Liu Tao wrote:
> I use random() in my program to generate a random number,
> but every time when I restart my program I get the same number.
> How can I get different random numbers each time?

Look at srandom() to seed the generator. You can seed it with the
current time, or with a couple of bytes from /dev/urandom, and so
forth.

-- 
John Patton                      patton66@home.com

"They couldn't hit an elephant at this dist..."
- General John B. Sedgwick Last words, 1864



Reply to: