diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index 8eec4c14..c6e9f7c1 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -392,9 +392,13 @@ namespace MathNet.Numerics.Distributions /// a random number from the Beta distribution. internal static double SampleUnchecked(System.Random rnd, double a, double b) { - var x = Gamma.SampleUnchecked(rnd, a, 1.0); - var y = Gamma.SampleUnchecked(rnd, b, 1.0); - return x == 0 ? 0 : x / (x + y); + double x, y; + do + { + x = Gamma.SampleUnchecked(rnd, a, 1.0); + y = Gamma.SampleUnchecked(rnd, b, 1.0); + } while (x == 0 && y == 0); + return x / (x + y); } internal static void SamplesUnchecked(System.Random rnd, double[] values, double a, double b)