Module rand_chacha
ChaCha-based cryptographically secure random number generators.
- Crate
::rand_chacha. - docs.rs
- crates.io
- GitHub
rand_chacha provides random number generators based on the ChaCha stream cipher.
These are cryptographically secure and portable --
given the same seed they produce identical output on all platforms.
Three variants are available, differing in the number of ChaCha rounds:
ChaCha20Rng-- 20 rounds, the standard choice for cryptographic security.ChaCha12Rng-- 12 rounds, a good default balancing security and speed.ChaCha8Rng-- 8 rounds, fastest but with a lower security margin.
If you neeed a specific, stable, secure random number generator pick ChaCha12 by default.
ChaCha20 is tha standard strength algorithm and considered secure.
ChaCha12 is weaker, but expert consensus is that it is also secure,
with no known attacks
(it is the the default algorithm of the rand crate's StdRng,
though its algorithm is not specified to be stable).
Example
use SeedableRng;
use Rng;
use ChaCha12Rng;
let mut rng = seed_from_u64;
let value: u32 = rng.random;
let in_range: f64 = rng.random_range;
let coin: bool = rng.random;
Type Aliases
- ChaChaCore ChaCha with 20 rounds, low-level interface
- ChaChaRng ChaCha with 20 rounds