alea icon indicating copy to clipboard operation
alea copied to clipboard

Fast and easy zero-dep random number generation.

alea

Crates.io Documentation License

A zero-dependency crate for fast number generation, with a focus on ease of use (no more passing &mut rng everywhere!).

The implementation is based on wyrand, a high-quality and fast generator.

This crate is heavily inspired by fastrand. For some benchmarks, see benches.

Usage

Add the following to your Cargo.toml:

[dependencies]
alea = "0.2"

Examples

Flip a coin:

if alea::bool() {
  println!("heads");
} else {
  println!("tails");
}

Generate a u64:

let u = alea::u64();

Fill a vector with random integers in some range:

let n = 1_000_000;

let mut v = vec![0; n];
for i in 0..n {
  v[i] = alea::i32_in_range(-200, 150);
}

Seed the generator to get reproducible results:

alea::set_seed(10);