www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/07/12:47:45

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to limit a random() with DJGPP ?
Date: Sat, 07 Feb 1998 12:43:07 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 20
Message-ID: <34DC9D2B.3396@cs.com>
References: <6bdeu3$evr$1 AT news4 DOT isdnet DOT net> <19980206025400 DOT VAA01280 AT ladder03 DOT news DOT aol DOT com> <6bgu3j$ra9 AT freenet-news DOT carleton DOT ca>
NNTP-Posting-Host: ppp220.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Paul Derbyshire wrote:
> 
> Your best bet, actually, would be to use (random()>>4)%10, for instance,
> to discard the low four bits, which are usually less random than the rest
> of the pseudo-random number and which make this known when %ing by small
> quantities.

While DJGPP's rand() library function suffers from this problem,
random() uses a better algorithm that does not.  This is an example of
why it's not a good idea to depend on built-in random number generators
if you are writing code that depends on having as much "randomness" as
possible.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "If 'everybody knows' such-and-such, |
|       aka Fighteer I       | then it ain't so, by at least ten    |
|   mailto:fighteer AT cs DOT com   | thousand to one."                    |
| http://www.cs.com/fighteer |                 - Lazarus Long       |
---------------------------------------------------------------------

- Raw text -


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