use rand::prelude::SliceRandom;
use rand::Rng;
#[derive(PartialEq)]
enum SeparatorType {
Number,
Symbol,
}
pub fn make_separator(rng: &mut impl Rng, sep: &str) -> String {
match sep {
"_n" => get_random_number(rng),
"_s" => get_random_symbol(rng),
"_b" => get_random_number_or_symbol(rng),
_ => sep.to_string(),
}
}
fn get_random_number_or_symbol(rng: &mut impl Rng) -> String {
let separator_type_to_use: &SeparatorType = [SeparatorType::Number, SeparatorType::Symbol]
.choose(rng)
.unwrap();
if separator_type_to_use == &SeparatorType::Symbol {
get_random_symbol(rng)
} else {
get_random_number(rng)
}
}
fn get_random_symbol(rng: &mut impl Rng) -> String {
const CHARSET: &[u8] = b"!@#$%&*(){}[]\\:;'<>?,./_-+=";
let idx = rng.gen_range(0..CHARSET.len());
(CHARSET[idx] as char).to_string()
}
fn get_random_number(rng: &mut impl Rng) -> String {
rng.gen_range(0..=9).to_string()
}