Module rand_chacha

ChaCha-based cryptographically secure random number generators.


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:

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 rand::SeedableRng;
use rand::Rng;
use rand_chacha::ChaCha12Rng;

let mut rng = ChaCha12Rng::seed_from_u64(42);

let value: u32 = rng.random();
let in_range: f64 = rng.random_range(0.0..1.0);
let coin: bool = rng.random();

Type Aliases