migrate rand
diff --git a/src/rngs/adapter/read.rs b/src/rngs/adapter/read.rs index a5b31cc..5b4e5f0 100644 --- a/src/rngs/adapter/read.rs +++ b/src/rngs/adapter/read.rs
@@ -56,6 +56,12 @@ } impl<R: Read> RngCore for ReadRng<R> { + fn next_bool(&mut self) -> bool { + let mut buf = [0; 1]; + self.fill_bytes(&mut buf); + (buf[0] & 1) == 1 + } + fn next_u32(&mut self) -> u32 { impls::next_u32_via_fill(self) }
diff --git a/src/rngs/adapter/reseeding.rs b/src/rngs/adapter/reseeding.rs index 1977cb3..6560233 100644 --- a/src/rngs/adapter/reseeding.rs +++ b/src/rngs/adapter/reseeding.rs
@@ -106,10 +106,14 @@ // implements RngCore, but we can't specify that because ReseedingCore is private impl<R, Rsdr: RngCore> RngCore for ReseedingRng<R, Rsdr> where - R: BlockRngCore<Item = u32> + SeedableRng, - <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>, + R: BlockRngCore + SeedableRng { #[inline(always)] + fn next_bool(&mut self) -> bool { + self.0.next_bool() + } + + #[inline(always)] fn next_u32(&mut self) -> u32 { self.0.next_u32() } @@ -161,7 +165,6 @@ R: BlockRngCore + SeedableRng, Rsdr: RngCore, { - type Item = <R as BlockRngCore>::Item; type Results = <R as BlockRngCore>::Results; fn generate(&mut self, results: &mut Self::Results) { @@ -172,7 +175,7 @@ // returning from a non-inlined function. return self.reseed_and_generate(results, global_fork_counter); } - let num_bytes = results.as_ref().len() * size_of::<Self::Item>(); + let num_bytes = results.as_ref().len(); self.bytes_until_reseed -= num_bytes as i64; self.inner.generate(results); } @@ -242,7 +245,7 @@ trace!("Reseeding RNG (periodic reseed)"); } - let num_bytes = results.as_ref().len() * size_of::<<R as BlockRngCore>::Item>(); + let num_bytes = results.as_ref().len(); if let Err(e) = self.reseed() { warn!("Reseeding RNG failed: {}", e);
diff --git a/src/rngs/mock.rs b/src/rngs/mock.rs index a1745a4..6f2ae50 100644 --- a/src/rngs/mock.rs +++ b/src/rngs/mock.rs
@@ -47,6 +47,11 @@ impl RngCore for StepRng { #[inline] + fn next_bool(&mut self) -> bool { + (self.next_u64() & 1) == 1 + } + + #[inline] fn next_u32(&mut self) -> u32 { self.next_u64() as u32 }
diff --git a/src/rngs/std.rs b/src/rngs/std.rs index a90d86f..803abac 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs
@@ -38,6 +38,11 @@ impl RngCore for StdRng { #[inline(always)] + fn next_bool(&mut self) -> bool { + self.0.next_bool() + } + + #[inline(always)] fn next_u32(&mut self) -> u32 { self.0.next_u32() }
diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index 3a216bc..f7b0cf2 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs
@@ -94,6 +94,11 @@ impl RngCore for ThreadRng { #[inline(always)] + fn next_bool(&mut self) -> bool { + unsafe { self.rng.as_mut().next_bool() } + } + + #[inline(always)] fn next_u32(&mut self) -> u32 { unsafe { self.rng.as_mut().next_u32() } }