Function etebase::utils::randombytes_deterministic
source · pub fn randombytes_deterministic(size: usize, seed: &[u8; 32]) -> Vec<u8> ⓘ
Expand description
Return a buffer filled with deterministically cryptographically random bytes
This function is similar to randombytes
but always returns the same data for the same seed.
Useful for testing purposes.
Arguments:
seed
- the seed to generate the random data fromsize
- the size of the returned buffer (in bytes)
Examples
use etebase::utils::randombytes_deterministic;
let seed = [42; 32];
// Equal seeds produce equal sequences, regardless of length
let a = randombytes_deterministic(10, &seed);
let b = randombytes_deterministic(5, &seed);
assert_eq!(a[..5], b);
// Different seeds produce different sequences
let c = randombytes_deterministic(10, &[0; 32]);
assert_ne!(a, c);
assert_eq!(c, &[5, 67, 208, 128, 105, 110, 24, 70, 104, 100]);