Skip to content

Commit

Permalink
Improve the distribution of scaleLinear (#405)
Browse files Browse the repository at this point in the history
* Improve the distribution of scaleLinear

* Style nits (STYLE_GUIDE.md)

Co-authored-by: Nikos Baxevanis <nikos.baxevanis@gmail.com>
  • Loading branch information
jonfowler and moodmosaic committed Oct 8, 2020
1 parent 0371468 commit 06eb474
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hedgehog/src/Hedgehog/Internal/Range.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@moodmosaic

moodmosaic May 25, 2024

Author Member

Based on feedback from @DigitalBrains1 on #528, I wonder if something simple as this passes dieharder tests:

- ((n - z) * fromIntegral sz) `quot` 99
+ ((n - z) * fromIntegral sz + (if sz == 99 then (n - z) else 0)) `quot` 99

That is, conditionally adding n - z when sz is 99, and dividing by 99 to ensure the max value occurs more often.

(rng * fromIntegral sz) `quot` 100
in
fromInteger $ z + diff

Expand Down

0 comments on commit 06eb474

Please sign in to comment.