Mail Archives: djgpp/1996/08/29/06:03:25
Lievre Ludovic wrote:
>
> Mark Gilbert wrote:
> >
> > I can't figure rand() and random() out. They both seem positively un-random
> > giving out the same numbers every time.
>
> When you use rand(), you must initialize a 'seed' with srand.
> Such a code initialize the seed with current time.
> [snip]
The code example given is probably clearer as:
srand( (int) time( NULL ) );
Also, rand() and random() are two different functions, with random()
being generally more random than rand(). However, you must use
srandom() to seed random(), not srand(). For more details, look up
these functions in "info libc".
BTW. there is no 'randomize' function in DJGPP.
John
--
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W+>++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------
- Raw text -