1 module des.math.method.stat.randn; 2 3 import std.math; 4 public import std.random; 5 6 /// 7 double normal( double mu=0.0, double sigma=1.0 ) 8 { 9 static bool deviate = false; 10 static float stored; 11 12 if( !deviate ) 13 { 14 double max = cast(double)(ulong.max - 1); 15 double dist = sqrt( -2.0 * log( uniform( 0, max ) / max ) ); 16 double angle = 2.0 * PI * ( uniform( 0, max ) / max ); 17 18 stored = dist * cos( angle ); 19 deviate = true; 20 21 return dist * sin( angle ) * sigma + mu; 22 } 23 else 24 { 25 deviate = false; 26 return stored * sigma + mu; 27 } 28 }