delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/05/04:17:17

Date: Thu, 5 Jun 1997 11:14:13 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Alan Wilson <awilson AT wilshire DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Random numbers/George
In-Reply-To: <2.2.32.19970604162434.0069d50c@gate>
Message-ID: <Pine.SUN.3.91.970605111344.5841K-100000@is>
MIME-Version: 1.0

On Wed, 4 Jun 1997, Alan Wilson wrote:

> It sounds like to me that DJGPP doesnt have a truly random generator then.
> "Informal" random numbers are nice but it would be better if we could
> generate truly random numbers where the frequency of all numbers were the
> same...

You got it wrong, sorry.  No computer algorithm can ever generate
``true'' random numbers.  True random numbers can be only generated by
physical processes; you will have to build a hardware device and
connect it to your machine to get truely random series.

Computer programs can only generate so-called ``pseudo-random''
series.  The differece is that the numbers they generate repeat
themselves after a certain period.  A good generator has a very large
period (typically, more than the 2^N where N is the number of bits in
the integer word).  A good generator also has good statistical
properties such as approximately equal frequency of generating each
number.

Pseudo-random generators in DJGPP's library are such ``good''
generators.  They are NOT ``informal''; they are based on proven
algorithms, and therefore the series they produce are quite good.

However, this thread started when somebody tried to produce small
random numbers by computing "rand() % b" where b is a small integer.
This is usually a bad idea because many random generators don't ensure
their least significant bits are also random.  This can only be done
with generators specifically designed to make all their bits random.
`rand' doesn't have this property (`random' does); but that doesn't
mean it generates non-random series, it just means that you shouldn't
produce small random values by that naive method when you use `rand'.

- Raw text -


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