Mail Archives: djgpp/1996/06/04/09:01:56
From: halibut AT kuhub DOT cc DOT ukans DOT edu
Date: 3 Jun 96 06:17:09 CDT
You'll have to forgive me if this question is too easy I'm a C
beginner, but any it has to do with srand.
To seed the random number table I always used srand(time(NULL)).
I have both time.h and stdlib.h included. Djgpp refuses to accept
this line of code. Is there any other way to do this?
I download some programs hoping to find this answer but most
of them had a randomize() function which Djgpp doesnt seem to touch
and one of them even querried the user for the seed!
Maybe this could be put in the faq?
The function time() returns a (time_t). Simply cast it to an (unsigned int)
which is what srand() expects, hence:
srand((unsigned int)time( (time_t *)NULL ));
--
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com
A proverb is no proverb to you 'till life has illustrated it. -- John Keats
BTW: Please no one get on my case about the cast of the NULL. We've been over
that already.
- Raw text -