Mail Archives: djgpp/1998/03/27/19:15:39
KillFerFun wrote:
>
> How do you seed the random number generator (like with Borland's randomize()
> function)?
>
> Is there any list of legal DJGPP commands and usages? I use a Borland C++ help
> file, but many of the functions are not portable. Could someone point me to a
> URL? Much appreciated...
The libc documentation comes with DJGPP and can be read with the GNU
Info reader (v2gnu/txi390b.zip). Just install Info and type "info libc"
to read it.
DJGPP has the ANSI-standard functions rand() and srand() (randomize is a
Borland-ism that I particularly detest). You call srand() to seed the
RNG and rand() to obtain random values from 0 to RAND_MAX (defined in
<limits.h>. A good seed value is the system clock - include <time.h>
and call srand((int)time(NULL)). You can clip the value from rand() to
the desired range with the mod (%) operator.
DJGPP also has a more complex, and more robust RNG called random(),
which you can seed with the srandom() function. It's nonstandard but
provides substantially better performance than rand(), at the cost of
some speed.
P.S.: The documentation for srand() was inadvertently omitted from the
v2.01 libc.inf. It will be in the next version.
--
---------------------------------------------------------------------
| John M. Aldrich | "A 'critic' is a man who creates |
| aka Fighteer I | nothing and thereby feels qualified |
| mailto:fighteer AT cs DOT com | to judge the work of creative men." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -