SeedableGenerator

Trait SeedableGenerator 

Source
pub trait SeedableGenerator: Generator + Default {
    // Required method
    fn new_with_seed(seed: u64) -> Self;
}
Expand description

Trait for RNGs that can be created from a user-provided seed.

Required Methods§

Source

fn new_with_seed(seed: u64) -> Self

Creates a generator from the output of an internal PRNG, which is itself seeded from seed.

As a rule: unless you are absolutely certain that you need to manually seed a generator, you don’t. Instead, use crate::new_rng when you need to create a new instance.

If you have a scenario where you really do need a set seed, prefer using the Default implementation of the desired generator.

§Examples
use ya_rand::*;

let mut rng1 = ShiroRng::new_with_seed(0);
// Default initialization is just a shortcut for explicitly seeding with 0.
let mut rng2 = ShiroRng::default();
assert!(rng1 == rng2);

let result1 = rng1.u64();
let result2 = rng2.u64();
assert!(result1 == result2);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§