catsploit_lib/util/
gen.rs

1use rand::distributions::Alphanumeric;
2use rand::{thread_rng, Rng};
3
4pub fn random_alphanumeric(length: usize) -> String {
5    let random_alphanumeric: String = thread_rng()
6        .sample_iter(&Alphanumeric)
7        .take(length)
8        .map(char::from)
9        .collect();
10    random_alphanumeric
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn test_random_alphanumeric() {
19        let res = random_alphanumeric(6);
20        assert_eq!(res.len(), 6);
21        assert!(res.chars().all(char::is_alphanumeric));
22    }
23}