public static double gaussian ( ) { // use the polar form of the Box-Muller transform double r , x , y ; do { x = uniform ( - 1.0 , 1.0 ) ; y = uniform ( - 1.0 , 1.0 ) ; r = x * x + y * y ; } while ( r >= 1 || r == 0 ) ; return x * Math . sqrt ( - 2 * Math . log ( r ) / r ) ; // Remark: y * Math.sqrt(-2 * Math.log(r) / r) // is an independent random gaussian }
Returns a real number with a standard Gaussian distribution .