WIP: Fixing normal distribution
This commit is contained in:
parent
d325e038ba
commit
11c887988d
@ -29,13 +29,19 @@ namespace FastRng.Double.Distributions
|
|||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var u1 = await this.Random.GetUniform(token);
|
//
|
||||||
var u2 = await this.Random.GetUniform(token);
|
// Previously:
|
||||||
var r = Math.Sqrt(-2.0 * Math.Log(u1));
|
//
|
||||||
var theta = 2.0 * Math.PI * u2;
|
// var u1 = await this.Random.GetUniform(token);
|
||||||
var value = r * Math.Sin(theta);
|
// var u2 = await this.Random.GetUniform(token);
|
||||||
|
// var r = Math.Sqrt(-2.0 * Math.Log(u1));
|
||||||
|
// var theta = 2.0 * Math.PI * u2;
|
||||||
|
// var value = r * Math.Sin(theta);
|
||||||
|
// return this.Mean + this.StandardDeviation * value;
|
||||||
|
|
||||||
return this.Mean + this.StandardDeviation * value;
|
const double SQRT_2PI = 2.506628275;
|
||||||
|
var x = await this.Random.GetUniform(token); // BUG: It seems, that uniform is not uniform (enough) or RunningStatistics had specific issues
|
||||||
|
return 1.0 / (this.StandardDeviation * SQRT_2PI) * Math.Exp(-0.5 * Math.Pow((x - this.Mean) / this.StandardDeviation, 2.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user