From b9e4b1f3851bed9d8fce0bfb64f8748cb90eb3cd Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Thu, 22 Jun 2023 17:56:51 +0200 Subject: [PATCH] reto08 terminado --- ejercicios/reto08/Cargo.toml | 8 ++++++++ ejercicios/reto08/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 ejercicios/reto08/Cargo.toml create mode 100644 ejercicios/reto08/src/main.rs 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); +}