mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Fix possible exception caused by log(0)
This commit is contained in:
parent
3356742ba2
commit
a912bcadf8
@ -212,8 +212,8 @@ namespace osu.Game.Rulesets.Osu.Utils
|
|||||||
|
|
||||||
public static float RandomGaussian(Random rng, float mean = 0, float stdDev = 1)
|
public static float RandomGaussian(Random rng, float mean = 0, float stdDev = 1)
|
||||||
{
|
{
|
||||||
double x1 = rng.NextDouble();
|
double x1 = 1 - rng.NextDouble();
|
||||||
double x2 = rng.NextDouble();
|
double x2 = 1 - rng.NextDouble();
|
||||||
double stdNormal = Math.Sqrt(-2 * Math.Log(x1)) * Math.Sin(2 * Math.PI * x2);
|
double stdNormal = Math.Sqrt(-2 * Math.Log(x1)) * Math.Sin(2 * Math.PI * x2);
|
||||||
return mean + stdDev * (float)stdNormal;
|
return mean + stdDev * (float)stdNormal;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user