use fill and SmallRng
This commit is contained in:
parent
cdaa7bce4b
commit
0c58265685
3 changed files with 12 additions and 13 deletions
|
@ -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
1
maze.c
|
@ -25,3 +25,4 @@ int main() {
|
|||
fwrite(buf, sizeof(char), BUF_SIZE, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
src/main.rs
18
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();
|
||||
rng.fill(&mut bits[..]);
|
||||
for bits in bits {
|
||||
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]);
|
||||
let c = if bit == 0 { b'/' } else { b'\\' };
|
||||
let _ = stdout.write_all(&[c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue