rapidrand
An extremely fast pseudo-random number generator, using the rapidhash mixing algorithm, designed for the rand crate and based on wyrand.
- Extremely fast: matching the performance of
fastrand,nanorand, andturborandthat all use the same PRNG construction but their own RNG traits. - High quality: passes TestU01's BigCrush and PractRand up to 16TB.
- Designed for
rand: use therandcrate traits 10x faster. Perfect for testing, benchmarks, and synthetic datasets. - Non-cryptographic: This is not a cryptographic random number generator.
Usage
RapidRng is built for the rand crate. Add both crates and use the full rand API:
[]
= "0.10"
= "0.1"
Seed it from rand's thread-local RNG (itself seeded from the OS) with from_rng:
use ; // RngExt brings `.random()`, `.random_range()`, ...
use RapidRng;
let mut rapid = from_rng;
let coin: bool = rapid.random;
let roll = rapid.random_range;
let x: u32 = rapid.random;
For a reproducible stream, seed it from a fixed value instead:
use ;
use RapidRng;
let mut rapid = seed_from_u64;
let x: u32 = rapid.random;
Without the rand crate
RapidRng also works with just rand_core's traits, using next_u64 for a u64:
use RapidRng;
use ;
let mut rng = seed_from_u64;
let x = rng.next_u64;
Or use the standalone function directly, threading the seed yourself:
use rapidrng;
let mut state: u64 = 42;
let x = rapidrng;
Features
- Default:
rand rand: implementsrand_core'sRng/SeedableRngand enablesRapidRng(rand 0.10).
License
Licensed under either of Apache-2.0 or MIT at your option.