public double randInverseCDF ( ) { final double a0 = 2.50662823884 ; final double a1 = - 18.61500062529 ; final double a2 = 41.39119773534 ; final double a3 = - 25.44106049637 ; final double b0 = - 8.47351093090 ; final double b1 = 23.08336743743 ; final double b2 = - 21.06224101826 ; final double b3 = 3.13082909833 ; final double c0 = 0.3374754822726147 ; final double c1 = 0.9761690190917186 ; final double c2 = 0.1607979714918209 ; final double c3 = 0.0276438810333863 ; final double c4 = 0.0038405729373609 ; final double c5 = 0.0003951896511919 ; final double c6 = 0.0000321767881768 ; final double c7 = 0.0000002888167364 ; final double c8 = 0.0000003960315187 ; double y , r , x ; double u = Math . random ( ) ; while ( u == 0.0 ) { u = Math . random ( ) ; } y = u - 0.5 ; if ( Math . abs ( y ) < 0.42 ) { r = y * y ; x = y * ( ( ( a3 * r + a2 ) * r + a1 ) * r + a0 ) / ( ( ( ( b3 * r + b2 ) * r + b1 ) * r + b0 ) * r + 1 ) ; } else { r = u ; if ( y > 0 ) { r = 1 - u ; } r = Math . log ( - Math . log ( r ) ) ; x = c0 + r * ( c1 + r * ( c2 + r * ( c3 + r * ( c4 + r * ( c5 + r * ( c6 + r * ( c7 + r * c8 ) ) ) ) ) ) ) ; if ( y < 0 ) { x = - ( x ) ; } } return mu + sigma * x ; }
Uses Inverse CDF method to generate a Gaussian deviate .