www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/28/20:16:51

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random implementation
Date: Wed, 28 Jan 1998 20:01:52 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 37
Message-ID: <34CFD500.219A@cs.com>
References: <34CEAEE2 DOT 2DCF AT cs DOT com> <19980129003900 DOT TAA29842 AT ladder03 DOT news DOT aol DOT com>
NNTP-Posting-Host: ppp213.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Myknees wrote:
> 
> I have tried to do random numbers before without success.  Now I think I know
> why.  In the info documentation's alphabetical list, there is no mention of
> srand().  And there's no cross reference to srand() from rand().
> 
[code snipped]
> 
> But if this is right, how would a beginner find it out?  (Besides, of course,
> reading about it from an outside source.)

srand() was omitted from the documentation, but srandom() was not.  I
noticed this, along with several other people, and there is a posted bug
report correcting the docs.  In any case, the seed functions probably
ought to be mentioned in the docs for rand() and random(), and I think
this will be done in v2.02.

Your program is very strange.  The use of bioskey() for example, is
totally hardware-specific and makes no sense, when all you really need
is getkey() or even getch().  Furthermore, calling srand() once for each
call to rand() doesn't guarantee randomness; in fact it makes the
results less random.  You only need to seed a RNG once per program.

As a final note, DJGPP's documentation isn't designed to teach standard
C; it's designed to explain the functionality of the library code.  I
can see how it could be made clearer in some cases, but it would be
wasteful to include a complete tutorial on random numbers in the library
documentation when there are entire books devoted specifically to the
subject.  :-)

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Autocracy is based on the assumption|
|       aka Fighteer I       | that one man is wiser than a million |
|   mailto:fighteer AT cs DOT com   | men.  Let's play that over again,    |
| http://www.cs.com/fighteer | too.  Who decides?"   - Lazarus Long |
---------------------------------------------------------------------

- Raw text -


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