Crate lazyrand

source ·
Expand description

It is a simple library for generating random numbers easily. The random seed is automatically initialized. But this library is not cryptographically secure. It is based on xoshiro256plusplus.

§Examples

Generate random number

let num = lazyrand::randint(1, 6);
println!("random number = {}", num);

Generate random number with seed. It can be used to generate the same random number sequence.

lazyrand::set_seed(123456);
let n1 = lazyrand::rand();
let n2 = lazyrand::rand();
let n3 = lazyrand::rand();
println!("nums = [{}, {}, {}]", n1, n2, n3);

Generate random floating point number

let f = lazyrand::rand_f64();
println!("num = {}", f);

§Examples - Shuffle

Shuffle slice

let mut a = vec![1, 2, 3, 4, 5];
lazyrand::shuffle(&mut a);
println!("shuffled = {:?}", a);

Choice one element from slice

// choice one number from slice
let mut a = vec![1, 2, 3];
let n = lazyrand::choice(&a);
println!("choice = {:?}", n);
// choice one &str from slice
let mut a = vec!["apple", "banana", "orange"];
let s = lazyrand::choice(&a);
println!("choice = {:?}", s);

§Examples with Random struct

Generate random number with Random struct

let mut random = lazyrand::Random::new();
println!("random number = {}", random.randint(1, 6));

Modules§

Structs§

Enums§

Functions§