start rand utils suite

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-03 08:44:59 +00:00
parent 25c004f08c
commit 4f5c6de853
3 changed files with 28 additions and 12 deletions

View file

@ -1,15 +1,5 @@
use rand::prelude::*;
use crate::Result;
pub fn random_string(length: usize) -> String {
thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(length)
.map(char::from)
.collect()
}
/// Parses the bytes into a string.
#[inline]
pub fn string_from_bytes(bytes: &[u8]) -> Result<String> {