diff --git a/Cargo.toml b/Cargo.toml index 97832b3..3c3f7b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -rand = "0.8.5" +rand = { version = "0.8.5", features = ["small_rng", "std_rng"] } diff --git a/maze.c b/maze.c index f763202..0868100 100644 --- a/maze.c +++ b/maze.c @@ -25,3 +25,4 @@ int main() { fwrite(buf, sizeof(char), BUF_SIZE, stdout); } } + diff --git a/src/main.rs b/src/main.rs index b261550..4f0519c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,19 @@ use std::io::{self, BufWriter, Write}; -use rand::Rng; +use rand::{rngs::SmallRng, Rng, SeedableRng}; fn main() { - let mut rng = rand::thread_rng(); let mut stdout = BufWriter::new(io::stdout().lock()); + let mut rng = SmallRng::from_entropy(); + let mut bits = [0u64; 8192]; loop { - let bits: u64 = rng.gen(); - for i in 0..64 { - let bit = (bits >> i) & 1; - // '/' - // 0101111 - // '\\' - // 1011100 - let c = if bit == 0 { '/' } else { '\\' }; - // let _ = write!(stdout, "{c}"); - let _ = stdout.write_all(&[c as u8]); + rng.fill(&mut bits[..]); + for bits in bits { + for i in 0..64 { + let bit = (bits >> i) & 1; + let c = if bit == 0 { b'/' } else { b'\\' }; + let _ = stdout.write_all(&[c]); + } } } }