[−][src]Trait random_trait::GenerateRand
This trait is used by Random::gen()
as a generic function to create a random value for any type which implements it.
I try to give by default implementations for all the types in libcore, including arrays and tuples, if anything is missing please raise the issue.
You can implement this for any of your types.
Examples
use random_trait::{Random, GenerateRand}; struct MyStuff{ a: u64, b: char, } impl GenerateRand for MyStuff { fn generate<R: Random + ?Sized>(rand: &mut R) -> Self { MyStuff {a: rand.gen(), b: rand.gen() } } }
Required methods
fn generate<R: Random + ?Sized>(rand: &mut R) -> Self
Generate a random value, using the rand
as source of randomness.