Fixed rare issue with too high index for bucket

This commit is contained in:
Thorsten Sommer 2020-11-01 13:47:33 +01:00
parent f213ca64b0
commit 3f4c79a23d
2 changed files with 6 additions and 0 deletions

View File

@ -47,6 +47,9 @@ namespace FastRng.Double
return x;
var nextBucket = (int)Math.Floor(x * this.sampleSize);
if (nextBucket >= this.probabilities.Length)
nextBucket = this.probabilities.Length - 1;
var threshold = this.probabilities[nextBucket];
var y = await this.rng.NextNumber(0.0d, this.max, this.uniform, token);
if (double.IsNaN(y))

View File

@ -46,6 +46,9 @@ namespace FastRng.Float
return x;
var nextBucket = (int)MathF.Floor(x * this.sampleSize);
if (nextBucket >= this.probabilities.Length)
nextBucket = this.probabilities.Length - 1;
var threshold = this.probabilities[nextBucket];
var y = await this.rng.NextNumber(0.0f, this.max, this.uniform, token);
if (float.IsNaN(y))