cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/27/19:15:39

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Simple random number generation question
Date: Fri, 27 Mar 1998 19:02:54 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 35
Message-ID: <351C3E2E.5F5C@cs.com>
References: <1998032722364801 DOT RAA11959 AT ladder03 DOT news DOT aol DOT com>
NNTP-Posting-Host: ppp246.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019