Crate rand_blake3
source ·Expand description
rand types backed by a Blake3 hasher.
Examples
// Hash input and convert the output stream to an rng.
let mut hasher = blake3::Hasher::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
let mut rng: rand_blake3::Rng = hasher.into();
let output: u64 = rng.gen();
assert_eq!(output, 0xfb61f3c9e0fe9ac0u64);
// Alternately, seed it as a rand::SeedableRng.
let mut rng = rand_blake3::Rng::from_seed(*b"0123456789abcdefghijklmnopqrstuv");
let output: u64 = rng.gen();
assert_eq!(output, 0x9958c58595366357u64);
// In the real world, you will probably not use a static seed, but seed from
// OsRng or something of the sort.
let mut rng = rand_blake3::Rng::from_entropy();
let _output: u64 = rng.gen();
// You can also use this as a backing for a rand ReseedingRng
let mut reseeding = rand::rngs::adapter::ReseedingRng::new(
rand_blake3::UnbufferedRng::from_entropy(),
1024 * 256,
rand::rngs::OsRng,
);
let _output: u64 = reseeding.gen();
Structs
- The buffered Rng wrapper for
OutputReader
. Note that it has From impls forOutputReader
as well asHasher
, and also implementsSeedableRng
so you can seed it however you like. - The unbuffered counterpart to
Rng
.