delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/28/06:34:50

Message-ID: <3545ADCF.5AE@pobox.oleane.com>
Date: Tue, 28 Apr 1998 12:22:07 +0200
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Elias Pschernig <f DOT x DOT gruber-museum-arnsdorf AT magnet DOT at>
CC: djgpp AT delorie DOT com
Subject: Re: Problem with Function rand()
References: <8e5722f0 DOT 35435f96 AT aol DOT com> <6i2nmp$sk8$2 AT orudios DOT magnet DOT at>

Elias Pschernig wrote:
> 
> hi, i dont understand everything of the article,
> but when reading it, it seems GNU's random
> number function is not very good ?
> 

Sort of. It is probably good enough for 99% of all applications using 
random numbers. In particular, if you are programming games, it is 
certainly random enough.

> because i wrote a program to test the random
> numbers, and i just counted how often the
> first 32 bits (from 0 to 31) appear, and so far
> the random numbers do work, after a million
> times or so there still was no such difference
> in their count that i thought it wouldn't work.
> 

The "spectral test" used by the original poster attempts to detect "low 
order correlations". Its result shows that sets of three successive calls 
to rand() tend to be correlated with each other. If you take three 
successive random numbers and interpret them as the coordinates of a 
point in 3d space, the result obtained on the spectral test says that 
these points tend to fall along a small number of planes. 


> so does the article say it's not good to use
> GNU's rand() function in programs any longer,
> or can i go on using it ?

The article says that, given the algorithm chosen, one could choose 
better parameters than those use in rand(). In practice, it means that if 
you are doing research in statistics and you need a random number 
generator, or if you do Monte Carlo integration of a very "hairy" 
function, DJGPP rand() *might* cause you problems, and you should cross 
check your results with those obtained with another RNG (but this is a 
sensible thing to do everytime you use random numbers in a serious 
fashion). For all other cases, DJGPP's rand() is IMHO good enough, and 
you can go on using it.

Francois


- Raw text -


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