Trait rand::reseeding::Reseeder [-] [+] [src]

pub trait Reseeder<R> {
    fn reseed(&mut self, rng: &mut R);
}

Something that can be used to reseed an RNG via ReseedingRng.

Example

use rand::{Rng, SeedableRng, StdRng};
use rand::reseeding::{Reseeder, ReseedingRng};

struct TickTockReseeder { tick: bool }
impl Reseeder<StdRng> for TickTockReseeder {
    fn reseed(&mut self, rng: &mut StdRng) {
        let val = if self.tick {0} else {1};
        rng.reseed(&[val]);
        self.tick = !self.tick;
    }
}
fn main() {
    let rsdr = TickTockReseeder { tick: true };

    let inner = StdRng::new().unwrap();
    let mut rng = ReseedingRng::new(inner, 10, rsdr);

    // this will repeat, because it gets reseeded very regularly.
    let s: String = rng.gen_ascii_chars().take(100).collect();
    println!("{}", s);
}

Required Methods

fn reseed(&mut self, rng: &mut R)

Reseed the given RNG.

Implementors