From ad298b5e751a9354c8269e00e40cfdc4c7deb16b Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Wed, 14 Jun 2023 17:48:33 +0200 Subject: [PATCH] reto03 14062023 17:48 --- ejercicios/reto03/src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ejercicios/reto03/src/main.rs b/ejercicios/reto03/src/main.rs index 573f77d..d096d79 100644 --- a/ejercicios/reto03/src/main.rs +++ b/ejercicios/reto03/src/main.rs @@ -7,19 +7,25 @@ * - Con o sin símbolos. * (Pudiendo combinar todos estos parámetros entre ellos) */ -use rand::Rng; // 0.8.5 - // +use rand::Rng; + fn main() { - let mut ch: char = 'A'; + // configurar: + let veces = 13; + let letras_mayusculas = true; + let numeros = true; + let simbolos = true; - println!("ASCII value: {}", ch as u32); - - ch = '&'; - println!("ASCII value: {}", ch as u32); - - ch = 'X'; - println!("ASCII value: {}", ch as u32); - - let num: u8 = rand::thread_rng().gen_range(0..255); - println!("{}", num as char); + let mut caracteres = String::from_utf8((b'a'..=b'z').collect()).unwrap(); + if letras_mayusculas { + let vector_mayusculas = String::from_utf8((b'A'..=b'Z').collect()).unwrap(); + caracteres += vector_mayusculas.to_string().as_str(); + } + let mut texto: String = String::new(); + for _ in 0..veces { + let num: u8 = rand::thread_rng().gen_range(33..127); + let caracter = num as char; + texto += &caracter.to_string(); + } + println!("{}", texto.to_string()); }