The probability density function for a gaussian distributed random variable X
|f(x) = |
|[ 1 / √(2π) ] e -½ x²|| for -∞ < x < ∞|
Because gaussian random variates are frequently used to generate random variates with different probability distributions and several algorithms are available to generate a gaussian random variate; the place holder, Gaussian_Random_Variate()
, is used for the gaussian distributed random variate. Any other function which uses a gaussian random variate calls Gaussian_Random_Variate()
, which in turn calls the algorithm to generate a gaussian random variate. The function, Init_Gaussian_Random_Variate()
, must be called prior to calling Gaussian_Random_Variate()
- void Init_Gaussian_Random_Variate( double (*r_generator)(void) )
This function sets the gaussian random number generator to that specified by the argument so that later calls to Gaussian_Random_Variate() will call the function given in the argument list. Currently, four such possible functions are given below: Gaussian_Variate_Box_Muller(), Gaussian_Variate_Polar_Marsaglia(), double Gaussian_Variate_Marsaglias_Ziggurat(), and double Gaussian_Variate_Sum_12_Uniforms() .
- double Gaussian_Random_Variate( void )
This function calls the gaussian generator specified in the call to Init_Gaussian_Random_Variate to return an gaussian random variate.
- double Gaussian_Variate_Box_Muller( void )
This function uses the Box-Muller method to return a random variate with the gaussian density given above.
- double Gaussian_Variate_Polar_Marsaglia( void )
This function uses the Polar-Marsaglia method to return a random variate with the gaussian density given above.
- double Gaussian_Variate_Marsaglias_Ziggurat( void )
This function uses the Marsaglia's ziggurat method to return a random variate with the gaussian density given above.
- double Gaussian_Variate_Sum_12_Uniforms( void )
This function invokes the Central limit theorem to generate a gaussian random variate by returning the sum of 12 independent uniform(0,1) random variates after subtracting 6 (the mean). This method is not recommended as it is both slower than the others and has poorer accuracy. It is included only because it was one of the earliest methods used.
source code is available for these routines: