views:

1119

answers:

4

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

A: 

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.

David Arno
Since when is Gaussian distribution 'specialised'? It's far more general than, say, AJAX or DataTables.
TraumaPony
@TraumaPony: are you seriously trying to suggest more developers use Gaussian distribution than use AJAX on a regular basis?
David Arno
Possibly; what I'm saying is that it's far more specialised. It only has one use- web apps. Gaussian distributions have an incredible number of unrelated uses.
TraumaPony
+6  A: 

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 Meyer
+7  A: 

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)
yoyoyoyosef
I tested it and compared to MathNet's Mersenne Twister RNG and NormalDistribution. Your version is more than twice as fast and the end result is basically the same (visual inspection of the "bells").
Johann Gerell
+2  A: 

Math.NET Iridium also claims to implement "non-uniform random generators (normal, poisson, binomial, ...)".

Jason DeFontes