Hi there,
does someone of you know if there is a class in the standard library of .net, that gives me the functionality to create random variables that follow a gaussian distribution?
Greets
Sebastian
Hi there,
does someone of you know if there is a class in the standard library of .net, that gives me the functionality to create random variables that follow a gaussian distribution?
Greets
Sebastian
I don't think there is. And I really hope there isn't, as the framework is already bloated enough, without such specialised functionality filling it even more.
Take a look at http://www.extremeoptimization.com/Statistics/UsersGuide/ContinuousDistributions/NormalDistribution.aspx and http://www.vbforums.com/showthread.php?t=488959 for a third party .NET solutions though.
http://mathworld.wolfram.com/Box-MullerTransformation.html
Using two random variables, you can generate random values along a Gaussian distribution. It's not a difficult task at all.
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 = 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)
Math.NET Iridium also claims to implement "non-uniform random generators (normal, poisson, binomial, ...)".