bee_block/rand/
bytes.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use rand::Rng;
5
6/// Generates a [`Vec`] of random bytes with a given length.
7pub fn rand_bytes(len: usize) -> Vec<u8> {
8    (0..len).map(|_| rand::random::<u8>()).collect()
9}
10
11/// Generates an array of random bytes of length N.
12pub fn rand_bytes_array<const N: usize>() -> [u8; N] {
13    rand::thread_rng().gen::<[u8; N]>()
14}