reto08 terminado

This commit is contained in:
2023-06-22 17:56:51 +02:00
parent 7d9450217c
commit b9e4b1f385
2 changed files with 41 additions and 0 deletions

View File

@@ -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]

View File

@@ -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::<String>()
.split("")
.collect::<Vec<&str>>()[10..13]
.join("")
.parse::<u32>()
.unwrap() as u32;
while now > 100 {
now = now - 100;
}
now
}
fn main() {
let numero = seudorandom();
println!("El número es: {}", numero);
}