Path: utzoo!utgpu!water!watmath!clyde!rutgers!mailrus!ames!pasteur!ucbvax!agate!saturn!chromo!joseph From: joseph@chromo.ucsc.edu (Joseph Reger) Newsgroups: comp.lang.c Subject: Re: random number generator Summary: How to get approximately normal deviates Keywords: Random numbers, normal distribution, central limit theorem Message-ID: <1989@saturn.ucsc.edu> Date: 17 Feb 88 17:40:43 GMT References: <11809@brl-adm.ARPA> <225800004@uxe.cso.uiuc.edu> Sender: usenet@saturn.ucsc.edu Reply-To: joseph@chromo.ucsc.edu (Joseph Reger) Organization: Physics Department, University of California, Santa Cruz Lines: 25 In article <225800004@uxe.cso.uiuc.edu> mcdonald@uxe.cso.uiuc.edu writes: > >>Simplistic, but this works: >>Generate about 12 random numbers (assuming 0.0 <= i <1.0) > > ADD THEM TOGETHER > >>and divide by 12. This is sufficiently close to gaussian distribution >>for most purposes. The more numbers you generate before you do the >>division, the closer you will get to purely gaussian distribution. Devide by 12?? This method uses the central limit theorem and gives nearly gaussian (normal) random numbers if the number of uniform random numbers to be summed up is sufficiently large: Take N uniform random deviates on (0,1): u(1), u(2),...,u(N). Then g = sqrt(12/N) * ( (u(1)+u(2)+...+u(N)) - N/2 ) yields a (nearly) normal variable with mean 0 and variance 1. N=12 seems to be sufficiently large for most purposes and avoids computing the sqrt() factor. (So do not devide by 12, subtract 6!). g' = M + D * g gives a normal random number with mean M and standard deviation D.