Expand the ranges of arbitrary integers. #221
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is supposed to address both #119 and #190 by interpreting the generator's size parameter as a bias towards the induced range, instead of as a hard limit. Specifically:
In accordance with intuition, lowering the size parameter increases the probability of smaller numbers and increasing the size parameter increases the probability of larger numbers being generated.
The distribution could be further refined but I was trying to keep it simple while solving the main problem of sampling from the entire range such that the influence of the generator's
size
is easily described and understood. Here are some sample distributions with size=100 (the default size).Further comments:
Because I expanded the tests a little and also wanted to cover
i128
/u128
, I bumped the dependencies onrand
andrand_core
to0.6
and0.3
, respectively, requiring a few minor modifications.Because the latest version of the transitive dependency
lazy_static
has a lower bound for rustc >= 1.24.1 I bumped the lower bound for quickcheck accordingly. If you are willing to go up to1.26
, the feature gate fori128
could be removed, as it stabilised in that release. Would that be desirable?The
assert!
s serve only to state the established invariants and could be removed or turned into comments, if desired.