Crates.io | rand_blake3 |
lib.rs | rand_blake3 |
version | 1.0.2 |
source | src |
created_at | 2023-11-17 20:17:49.672075 |
updated_at | 2023-11-17 22:08:46.736115 |
description | rand implementations for blake3 types |
homepage | |
repository | https://codeberg.org/Taywee/rand_blake3 |
max_upload_size | |
id | 1039468 |
size | 34,609 |
Implementation of RngCore using BLAKE3 as a PRNG.
// 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();