seeded_random/
seed.rs

1#[allow(missing_copy_implementations)]
2#[derive(Debug)]
3/// This encapsulates the RNG seed into a separate, *uncopyable*, and *uncloneable* value so
4/// it can not be accidentally propagated to another RNG without understanding the implication
5/// of reusing seeds.
6pub struct Seed(pub(crate) u64);
7
8impl Seed {
9  /// If you absolutely need to create a new seed from a raw value, use this function.
10  /// It's "unsafe" not because of memory reasons but because blindly reusing seed values
11  /// can get you into tough-to-troubleshoot situations.
12  ///
13  /// It's better to generate new seeds and new RNGs from those seeds.
14  pub const fn unsafe_new(seed: u64) -> Self {
15    Self(seed)
16  }
17
18  /// Creates a new RNG from this seed.
19  #[cfg(feature = "rng")]
20  pub fn rng(self) -> crate::Random {
21    crate::Random::from_seed(self)
22  }
23}
24
25impl std::fmt::Display for Seed {
26  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27    write!(f, "{}", self.0)
28  }
29}