reto08 terminado
This commit is contained in:
33
ejercicios/reto08/src/main.rs
Normal file
33
ejercicios/reto08/src/main.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user