[go: up one dir, main page]

Function srand

Source
pub fn srand(seed: u64)
Expand description

Seeds the pseudo-random number generator used by rand() with the value seed.

Examples found in repository?
examples/basic.rs (line 5)
3fn main() {
4    // seed random
5    qrand::srand(12345);
6
7    // get random number from 0 to u32::MAX
8    let x = qrand::rand();
9
10    // get random number from given range
11    let x = qrand::gen_range(0., 1.);
12    assert!(x >= 0. && x < 1.);
13    println!("x={}", x);
14
15    // gen_range works for most of standard number types
16    let x: u8 = qrand::gen_range(64, 128);
17    assert!(x >= 64 && x < 128);
18    println!("x={}", x);
19}