Skip to content

Migrate pecos-random to rapidrand with stream-identical seeding#356

Merged
ciaranra merged 5 commits into
devfrom
rapidrand-migration
Jul 12, 2026
Merged

Migrate pecos-random to rapidrand with stream-identical seeding#356
ciaranra merged 5 commits into
devfrom
rapidrand-migration

Conversation

@ciaranra

Copy link
Copy Markdown
Member

rapidhash 4.5 deprecated its rng module ("use the rapidrand crate instead"), which is what tripped PR #355's lint gates and led to the temporary <4.5 hold. This is the proper migration.

The determinism question, settled empirically

Seeded reproducibility is load-bearing (users record seeds to reproduce runs), so the swap was gated on stream identity, not assumed:

  • rapidrand's mixing function and secrets are byte-identical to rapidhash 4.4's rapidrng_fast (verified against both crates' sources).
  • The seeding paths differ: old RapidRng::new(seed) stored the seed raw; rapidrand's seed_from_u64 pre-mixes (different stream), while SeedableRng::from_seed(seed.to_le_bytes()) is raw. Verified with a side-by-side harness over seeds {0, 1, 42, 0xDEADBEEF, u64::MAX}: from_seed is bit-identical to the old stream; seed_from_u64 is not.

Changes

  • New private pecos_random::rapid_rng::RapidRng shim wrapping rapidrand::RapidRng with the legacy semantics (new(u64) = raw from_seed; next()), documented in one place — all existing call sites in rng.rs/scalar_rng.rs unchanged.
  • New golden test tests/seed_stream_stability.rs: locks the first 8 outputs of ParallelRapidRng and PecosScalarRng at seed 42 to values captured from the pre-migration implementation and verified passing before the swap — any future accidental reproducibility break fails loudly.
  • statistical_quality.rs and the RNG benchmarks migrated the same way (raw from_seed, so bench comparability holds).
  • rapidhash removed from the workspace entirely (no other consumers); rapidrand 0.1.2 added.

Verification

Golden stream test passes on both sides of the migration (the actual oracle); full pecos-random suite green; cargo check --workspace clean; clippy clean on pecos-random (all targets) + benchmarks; fmt clean.

Merge-order note: #355 holds rapidhash = "4, <4.5"; this PR deletes the dependency. Whichever merges second takes a trivial Cargo.toml/Cargo.lock conflict — happy to rebase this one after #355 lands.

@ciaranra ciaranra merged commit e2b67de into dev Jul 12, 2026
62 checks passed
@ciaranra ciaranra deleted the rapidrand-migration branch July 12, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant