From f17bff5490254ea871da75918c3928be7a3b41be Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 1 Feb 2021 16:25:31 -0800 Subject: [PATCH] fill in Deterministic impl of RngCore --- crates/wasi-common/src/random.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/wasi-common/src/random.rs b/crates/wasi-common/src/random.rs index 45e4cb0ea9..9e4711534c 100644 --- a/crates/wasi-common/src/random.rs +++ b/crates/wasi-common/src/random.rs @@ -15,10 +15,16 @@ impl Deterministic { impl RngCore for Deterministic { fn next_u32(&mut self) -> u32 { - todo!() + let b0 = self.cycle.next().expect("infinite sequence"); + let b1 = self.cycle.next().expect("infinite sequence"); + let b2 = self.cycle.next().expect("infinite sequence"); + let b3 = self.cycle.next().expect("infinite sequence"); + ((b0 as u32) << 24) + ((b1 as u32) << 16) + ((b2 as u32) << 8) + (b3 as u32) } fn next_u64(&mut self) -> u64 { - todo!() + let w0 = self.next_u32(); + let w1 = self.next_u32(); + ((w0 as u64) << 32) + (w1 as u64) } fn fill_bytes(&mut self, buf: &mut [u8]) { for b in buf.iter_mut() {