use rand::Rng;
use std::io;
fn main() {
println!("Enter the desired length of the random sequence:");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let length: usize = match input.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Invalid input. Please enter a valid number.");
return;
}
};
let random_sequence = generate_random_sequence(length);
println!("Random sequence: {}", random_sequence);
}
fn generate_random_sequence(length: usize) -> String {
let mut rng = rand::thread_rng();
// Define your character set
let characters: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
(0..length)
.map(|_| {
let index = rng.gen_range(0..characters.len());
characters[index] as char
})
.collect()
}