Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random Gaussian Variables

Tags:

c#

.net

Is there a class in the standard library of .NET that gives me the functionality to create random variables that follow Gaussian distribution?

like image 964
Sebastian Müller Avatar asked Oct 20 '08 11:10

Sebastian Müller


People also ask

What is Gaussian distribution random variable?

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.

What are Gaussian random numbers?

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.


1 Answers

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) 
like image 123
yoyoyoyosef Avatar answered Sep 29 '22 18:09

yoyoyoyosef