// Normal distribution function. select one of the three generation methods randomly, which is more random.
Public classNormal {
Public normal (){
}
Public double normalrandom1 (double A, double B) {// note that B is the square of the variance, which is equal to the standard deviation.
Double temp = 12;
Double X = 0;
For (INT I = 0; I <temp; I ++)
X = x + (math. Random ());
X = (X-temp/2)/(math. SQRT (temp/12 ));
X = a + x * Math. SQRT (B); Return X;
}
Public double normalrandom2 (double A, double B ){
Double Pi = 3.1415926535;
Double R1 = math. Random ();
Math. Random ();
Math. Random ();
Math. Random ();
Math. Random ();
Math. Random ();
Math. Random ();
Math. Random ();
Double r2 = math. Random ();
Double u = math. SQRT (-2) * Math. Log (R1) * Math. Cos (2 * pI * R2 );
Double Z = a + u * Math. SQRT (B); Return (z );
}
Public double normalrandom3 (double A, double B ){
Double f = 0;
Double C0 = 2.515517, C1 = 0.802853, C2 = 0.010328;
Double d1 = 1.432788, D2 = 0.189269, D3 = 0.001308; double W;
Double R = math. Random ();
If (r <= 0.5) W = R;
Else W = 1-R;
If (R-0.5)> 0) F = 1;
Else if (r- 0.5) <0) F =-1;
Double Y = math. SQRT (-2) * Math. Log (w ));
Double X = F * (Y-(C0 + C1 * Y + C2 * y * Y) /(1 + D1 * Y + D2 * y * Y + D3 * y ));
Double Z = a + x * Math. SQRT (B); Return (z );
}
// The method for determining which Normal Distribution Random Number function is used is as follows:
Public double normalrandom (double A, double B ){
Double R = math. Random () * 9;
Switch (INT) R/3 ){
Case 0: Return normalrandom1 (A, B );
Case 1: Return normalrandom2 (A, B );
Case 2: Return normalrandom3 (A, B );
}
Return 0.0;
}
}