What do I need?
Rust 1.85 or newer. vrd's manifest declares 1.70, but the rand 0.10 crate it depends on needs 1.85: on Rust 1.80 the build stops while reading rand_core's manifest, and on 1.85 it succeeds.
How do I add it?
or in Cargo.toml:
[dependencies]
vrd = "0.0.12"
0.0.12 is the latest release on crates.io. The default feature is std, which turns on alloc.
How do I draw numbers?
use Random;
Random::new() asks the operating system for a seed and may panic if none is available; Random::from_seed never does.
How do I get the same numbers every run?
Seed the generator yourself:
use Random;
let mut rng = from_u64_seed;
let first = rng.rand; // 2783027749 with vrd 0.0.12
Random::from_seed([u8; 32]) takes a 32-byte seed instead. Neither allocates.
How do I use another backend?
Call its constructor; the methods stay the same.
use Random;
let mut mt = new_mersenne_twister; // MT19937
let mut pcg = new_pcg32; // needs the pcg feature
let mut secure = new_secure; // ChaCha20, needs the crypto feature
let token = secure.base64_token;
[dependencies]
vrd = { version = "0.0.12", features = ["pcg", "crypto"] }
How do I build for an embedded target?
Turn off the default features and seed manually:
[dependencies]
vrd = { version = "0.0.12", default-features = false }
use Random;
let mut rng = from_seed;
let n = rng.rand;
Where next?
- The API guide for every method and Cargo feature.
- The migration guide if you are coming from
rand,fastrandor an older vrd. - The full API reference on docs.rs.