[][src]Trait sgx_rand::reseeding::Reseeder

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

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

Example

use sgx_rand::{Rng, SeedableRng, StdRng};
use sgx_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.

Loading content...

Implementors

impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault[src]

Loading content...