[comp.sources.wanted] Normal distribution random number generator -- WANTED

winarko@qucis.queensu.CA (Edi Winarko) (12/01/90)

I am looking for C source code to generate normal distribution
random numbers. I want to be able to generate random numbers
in the range of 0 - N (N could be equal to 9999, 99999 or 999999) that 
have normal distribution with mean, say, u and standard deviation s.

Thanks for any help,

--Edi W
winarko@qucis.queensu.ca

wilf@sce.carleton.ca (Wilf Leblanc) (12/01/90)

winarko@qucis.queensu.CA (Edi Winarko) writes:

>I am looking for C source code to generate normal distribution
>random numbers. I want to be able to generate random numbers
>in the range of 0 - N (N could be equal to 9999, 99999 or 999999) that 
>have normal distribution with mean, say, u and standard deviation s.

Add M random uniform random numbers x (where x is between 0 and
N/M).  Using M = 12 to 30, will generate random variables which
are very close to normal, (not quite, but your specification
of limits ensures the results will not 'truly' be normal).
This works because of the central limit theorem (see any
probability text).  The variance and mean are easily computable
from M and N.

I hope this helps.  If you want source code, mail me.

>Thanks for any help,

>--Edi W
>winarko@qucis.queensu.ca

--
---
Wilf LeBlanc                                Systems and Computer Eng.
Internet: wilf@sce.carleton.ca              Carleton University
    UUCP: ...!uunet!mitel!sce!wilf          Ottawa, Ont, Canada

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (12/02/90)

In article <wilf.660026793@rigel.sce.carleton.ca> wilf@sce.carleton.ca (Wilf Leblanc) writes:
> >I am looking for C source code to generate normal distribution
> >random numbers.
> Add M random uniform random numbers x (where x is between 0 and
> N/M).  Using M = 12 to 30, will generate random variables which
> are very close to normal,

There are many methods available which are not only accurate but also a
lot faster than generating and summing thirty numbers. (It's also very
dangerous to add successive outputs of a linear congruential sequence.)
Look in Knuth chapter 3 to find some good techniques.

---Dan