Tag Archives: normal

Generating values of normal distribution – Marsaglia method

Assuming you can already produce variables of uniform distribution, you can produce variables of normal distribution using various formulas. Two of the most important are:

  1. Box–Muller method
  2. Marsaglia polar method

Most methods are based on Box-Muller method.

The Marsaglia method is my favorite since it does not require using sin() or cos() functions and the steps are very easily to implement.

Here is a sequence of the steps:

  1. Generate a value that follows uniform distribution in any space you want (eg: [ 0 , 1 ))
  2. Map that value to space (-1, +1) and assign it to variable U
  3. Repeat steps 1 and 2 and assign the result to variable V
  4. Calculate S = U*U + V*V
  5. if S = 0 or S >= 1 then free all variables if needed and restart from the beginning
  6. The following two variables will be independent and standard normally distributed (mean = 0, variance = 1):

marsaglia

Optionally you can add m to the quantities above to change the mean value of the distribution.

 

Advertisements