#random #rand #no-alloc

no-std rand_blake3

blake3类型的使用rand实现

8个版本 (3个稳定版本)

1.0.2 2023年11月17日
0.1.4 2023年11月17日

#89无标准库

每月下载量 30

MPL-2.0 许可证

12KB
181

rand-blake3

使用BLAKE3作为伪随机数生成器的RngCore实现。

示例

// 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();

依赖项

~1.5MB
~40K SLoC