Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the distribution of scaleLinear #405

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
(rng * fromIntegral sz) `quot` 100
in
fromInteger $ z + diff

Expand Down