[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

938.0. "Normal Dist. Random Numbers" by VIVIAN::MILTON (I'm thinking about it!) Fri Sep 30 1988 15:37

    Does anyone have a package that returns normally distibuted random
    numbers that I can use from pascal or other language?
    
    Thanks
    Tony.
T.RTitleUserPersonal
Name
DateLines
938.1BEING::POSTPISCHILAlways mount a scratch monkey.Fri Sep 30 1988 16:2515
    Here's an algorithm to generate two numbers, n1 and n2, selected from a
    Gaussian distribution with mean m and standard deviation s, given
    numbers r1 and r2 which were selected from a uniform distribution in
    [0,1).
    
    t1 = sqrt(-2 ln(r1)) sin(2 pi r2)
    t2 = sqrt(-2 ln(r1)) cos(2 pi r2)

    n1 = s t1 + m
    n2 = s t2 + m
    
    From Kiyoshi Akima, PPC Journal, who got it from Donald E. Knuth.
    
    
    				-- edp
938.2Same algorithm, faster implementation.PBSVAX::COOPERTopher CooperFri Sep 30 1988 18:1222
    Here is essentially the same algorithm from Knuth (Vol 2), in a
    form which avoids the calculation of the sin and cos.
    
    Let U1, and U2 be two independent uniform [0, 1).  Let
    
    V1 =  2*U1 - 1;	V2 = 2*U2 - 1;
    
    (V1 & V2 are uniformly distributed between -1 and 1).
    
    Let S = V1^2 + V2^2 and check to see if it is greater than 1, if
    it is get two more U's and try again.  According to Knuth this
    will repeat on the average of about 1.27 times.
    
    Now t1, and t2 are calculated as
    
    t1 = V1*sqrt(-2 ln(S)/S);  t2 = V2*sqrt(-2 ln(S)/S);
    
    These are independently distributed according to the standard normal
    distribution (mean = 0, sd = 1), and can be rescaled for a different
    mean and sd as in .1.
    
    					Topher
938.3CLT::GILBERTMultiple inheritence happensMon Oct 03 1988 12:162
    Also, check the recent literature.  I recall seeing a new improved
    algorithm in the Journal of Mathematics sometime in the past 2 yrs.
938.4Faster algorithmsCTCADM::ROTHLick Bush in '88Mon Oct 03 1988 14:4311
    See also the June 1986 issue of IEEE Micro for a much faster algorithm.
    (But the quality of the ones above is excellent.)

    Another useful reference is

	Marsaglia and Tsang
	"A fast, easily implemented method for sampling from decreasing
	or symmetric unimodal density functions"
	SIAM J. Scientific and Statistical Computing, June 1984

    - Jim