Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!rutgers!mephisto!ncsuvx!news From: harish@csl36h.ncsu.edu (Harish Hiriyannaiah) Newsgroups: comp.lang.c Subject: Re: Random number generator Message-ID: <1989Dec26.164103.17945@ncsuvx.ncsu.edu> Date: 26 Dec 89 16:41:03 GMT References: <1989Dec24.175914.813@twwells.com> <83943@linus.UUCP> <940001@hpavla.HP.COM> Sender: news@ncsuvx.ncsu.edu (USENET News System) Reply-To: harish@ecebucolix.ncsu.edu Organization: Dept. of ECE, North Carolina State University, Raleigh, NC 27695 Lines: 60 A lot of netters have suggested using "rand = rand1*655536 + rand2" to create a uniform random number, where rand1 and rand2 are two uniform r.v's. It should be noted that rand will NOT be uniform, since, if z = a1*X + a2*Y , then pdf(z) = (a1*pdf(X)) *** (a2*pdf(Y)). Here *** denotes convolution, X and Y are independent random variables and pdf() is the probability density function. If pdf(X) and pdf(Y) are uniform, then pdf(z) is a trapezoid, degenerating to a triangular pdf if pdf(X) = pdf(Y), with a1 = a2. Now, if the convolution is between a very wide uniform distribution and a very narrow uniform distribution, then the resulting trapeziodal pdf MAY be approximated to a uniform distribution. So netters should be aware of this approximation and not trust the values of z near the ends of the distribution. i.e _ | | | | | | | | _____________________________________ | | *** __________________________ = / \ | | | | / \ w1 w2 ^^^^ w3 ^^^^ Areas of approximation not to be trusted. In our case, if pdf(rand1) = pdf(rand2) ( which is the case), and if a1 >> a2, (which is also true), then the above scenario results. Since I am lazy to delve into a book on probability to analytically determine the triangular portions of the trapezoidal distribution in terms of a1 and a2, I suggest that the netters carefully look into it before using the r.v's like rand. (Actually, if w1 is the width of the narrow unif pdf, and w2 that of the wide pdf, then w3 = w1 + w2, and each triagular region is of width w1, with the flat region having a height of 1/(w1*w2). ) harish pu. hi. harish@ecebucolix.ncsu.edu harish@ecelet.ncsu.edu