Mail Archives: djgpp/1999/11/25/13:03:43
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 -