Normal Distribution - 
Random Number


About Random Values


In programming languages the random number generator uses a unified distribution to select its values with the range from 0 to some max value. In the programming language C/C++ the max value is 32767 for a 16-bit integer. Now taking these values to the limit of 0 to 1 by dividing the random number by the maximum value gives a random number of type double. If you take a large set of numbers, like 10,000 and display a histogram of the results, you would end up seeing a uniform distribution. The probability of any of those random values being selected are all equal. Of course some could argue that this is or isn't true randomness.

-Normal Distribution-

The conversion of random numbers to a Normal Distribution is done by first taking the random value from one distribution (unified) and then transforming it into a new random variable of a differing distribution. This transformation can be done many different ways, but I am only going to discuss two techniques of transformation one called the Box-Muller transformation and the other called the Probability Integral transform.

-Probability Integral Transform-

The Normal distribution has a mean, μ, of 0 and a standard deviation, σ, of 1. Lets say X represents a continuous uniform distribution of the random numbers on (0,1) where P(X ≤ x) = x from 0 < x < 1.

The probability distribution function (pdf) of f(x) = 1/(b-a)  where a ≤ x ≤ b thus giving,

 f(x) = 
         0≤ x ≤ 1
0          else

by using the inverse of the continuous distribution function (cdf) of X

F(x) = 
0          x < 0     
x          0≤ x ≤ 1
1          x >1


to set Y = F-1(X) we can develop new random variables ~N(0,1).

            Basically the random number is selected giving a real value, n, and then is used to represent the nth quantiles of the normal distribution.

  Example:

The first random variable that shows up from the code, for this example, is 0.0013

0.13th percentile is then used to represent the probability of getting a random number below this percentile. The z value then gives a value of -3.011454 for its new random value.

 -Box-Muller Transformation-

              In the Box-Muller transformation the development is easier to set-up. [Carter] recommends the use of polar coordinates instead of the basic form because of the subsequent:

  1. Speed,
  2. Problems with stability around 0,
  3. Stochastic models, and
  4. Generating millions of numbers.

With this in mind I've uses the polar coordinates to generate in my C# program. A snippet of the code (in C/C++) is as follow:

   do {

         x1 = 2.0 * ranf() - 1.0;

         x2 = 2.0 * ranf() - 1.0;

         w = x1 * x1 + x2 * x2;

       } while (w >= 1.0);

       w = sqrt((-2.0 * log(w)) / w);

       y1 = x1 * w;

       y2 = x2 * w;

Every time you run this loop you will end up getting two random numbers in the normal distribution. 


-Conclusion-

           

            All three techniques that are described, helps reassure that the other techniques are also correct without a formal proof. In the normal distribution the mean is 0 with standard deviation of 1, and this could also be changed to reflect the needed distribution of values with the standardized variable formula: Z = (X – μ)/σ. 


Here are a few screen shots taken of the program:



Download


Requirements/Recommend:

File:

Click Here to Download

Instructions:

Installation:

Simply unzip the file and place the folder in the desire location. Run the [RandomNumbers.exe] file to run the program. 

Running:

Just enter how many random numbers you want the program to process, and select which type of method to have the numbers distributed over.  The program will generate the numbers and display the graphed results. 

Sources


[Andrus 04] Andrus, W., (2004). Unified Random Numbers distribution over Normal Distribution. Project for Math 370: Applied Probability at the State University of New York Institute of Technology in Utica, New York

[Carter]            Carter, E.F, “Generating Gaussian Random Numbers” http://www.taygeta.com/random/gaussian.html (visited 4/19/04).

 [Ødegaard ]            Ødegaard, B.A., “Normal Distribution Approximation”. http://finance.bi.no/~bernt/gcc_prog/recipes/recipes/node23.html (visited 5/02/04). 

Benitez-Silva, H., (2004). “Drawing from distributions using the Probability Integral Transform: the lognormal case”. http://ms.cc.sunysb.edu/~hbenitezsilv/techn3.pdf (visited 4/20/04).

Mathepi, (2003). “Some Probability Theory”. http://www.mathepi.com/comp/spring2b.html (visited 5/2/04).