use rand::{random};
pub(crate) struct Randoms {
pub alpha: [char; 54],
pub num_max_index: usize,
pub char_min_index: usize,
pub char_max_index: usize,
pub upper_min_index: usize,
pub upper_max_index: usize,
pub lower_min_index: usize,
pub lower_max_index: usize,
}
impl Randoms {
pub fn new() -> Self {
let alpha = [
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z',
];
let num_max_index = 8;
let char_min_index = num_max_index;
let char_max_index = alpha.len();
let upper_min_index = char_min_index;
let upper_max_index = upper_min_index + 23;
let lower_min_index = upper_max_index;
let lower_max_index = char_max_index;
Self {
alpha,
num_max_index,
char_min_index,
char_max_index,
upper_min_index,
upper_max_index,
lower_min_index,
lower_max_index,
}
}
pub fn num_between(&mut self, min: i32, max: i32) -> i32 {
min + (random::<usize>() % (max - min) as usize) as i32
}
pub fn num(&mut self, num: usize) -> usize {
random::<usize>() % num
}
pub fn alpha(&mut self) -> char {
self.alpha[self.num(self.alpha.len())]
}
pub fn alpha_under(&mut self, num: usize) -> char {
self.alpha[self.num(num)]
}
pub fn alpha_between(&mut self, min: usize, max: usize) -> char {
self.alpha[self.num_between(min as i32, max as i32) as usize]
}
}