Random number generator

Harish Hiriyannaiah harish at csl36h.ncsu.edu
Wed Dec 27 03:41:03 AEST 1989


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 at ecebucolix.ncsu.edu
							harish at ecelet.ncsu.edu



More information about the Comp.lang.c mailing list