Xref: utzoo sci.math:5714 comp.sources.wanted:6382 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!voder!pyramid!prls!philabs!linus!bs From: bs@linus.UUCP (Robert D. Silverman) Newsgroups: sci.math,comp.sources.wanted Subject: Re: random numbers Keywords: normal distribution, Gaussian Message-ID: <44881@linus.UUCP> Date: 14 Feb 89 04:57:34 GMT References: <10471@ut-emx.UUCP> <734@fcs280s.ncifcrf.gov> Reply-To: bs@faron.UUCP (Robert D. Silverman) Distribution: na Organization: The MITRE Corporation, Bedford MA Lines: 31 In article <734@fcs280s.ncifcrf.gov> toms@ncifcrf.gov (Tom Schneider) writes: >In article <10471@ut-emx.UUCP> ken@ut-emx.UUCP (kenneth Moore) writes: >>I am looking for a program to generate -Normal distributed >> random numbers (for any mean and standard deviation).I would >The simplest way to generate such numbers is to add together several >flat distribution numbers. This is very costly, and there is a better way. >A friend showed me how to do this last week, so I put the code together Your friend misinformed you about the cost of the method. See below. >today. It works fine. The program is in Pascal, and should work >on any machine with a good compiler. Send me a note if you want a copy. >It's not hard to do. If U is a member of the set [0..1] and Un and Un+1 >are two members, then define > theta = Un 2 pi > r = sqrt(-2 ln(Un+1)) stuff deleted.... This is essentially the polar method. It does work. Your assertion that it is less costly than using the central limit theorem is incorrect however. It is far faster to do 6 floating point additions than to compute Un followed by a LOG and a SQUARE ROOT. The latter computation is MUCH slower. Especially on vector machines where a vectorized add is very quick. I might also suggest looking at rejection methods and Marsaglia's wedge tail method. Check out Knuth V. 2 Bob Silverman