Macro pix_engine::random

source ·
macro_rules! random {
    () => { ... };
    ($v:expr) => { ... };
    ($s:expr, $e:expr$(,)?) => { ... };
}
Expand description

Returns a random number within a range.

Examples

let x = random!(); // x will range from (0.0..1.0]
assert!(x >= 0.0 && x < 1.0);

let x = random!(100); // x will range from (0..100]
assert!(x >= 0 && x < 100);
let y = random!(20, 50); // x will range from (20..50]
assert!(y >= 20 && y < 50);

let x = random!(100.0); // x will range from (0.0..100.0]
assert!(x >= 0.0 && x < 100.0);
let y = random!(20.0, 50.0); // x will range from (20.0..50.0]
assert!(y >= 20.0 && y < 50.0);