rust-random / rand

A Rust library for random number generation.
https://crates.io/crates/rand
Other
1.67k stars 432 forks source link

Add serde1 feature on SmallRng #1467

Closed maratik123 closed 4 months ago

maratik123 commented 4 months ago

Summary

Added a serde1 feature and added Serialize/Deserialize to SmallRng

Motivation

Need to save and load random generator state on simulation to have reproducible generations. Internal implementations of SmallRng (Xoshiro256PlusPlus and Xoshiro128PlusPlus) can handle serde feature. It is strange that wrapper can not afford it.

Details

Add #[derive(Serialize, Deserialize)] to struct SmallRng

dhardy commented 4 months ago

It's deliberate that the wrapper doesn't support it: we reserve the right to change the implementation (and generated results) at any time, therefore it makes no sense to use this if you want reproducibility.

Use the rand_xoshiro crate (or another) instead.