From 06eb4747052a6ef109ab65688fc4d29a39a71c4c Mon Sep 17 00:00:00 2001 From: Jon Fowler Date: Thu, 8 Oct 2020 16:08:04 +0100 Subject: [PATCH] Improve the distribution of `scaleLinear` (#405) * Improve the distribution of scaleLinear * Style nits (STYLE_GUIDE.md) Co-authored-by: Nikos Baxevanis --- hedgehog/src/Hedgehog/Internal/Range.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hedgehog/src/Hedgehog/Internal/Range.hs b/hedgehog/src/Hedgehog/Internal/Range.hs index ce599f89..f009275d 100644 --- a/hedgehog/src/Hedgehog/Internal/Range.hs +++ b/hedgehog/src/Hedgehog/Internal/Range.hs @@ -305,8 +305,14 @@ scaleLinear sz0 z0 n0 = n = toInteger n0 + -- @rng@ has magnitude 1 bigger than the biggest diff + -- i.e. it specifies the range the diff can be in [0,rng) + -- with the upper bound being exclusive. + rng = + n - z + signum (n - z) + diff = - ((n - z) * fromIntegral sz) `quot` 99 + (rng * fromIntegral sz) `quot` 100 in fromInteger $ z + diff