cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/25/13:03:43

From: "Daniel H. Luecking" <luecking AT comp DOT uark DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: randN
Date: Tue, 23 Nov 1999 11:45:54 -0600
Organization: The University of Arkansas
Lines: 42
Message-ID: <Pine.SOL.4.10.9911231048340.27183-100000@comp.uark.edu>
References: <383904BA DOT AE45DCDE AT mpx DOT com DOT au> <81bigt$1i5 AT acp3bf DOT knirsch DOT de> <Pine DOT SUN DOT 3 DOT 91 DOT 991123091617 DOT 13225A-100000 AT is>
NNTP-Posting-Host: comp.uark.edu
Mime-Version: 1.0
In-Reply-To: <Pine.SUN.3.91.991123091617.13225A-100000@is>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 23 Nov 1999, Eli Zaretskii wrote:

> 
> On 22 Nov 1999, Hans-Bernhard Broeker wrote:
> 
> > The typical method works by transforming the distribution.
> 
> A much simpler way is to generate 6 uniform random number (by calling
> e.g. rand() 6 times), then return their average, suitably scaled to
> give the normal Gaussian deviate (if I'm not mistaken, subtract 3 from
> the average and divide the result by the square root of 2).

You are (slightly) mistaken.
 
> While seemingly stupid, this method is actually good enough to be
> included as part of respectable numerical libraries such as IMSL.  The
> theory behind it is the well-known theorem which states that the sum
> of a large number of independent random numbers approaches the normal
> distribution.

In this theorem, one needs mean of 0 and variance 1, and then use the
sum of N random numbers divided by sqrt(N).

To achieve mean 0, subtract RAND_MAX/2 fron the numbers returned by
rand(). To make them have variance 1, divide by RAND_MAX/(2*sqrt(3))
Now sum them and divide by sqrt(N).

If N=6 and you sum the numbers first, then divide the sum by RAND_MAX,
subtract 3 and _multiply_ by sqrt(2).

A disadvantage is that one will never get a result greater than
3*sqrt(2) in absolute value and the distribution is pretty far off near
these extremes. Applications may go wildly wrong if one needs to allow
large deviations or one takes very large samples. Of course the theorem
can be applied with arbitrary N much greater than 6 to get better
results.

-- 
Dan Luecking                           Dept. of Mathematical Sciences     
luecking AT comp DOT uark DOT edu                 University of Arkansas      
http://comp.uark.edu/~luecking/        Fayetteville, AR 72101

- Raw text -


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