random()
Reply-To:
Hi,
I have some trouble to generate a random number. Please help.
I use the current time for the seed:
unsigned int gen_magic()
{
time_t cur;
char *cur_time;
time(&cur);
cur_time = ctime(&cur);
srandom((unsigned int) (atol(cur_time)));
return random();
}
But everytime this function gets called, it is always return the same number:
+------------+
| number |
+------------+
| 1362961854 |
| 1362961854 |
| 1362961854 |
| 1362961854 |
| 1362961854 |
| 1362961854 |
| 1362961854 |
+------------+
There must be a better way to do this. Please tell me...
Thanks.
Shao.
--
____________________________________________________________________________
Shao Zhang - Running Debian 2.1 ___ _ _____
Department of Communications / __| |_ __ _ ___ |_ / |_ __ _ _ _ __ _
University of New South Wales \__ \ ' \/ _` / _ \ / /| ' \/ _` | ' \/ _` |
Sydney, Australia |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au |___/
_____________________________________________________________________________
Reply to: