Random rand = new Random(); //reuse this if you are generating many
double u1 = rand.NextDouble(); //these are uniform(0,1) random doubles
double u2 = rand.NextDouble();
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
double randNormal =
mean + stdDev * randStdNormal; //random normal(mean,stdDev^2)
public static float NextGaussian (float mean, float standard_deviation, float min, float max) {
float x;
do {
x = NextGaussian(mean, standard_deviation);
} while (x < min || x > max);
retun x;
}