Is there a class in the standard library of .NET that gives me the functionality to create random variables that follow Gaussian distribution?
DEFINITION 3.3: A Gaussian random variable is one whose probability density function can be written in the general form. (3.12) The PDF of the Gaussian random variable has two parameters, m and σ, which have the interpretation of the mean and standard deviation respectively.
This form allows you to generate random numbers from a Gaussian distribution (also known as a normal distribution). The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.
Jarrett's suggestion of using a Box-Muller transform is good for a quick-and-dirty solution. A simple implementation:
Random rand = new Random(); //reuse this if you are generating many double u1 = 1.0-rand.NextDouble(); //uniform(0,1] random doubles double u2 = 1.0-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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With