-
-
Notifications
You must be signed in to change notification settings - Fork 461
Deprecate rand::rngs::mock module and StepRng #1634
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
Conversation
91daf72
to
fdaf424
Compare
I think we can simply remove benchmarks for |
Yes... The more questionable case are the tests in Then there is a usage in Maybe we should keep Note: I updated the motivation above (last two paragraphs). I also note one usage in |
The easiest solution would be to just use |
This is not why those tests use |
For this we can use an internal mock RNG which just reads values from a static array. Something like this: pub MockRng32 {
values: &'static [u32],
pos: usize,
} Or indeed keep |
66b759f
to
f38ce9b
Compare
f38ce9b
to
e560ced
Compare
Tests still generate warnings like this:
There's already Shall I just delete the tests? |
I think, yes. It does not look like such tests add anything useful (I assume stability of distributions using a proper PRNG is tested in relevant modules). |
CHANGELOG.md
entrySummary
Deprecate
rand::rngs::mock
module andStepRng
Motivation
We have had many reports of unexpected outputs when using
StepRng
with other random algorithms (especiallyUniform
/random_range
): #628, #1020, #1303, #1578, #1633. These reports are due to people assuming thatStepRng::new(0, 1)
will immediately cycle over all possible outputs of a small range; it won't because our uniform range algorithms use variations on widening multiply, not division-with-remainder.Moreover, our algorithms should only be expected to yield outputs of the expected distribution when fed random inputs. As such, the only expectation which may be met when using a
StepRng
as input is that all outputs will be valid outputs. (Unless someone were to test all possible outputs untilStepRng
loops — get back to me when your test suite has finished counting tou64::MAX
! But even then, assumptions wouldn't hold to algorithms potentially consuming multiple random values in sequence.)Further motivation is that we can't think of a good reason to useTheStepRng
over something likeSmallRng
Pcg*
orXoshiro*
, which are easy to implement and yield pseudo-random output.rand
tests show some good reasons to want aStepRng
: in order to test how a randomised algorithm behaves with fixed input. This of course only has value where the exact behaviour of the algorithm is known, which is usually limited to the test code in the module where it is defined since this behaviour is usually not specified.In other words,
StepRng
should not be used except when testing a randomised algorithm implementation (thus all the issues linked above are mis-uses).Details
StepRng
and themock
module are deprecated, awaiting removal in the next breaking release.