-
Notifications
You must be signed in to change notification settings - Fork 432
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
Reproducibility of usize samples across architectures #805
Comments
It seems the core problem here is not how we generate However, I doubt an RFC with this would fly (even though it lowers memory usage), so it doesn't help us much. |
Maybe there is something we could take advantage of: The drawbacks are that (a) the effect of sampling a Obviously it needs benchmarking, but I think this sounds promising? |
I agree I also agree |
For consistency, I think the best solution is to always consume a single |
If usize were u16 then you'd need to truncate, not round, but sure. I'd think the real concern is that |
you have 64 kiB address space, so I don't expect you'll be using large libraries like Rand. Most of our RNGs produce output of 32-bit or larger words, and although the byte-oriented API can theoretically consume smaller amounts of random bits, in practice it's not worth it for performance. |
I would suggest to document the portability hazard, suggest to use fixed-width integers and casts instead, and close this issue. Note that #809 made |
Telling users to use casts like |
This is documented here. I guess we can close this issue now. |
One of the CI failures in #792 is:
This is a deterministic test that passes on x86_64 arches but is now failing on 32-bit MIPS. Why does it fail now? The RNG changed from
StdRng
(Hc128Rng
) toPcg32
, which obviously breaks tests depending on the exact RNG output — this test doesn't, but it does perform a test which only probably succeeds, and happens here not to.However, it now fails on two architectures (MIPS and ARMv7, both 32-bit). The test uses
choose_mut
which usesrng.gen_range(0, len)
wherelen: usize
... andPcg32
is a 32-bit RNG with different implementations ofgen
for 32-bit and 64-bitusize
.Okay, it's kind of obvious that
gen::<usize>()
is going to be different on different-sized architectures, but it's also a pain. Should we do something about this? @burdgesWe probably don't want to impose breaking changes like always forcing
gen::<usize>()
to useu64
or removing it altogether. And since this function is implemented in theRng
trait (which is automatically implemented for allRngCore
) we can't customise it based on the RNG.Are there any other good options for making things like
list.choose(&mut rng)
reproducible across architectures?The text was updated successfully, but these errors were encountered: