macro_rules! random { ($($proc_macro:tt)*) => { ... }; }
Expand description
Generate a random number.
ยงExamples
let f: f64 = random_number::random!();
assert!(0.0 <= f && f <= 1.0);
let i: u8 = random_number::random!(..);
assert!(0 <= i && i <= 255);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let f: f64 = random_number::random!(thread_rng);
assert!(0.0 <= f && f <= 1.0);
let i: u8 = random_number::random!(.., thread_rng);
assert!(0 <= i && i <= 255);
let i: u8 = random_number::random!(..=10);
assert!(0 <= i && i <= 10);
let i: i8 = random_number::random!(..=0);
assert!(-128 <= i && i <= 0);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let i: u8 = random_number::random!(..=10, thread_rng);
assert!(0 <= i && i <= 10);
let i: i8 = random_number::random!(..=0, thread_rng);
assert!(-128 <= i && i <= 0);
let i: u8 = random_number::random!(10..);
assert!(10 <= i && i <= 255);
let i: i8 = random_number::random!(0..);
assert!(0 <= i && i <= 127);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let i: u8 = random_number::random!(10.., thread_rng);
assert!(10 <= i && i <= 255);
let i: i8 = random_number::random!(0.., thread_rng);
assert!(0 <= i && i <= 127);
let i: u8 = random_number::random!(..10);
assert!(0 <= i && i <= 9);
let i: i8 = random_number::random!(..0);
assert!(-128 <= i && i <= -1);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let i: u8 = random_number::random!(..10, thread_rng);
assert!(0 <= i && i <= 9);
let i: i8 = random_number::random!(..0, thread_rng);
assert!(-128 <= i && i <= -1);
let i: u8 = random_number::random!(1..10);
assert!(1 <= i && i <= 10);
let i: i8 = random_number::random!(-2..=12);
assert!(-2 <= i && i <= 12);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let i: u8 = random_number::random!(1..10, thread_rng);
assert!(1 <= i && i <= 10);
let i: i8 = random_number::random!(-2..=12, thread_rng);
assert!(-2 <= i && i <= 12);
let i: u8 = random_number::random!(12, 20);
assert!(12 <= i && i <= 20);
let i: i8 = random_number::random!(20, 12);
assert!(12 <= i && i <= 20);
use random_number::rand;
let mut thread_rng = rand::thread_rng();
let i: u8 = random_number::random!(12, 20, thread_rng);
assert!(12 <= i && i <= 20);
let i: i8 = random_number::random!(20, 12, thread_rng);
assert!(12 <= i && i <= 20);