Mail Archives: djgpp/1997/06/05/04:17:17
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 -