rand_blake3

Crates.iorand_blake3
lib.rsrand_blake3
version1.0.2
sourcesrc
created_at2023-11-17 20:17:49.672075
updated_at2023-11-17 22:08:46.736115
descriptionrand implementations for blake3 types
homepage
repositoryhttps://codeberg.org/Taywee/rand_blake3
max_upload_size
id1039468
size34,609
Taylor C. Richberger (Taywee)

documentation

README

rand-blake3

Implementation of RngCore using BLAKE3 as a PRNG.

Example

// 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();
Commit count: 0

cargo fmt