Mail Archives: djgpp/1997/02/23/18:19:09
steve wilcox wrote:
>
> hi im having probs creating random numbers in djgpp i have made a
> define like so :
> #define randomize() srand((unsigned)time(NULL))
>
> and im my code i call randomize() first but i still dont get random
> numbers using x = random()%100;
>
> anyone know whats wrong ?
The DJGPP C library has two random numbers generators :
rand() and random(). They are two different functions, not aliases for
the same (random() being, I'm told, more random than rand(), but more
expensive to compute).
These two generators have different seeding functions : srand() for
rand(), and srandom() for random().
If your code is just like what you wrote above, you are calling srand()
to initialise rand() (this is ok) but then you call random(), which is
not seeded.
Either use srandom() in the randomize() function, or call rand() after
(*not both* ;-)).
Regards
Francois
- Raw text -