From e6ec8aeafa5861bae55b8f37fc75b6ff2a0f422b Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 29 Sep 2020 20:10:55 +0200 Subject: [PATCH] Added optional threshold --- FastRng/Double/ShapeFitter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FastRng/Double/ShapeFitter.cs b/FastRng/Double/ShapeFitter.cs index 4b45ebd..5f53e14 100644 --- a/FastRng/Double/ShapeFitter.cs +++ b/FastRng/Double/ShapeFitter.cs @@ -10,10 +10,12 @@ namespace FastRng.Double private readonly double[] samples; private readonly IRandom rng; private readonly ushort sampleSize; + private readonly double threshold; - public ShapeFitter(Func shapeFunction, IRandom rng, ushort sampleSize = 100) + public ShapeFitter(Func shapeFunction, IRandom rng, ushort sampleSize = 100, double threshold = 0.99) { this.rng = rng; + this.threshold = threshold; this.sampleSize = sampleSize; this.samples = new double[sampleSize]; this.probabilities = new double[sampleSize]; @@ -35,7 +37,7 @@ namespace FastRng.Double var nextBucket = (int)Math.Floor(nextNumber * this.sampleSize); this.samples[nextBucket] += this.probabilities[nextBucket]; - if (this.samples[nextBucket] >= 1.0) + if (this.samples[nextBucket] >= this.threshold) { this.samples[nextBucket] = 0.0; return nextNumber;