Macro sarkara::rand
[−]
[src]
macro_rules! rand { ( choose $range:expr, $n:expr ) => { ... }; ( choose $range:expr ) => { ... }; ( _ ) => { ... }; ( fill $vec:expr ) => { ... }; ( bytes $len:expr ) => { ... }; ( $len:expr ) => { ... }; }
rand macro.
rand!( choose $range, $n )
Randomly choose $n values in $range.
extern crate rand; #[macro_use] extern crate sarkara; let mut output = rand!(choose 0..3, 3); output.sort(); assert_eq!(output, [0, 1, 2]);Run
rand!( choose $range )
Randomly choose a value in $range.
extern crate rand; #[macro_use] extern crate sarkara; let output = rand!(choose 0..3); assert!([0, 1, 2].contains(&output));Run
rand!( _ )
Generating a random value, like rand::random()
.
extern crate rand; #[macro_use] extern crate sarkara; let output: u8 = rand!(_); assert!(std::u8::MIN <= output && std::u8::MAX >= output);Run
rand!( fill $vec )
fill a slice.
extern crate rand; #[macro_use] extern crate sarkara; let mut input = [0; 8]; rand!(fill input); assert!(input.iter().any(|&b| b != 0));Run
rand!( bytes $len )
Generate a random [u8; $len]
.
extern crate rand; #[macro_use] extern crate sarkara; let output = rand!(bytes 8); assert_eq!(output.len(), 8);Run
rand!( $len )
Generate a random Vec<_>
.
extern crate rand; #[macro_use] extern crate sarkara; let mut output = rand!(8); output.push(99); assert_eq!(output.len(), 9);Run