Re: random()
Shao Zhang <shao@cia.com.au> wrote:
> Reply-To:
> Hi,
> I have some trouble to generate a random number. Please help.
> I use the current time for the seed:
Why not:
unsigned int gen_magic()
{
srandom(time(0));
return random();
}
?
> unsigned int gen_magic()
> {
> time_t cur;
> char *cur_time;
>
> time(&cur);
> cur_time = ctime(&cur);
>
> srandom((unsigned int) (atol(cur_time)));
>
> return random();
> }
--
- mike http://ctelcom.net/mike/ -- Debian GNU/Linux http://www.debian.org/ -
"To God only wise, be glory through Jesus Christ for ever. Amen." Romans 16:27
Reply to:
- References:
- random()
- From: Shao Zhang <shao@cia.com.au>