use fill and SmallRng

This commit is contained in:
mehbark 2024-12-13 12:33:48 -05:00
parent cdaa7bce4b
commit 0c58265685
3 changed files with 12 additions and 13 deletions

View file

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

1
maze.c
View file

@ -25,3 +25,4 @@ int main() {
fwrite(buf, sizeof(char), BUF_SIZE, stdout);
}
}

View file

@ -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]);
}
}
}
}