You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rand_xoshiro: Add state() for serde-free state export (#109)
Add a `state()` method to all 15 RNG types in `rand_xoshiro`, returning
the internal state as a value matching the type's `SeedableRng::Seed`.
This lets callers persist and reload generator state without enabling
the `serde` feature: `Self::from_seed(rng.state())` reconstructs an
identical generator.
Return type per RNG matches its `Seed`:
| RNG | `state()` |
| --------------------------------------------------------- | ----------- |
| `SplitMix64`, `Xoroshiro64Star`, `Xoroshiro64StarStar` | `[u8; 8]` |
| `Xoroshiro128*`, `Xoshiro128*` | `[u8; 16]` |
| `Xoshiro256*` | `[u8; 32]` |
| `Xoshiro512*` | `Seed512` |
The all-zero state is unreachable from any non-zero seed for these
algorithms, so the round-trip is exact for any generator obtained via
the usual constructors. (`from_seed` remaps an all-zero input to
`seed_from_u64(0)`; this is documented on each `state()`.)
Implementation lives in four small macros in `common.rs`
(`impl_state_scalar!`, `impl_state_pair!`, `impl_state_array!`,
`impl_state_seed512!`); each RNG file gets one macro invocation and one
`state_roundtrip` test.
Fixes#109, #64.
0 commit comments