Fixed rare issue with too high index for bucket
This commit is contained in:
parent
f213ca64b0
commit
3f4c79a23d
@ -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))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user