diff --git a/ejercicios/reto08/Cargo.toml b/ejercicios/reto08/Cargo.toml new file mode 100644 index 0000000..1cf3380 --- /dev/null +++ b/ejercicios/reto08/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "reto08" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/ejercicios/reto08/src/main.rs b/ejercicios/reto08/src/main.rs new file mode 100644 index 0000000..a9b711d --- /dev/null +++ b/ejercicios/reto08/src/main.rs @@ -0,0 +1,33 @@ +/* + * Crea un generador de números pseudoaleatorios entre 0 y 100. + * - No puedes usar ninguna función "random" (o semejante) del lenguaje de programación seleccionado. + * + * Es más complicado de lo que parece... + */ +use std::time::SystemTime; +use std::time::UNIX_EPOCH; + +fn seudorandom() -> u32 { + let mut now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos() + .to_string() + .chars() + .collect::() + .split("") + .collect::>()[10..13] + .join("") + .parse::() + .unwrap() as u32; + + while now > 100 { + now = now - 100; + } + now +} + +fn main() { + let numero = seudorandom(); + println!("El número es: {}", numero); +}