MathNet
from second top answer
public static double GenerateRandomVariant(double mean,double deviation,System.Random rand=null, int factor=1)
{
rand = rand ?? new Random();
double randNormal=(MathNet.Numerics.Distributions.Normal.Sample(rand, mean , deviation));
return factor * randNormal;
}
Box-Mueller Transform
from top answer via link (twice as fast?)
by u/yoyoyoyosef Random Gaussian Variables
public static double GenerateRandomVariant(double mean, double deviation, System.Random rand=null, int factor = 1)
{
rand = rand ?? new Random();
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 + deviation * randStdNormal); //random normal(mean,stdDev^2)
return randNormal * factor;
}