Skip to content

Reproducibility of usize samples across architectures #805

@dhardy

Description

@dhardy

One of the CI failures in #792 is:

$ cross test --target mips-unknown-linux-gnu --tests --no-default-features
[...]
---- seq::test::test_slice_choose stdout ----
thread 'main' panicked at 'assertion failed: -20 <= err && err <= 20', src/seq/mod.rs:481:13

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) to Pcg32, 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 uses rng.gen_range(0, len) where len: usize... and Pcg32 is a 32-bit RNG with different implementations of gen for 32-bit and 64-bit usize.

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? @burdges

We probably don't want to impose breaking changes like always forcing gen::<usize>() to use u64 or removing it altogether. And since this function is implemented in the Rng trait (which is automatically implemented for all RngCore) 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-docsDocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions