Xoshiro256++ by default
Random::new() seeds a 32-byte Xoshiro256++ generator from the operating system. Bounded integers are unbiased and floats use every mantissa bit.
How the default worksOpen-source Rust library
vrd generates random numbers with Xoshiro256++ by default, and adds Mersenne Twister, PCG, ChaCha20 and quasi-random sequences when you need them.
What it does
Each card opens its section on the features page.
Random::new() seeds a 32-byte Xoshiro256++ generator from the operating system. Bounded integers are unbiased and floats use every mantissa bit.
How the default worksMersenne Twister, PCG32, PCG64 and a ChaCha20 generator for secrets sit behind the same Random type.
Choose a backendThe same seed gives the same sequence. Snapshot a generator with serde, or split off a stream 2128 draws ahead.
Reproduce a runUniform, normal (Ziggurat), exponential and Poisson built in, and a Distribution trait for your own.
See the distributionsHalton, Sobol and Van der Corput low-discrepancy sequences for Monte Carlo integration.
Sample evenlyWith default features off, the core builds for Cortex-M and wasm32 without an allocator, and CI checks both.
Where it runsBackends
The default and the alternatives are the same Random type. Only ChaCha20 is suitable for secrets.
Default
32 bytes of state. The default for simulations, games, sampling and tests. Not for secrets.
Compare the backendspcg feature
16 and 32 bytes of state. PCG32 is the fastest backend in the published benchmarks.
See the timingscrypto feature
A cryptographically secure generator from rand_chacha, for tokens, keys and anything an attacker would want to predict.
When you need itInstall
Add the crate, create a generator and draw. vrd 0.0.12 needs Rust 1.85 or newer.
use vrd::Random;
fn main() {
// Xoshiro256++, seeded by the operating system
let mut rng = Random::new();
let roll = rng.int(1, 6); // i32 in [1, 6]
let x = rng.double(); // f64 in [0, 1)
let pick = rng.choose(&["a", "b", "c"]);
println!("{roll} {x} {pick:?}");
}The default generator is fast and statistically good, and anyone who sees enough of its output can predict the rest.
For session tokens, API keys, password-reset links and nonces, turn on the crypto feature and use Random::new_secure(). The security page sets out what vrd does and does not promise.
In numbers
Counted from the vrd repository at version 0.0.14.
vrd is a free, open-source random number generator library for Rust. Its Random type gives you integers in a range, floats, booleans, choices from a slice, shuffles, tokens and samples from four distributions. The default generator is Xoshiro256++, seeded from the operating system; Cargo features add a Mersenne Twister, PCG32 and PCG64, a ChaCha20 generator for secrets, SIMD byte fills and quasi-random sequences. It is dual-licensed under Apache-2.0 or MIT.
Only with the crypto feature and Random::new_secure(). The default generator, like the Mersenne Twister and PCG backends, is not cryptographically secure: anyone who sees enough of its output can predict the rest. The security page explains where the line is.
No. With default features off, the core builds without the standard library or an allocator, and CI checks it for a Cortex-M target and for WebAssembly. The features page shows how.
vrd is written by Sebastien Rousseau and its contributors. The source, the issue tracker and every release are on GitHub; the crate is on crates.io. Read more on the about page.