Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!mcvax!enea!hafro!gunnar From: gunnar@hafro.UUCP (Gunnar Stefansson) Newsgroups: sci.math Subject: Re: Need formula for Normal Distribution Simulation Message-ID: <293@hafro.UUCP> Date: Thu, 6-Nov-86 02:21:09 EST Article-I.D.: hafro.293 Posted: Thu Nov 6 02:21:09 1986 Date-Received: Fri, 7-Nov-86 22:06:04 EST References: <146@helm.UUCP> <5270001@hpfcpf.HP.COM> <401@entropy.UUCP> <2198@ecsvax.UUCP> Reply-To: gunnar@hafro.UUCP (Gunnar Stefansson) Organization: Marine Research Institute, Reykjavik Lines: 47 My mailer can't seem to find this address any better than other mailers, so here we go to the net. I have my doubts about using the Box-Muller and like transforms, which some people have recommended. The reasons are at least twofold: 1. It is very ineffective -- there are sines, cosines, logs and square roots to be evaluated every time. So it takes MUCH longer than a random number generator should. Marsaglia's improvement of the method is somewhat more effective, but there are still logs and square roots to be taken every time. 2. It is not at all obvious what happens if your uniform input is not uniform enough. So to start with, you must be reasonably sure that your uniform numbers are really iid uniform. Of course, when using the Unix rand() (or whatever), you're probably not getting very good random numbers. Adding up 12 uniforms may be good enough, but that is unlikely. Be careful that the resulting distribution will have zero probability in the tails. So if you are interested in e.g. the distribution of a max of things, it seems likely that it will get messed up. I'd like to recommend the book 'Statistical Computing' by Kennedy and Gentle as a general intro -- it's more recent than Knuth. In it, you'll find lots of good algorithms, many of which can be very well programmed in C (as opposed to the Fortran that they use). The feedback-shift-register methods for uniforms seem to be quite adequate and cheap to use. Further, there are several algorithms for transforming to normal given, most of them cheaper than the Box-Muller transform. One in particular (the Marsaglia-Bray "convenient" method, p. 203) is simple and fast). I have implemented a u(0,1) and a n(0,1) from that book. Writing the programs in C turned out to be much simpler than the Fortran counterparts. --Gunnar ----------------------------------------------------------------------------- Gunnar Stefansson {mcvax,seismo}!enea!hafro!gunnar Marine Research Institute, Reykjavik gunnar@hafro.uucp -- ----------------------------------------------------------------------------- Gunnar Stefansson {mcvax,seismo}!enea!hafro!gunnar Marine Research Institute, Reykjavik gunnar@hafro.UUCP