Deprecate rand::rngs::mock module and StepRng#1634
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). |
The docs for rand::StepRng say "deprecated without replacement". In fact, according to rust-random/rand#1634 which removed them, the "replacements" are SmallRng, or Pcg*, or Xoshiro*. That is, the replacement is a separate crate. `rand` exposes Xoshiro256PlusPlus as "SmallRng", if you enable a feature that enables the extra dep. Unfortunately we cannot do this for tests only, because Cargo does not support optional dev-dependencies. (Ten year old issue: rust-lang/cargo#1596 .. last comment three years ago.) Directly use rand_xoshiro instead.
The docs for rand::StepRng say "deprecated without replacement". In fact, according to rust-random/rand#1634 which removed them, the "replacements" are SmallRng, or Pcg*, or Xoshiro*. That is, the replacement is a separate crate. `rand` exposes Xoshiro256PlusPlus as "SmallRng", if you enable a feature that enables the extra dep. Unfortunately we cannot do this for tests only, because Cargo does not support optional dev-dependencies. (Ten year old issue: rust-lang/cargo#1596 .. last comment three years ago.) Directly use rand_xoshiro instead.
The docs for rand::StepRng say "deprecated without replacement". In fact, according to rust-random/rand#1634 which removed them, the "replacements" are SmallRng, or Pcg*, or Xoshiro*. That is, the replacement is a separate crate. `rand` exposes Xoshiro256PlusPlus as "SmallRng", if you enable a feature that enables the extra dep. Unfortunately we cannot do this for tests only, because Cargo does not support optional dev-dependencies. (Ten year old issue: rust-lang/cargo#1596 .. last comment three years ago.) Directly use rand_xoshiro instead.
|
Hello, Is there any suggestion for downstream projects that use this now deprecated feature in tests? It seems like there is some admission that it's useful for testing yet the only solution seems to be to flag with allow deprecated which doesn't seem like a good long-term solution. |
|
Users should use a proper PRNG, e.g. |
|
Thanks, using |
|
Thanks, using |
CHANGELOG.mdentrySummary
Deprecate
rand::rngs::mockmodule andStepRngMotivation
We have had many reports of unexpected outputs when using
StepRngwith 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
StepRngas input is that all outputs will be valid outputs. (Unless someone were to test all possible outputs untilStepRngloops — 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 useTheStepRngover something likeSmallRngPcg*orXoshiro*, which are easy to implement and yield pseudo-random output.randtests 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,
StepRngshould not be used except when testing a randomised algorithm implementation (thus all the issues linked above are mis-uses).Details
StepRngand themockmodule are deprecated, awaiting removal in the next breaking release.