Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpl-opus!hpnmdla!hpsad!dann From: dann@hpsad.HP.COM (Dan Needham) Newsgroups: comp.lang.c Subject: Re: Wanted: Gaussian Random Number Generator Message-ID: <1820003@hpsad.HP.COM> Date: 21 Sep 89 22:47:29 GMT References: <1820002@hpsad.HP.COM> Organization: HP Signal Analysis Division - Rohnert Park, CA Lines: 32 >>>> cj@hpsad.HP.COM (Chris Johnson) writes ...... >>>> I'm looking for a random number routine which will generate >>>> numbers with a Gaussian distribution. Rand(3C) and other such >>>> programs produce (semi) even distributions. I suppose some sort >>>> of conversion routine would also work. If anyone out there has >>>> such a beast, please let me know. -cj cj@hpsad.hp.com ---------- I had to do this once in school and still have the paper I wrote it down on. This part of the program was handed out by the professor. function [a,b] = grv(sigma) % Generates a pair of Gaussian random variables with mean zero, variance sigma rand('uniform'); % Generates #'s between [0,1] pi = 3.1415927; p2 = 2*pi*rand(1); p1 = (-2) * log(rand(1)); a = sigma * sqrt(p1) * cos(p2); b = sigma * sqrt(p1) * sin(p2); ------------------------------------------------------------ Dan Needham