Fixed case when operation gets cancelled

This commit is contained in:
Thorsten Sommer 2020-10-31 22:11:20 +01:00
parent b662d08c9c
commit d5404d65c8

View File

@ -43,9 +43,14 @@ namespace FastRng.Double
while (!token.IsCancellationRequested)
{
var x = await this.rng.GetUniform(token);
if (double.IsNaN(x))
return x;
var nextBucket = (int)Math.Floor(x * this.sampleSize);
var threshold = this.probabilities[nextBucket];
var y = await this.rng.NextNumber(0.0d, this.max, this.uniform, token);
if (double.IsNaN(y))
return y;
if(y > threshold)
continue;