This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.

24 lines
485 B
Rust

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
/// Generate a random string of a given size
pub fn rand_str(len: usize) -> String {
thread_rng()
.sample_iter(&Alphanumeric)
.map(char::from)
.take(len)
.collect()
}
#[cfg(test)]
mod test {
use crate::utils::string_utils::rand_str;
#[test]
fn test_rand_str() {
let size = 10;
let rand = rand_str(size);
assert_eq!(size, rand.len());
}
}