100-days-of-rust/Misc-Projects/password_generator/src/main.rs

19 lines
544 B
Rust
Raw Normal View History

2023-03-24 00:52:21 +00:00
use rand::Rng;
fn main() {
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789)(*&^%$#@!~";
const PASSWORD_LEN: usize = 30;
let mut rng = rand::thread_rng();
let password: String = (0..PASSWORD_LEN)
.map(|_| {
let idx = rng.gen_range(0..CHARSET.len());
CHARSET[idx] as char
})
.collect();
println!("The following password was generated:");
println!("{:?}", password);
}