How to use SeedableRng?


#1

I can’t figure out how to use the SeedableRng trait, which I presume is used to initialize other generators, like XorShiftRng. I’ve tried these things:

let xsr = XorShiftRng::from_rng(rand::thread_rng());

That results in function or associated item not found in state::rand::XorShiftRng

let xsr : XorShiftRng = SeedableRng::from_rng(rand::thread_rng());

The results in function or associated item not found in state::rand::SeedableRng<_>

The from_seed function does work:

let xsr = XorShiftRng::from_seed([1,2,3,4]);

Are the docs perhaps just refering to a newer functionality that I don’t have in my version? I have “rustc 1.24.1” and rand = "*" in my Cargo.toml.


#2

I suppose that you want to use ThreadRng's output to seed a XorShiftRng:

let mut xsr = XorShiftRng::from_seed(rand::thread_rng().gen());