Article View: comp.sys.ibm.pc.programmer
Article #42Re: Random Number Generation in Turbo C 2.0
From: Scott Bostater
Date: Thu, 15 Mar 1990 13:46
Date: Thu, 15 Mar 1990 13:46
46 lines
2469 bytes
2469 bytes
In article <1990Mar14.195315.2985@agate.berkeley.edu> raymond@math.berkeley.edu (Raymond Chen) writes:
>eisen@jhunix.UUCP (Gunther Wil Anderson) presented an algorithm
>that claims to produce normally-distributed random numbers.
>
>If you read the code carefully, however, you'll observe that
>it really doesn't do that. It merely produces a crude approximation
>to a normal distribution, based on the principle that the sum
>of a large number of uniform distributions looks sort of like
>a normal distribution.
And a rough approximation at that. Try summing 10 to 15 points for something
close.
>
>In particular, the function will never return values with absolute
>value greater than sqrt(12).
>
[ details of doing the intergral to compute normal distribution omited]
There is a quick and easy transformation that takes 2 independant uniform
variables and provides 2 independant normal (or gaussian) random variables.
Essentially, given:
a,b { random variables uniform [0,1] }
sigma { standard deviation of gaussian variables }
mean { mean of gaussian variables }
Then
u = 2 * pi * a
v = Sqrt(2) * Sqrt( -ln(b)) { thats log base e }
x = Cos( u) * v * sigma + mean
y = Sin( u) * v * sigma + mean
x & y are now N(mean,sigma) distributed independant vairables.
References: 1) _Probabilty,_Random_Variables,_and_Stochastic_Processes_ by
Athanasios Papoulis (losey text, good reference)
2) _Numerical_Respicies_in_[C|Pascal|Fortran]_ (unsure of author)
(very good references, wish I owned a copy :-)
3) _EE_6051_Homework__Set_Number_5,_Problem_3_, (myself)
--
Scott Bostater GTRI/RAIL/RAD (Ga. Tech)
"My soul finds rest in God alone; my salvation comes from Him" -Ps 62.1
uucp: ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!bb16
Internet: bb16@prism.gatech.edu
Technical Details
Message-ID:
<7078@hydra.gatech.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!mephisto!prism!bb16References:
<21720@netnews.upenn.edu> <4491@jhunix.HCF.JHU.EDU> <1990Mar14.195315.2985@agate.berkeley.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!mephisto!prism!bb16 From: bb16@prism.gatech.EDU (Scott Bostater) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: Random Number Generation in Turbo C 2.0 Message-ID: <7078@hydra.gatech.EDU> Date: 15 Mar 90 13:46:29 GMT References: <21720@netnews.upenn.edu> <4491@jhunix.HCF.JHU.EDU> <1990Mar14.195315.2985@agate.berkeley.edu> Reply-To: bb16@prism.gatech.EDU (Scott Bostater) Distribution: usa Organization: Georgia Institute of Technology Lines: 46