Fixed case when operation gets cancelled
This commit is contained in:
parent
b662d08c9c
commit
d5404d65c8
@ -43,9 +43,14 @@ namespace FastRng.Double
|
|||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var x = await this.rng.GetUniform(token);
|
var x = await this.rng.GetUniform(token);
|
||||||
|
if (double.IsNaN(x))
|
||||||
|
return x;
|
||||||
|
|
||||||
var nextBucket = (int)Math.Floor(x * this.sampleSize);
|
var nextBucket = (int)Math.Floor(x * this.sampleSize);
|
||||||
var threshold = this.probabilities[nextBucket];
|
var threshold = this.probabilities[nextBucket];
|
||||||
var y = await this.rng.NextNumber(0.0d, this.max, this.uniform, token);
|
var y = await this.rng.NextNumber(0.0d, this.max, this.uniform, token);
|
||||||
|
if (double.IsNaN(y))
|
||||||
|
return y;
|
||||||
|
|
||||||
if(y > threshold)
|
if(y > threshold)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user