Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.20.0
- 1.22.0
- stable
- beta
- nightly
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ name = "quickcheck"
[dependencies]
env_logger = { version = "0.5", default-features = false, optional = true }
log = { version = "0.4", optional = true }
rand = "0.4"
rand = "0.5"
5 changes: 3 additions & 2 deletions benches/tuples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ extern crate rand;
extern crate test;

use quickcheck::{Arbitrary, StdGen};
use rand::isaac::IsaacRng;
use rand::prng::hc128::Hc128Rng;
use rand::SeedableRng;
use test::Bencher;

macro_rules! bench_shrink {
Expand All @@ -14,7 +15,7 @@ macro_rules! bench_shrink {
#[bench]
fn $fn_name(b: &mut Bencher) {
// Use a deterministic generator to benchmark on the same data
let mut gen = StdGen::new(IsaacRng::new_unseeded(), 100);
let mut gen = StdGen::new(Hc128Rng::from_seed([0u8; 32]), 100);
let value: $type = Arbitrary::arbitrary(&mut gen);

b.iter(|| {
Expand Down
15 changes: 9 additions & 6 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;

use rand::Rng;
use rand::{self, Rng, RngCore};

/// `Gen` wraps a `rand::Rng` with parameters to control the distribution of
/// `Gen` wraps a `rand::RngCore` with parameters to control the distribution of
/// random values.
///
/// A value with type satisfying the `Gen` trait can be constructed with the
/// `gen` function in this crate.
pub trait Gen : Rng {
pub trait Gen : RngCore {
fn size(&self) -> usize;
}

Expand All @@ -45,22 +45,25 @@ pub struct StdGen<R> {
/// The `size` parameter controls the size of random values generated.
/// For example, it specifies the maximum length of a randomly generated vector
/// and also will specify the maximum magnitude of a randomly generated number.
impl<R: Rng> StdGen<R> {
impl<R: RngCore> StdGen<R> {
pub fn new(rng: R, size: usize) -> StdGen<R> {
StdGen { rng: rng, size: size }
}
}

impl<R: Rng> Rng for StdGen<R> {
impl<R: RngCore> RngCore for StdGen<R> {
fn next_u32(&mut self) -> u32 { self.rng.next_u32() }

// some RNGs implement these more efficiently than the default, so
// we might as well defer to them.
fn next_u64(&mut self) -> u64 { self.rng.next_u64() }
fn fill_bytes(&mut self, dest: &mut [u8]) { self.rng.fill_bytes(dest) }
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
self.rng.try_fill_bytes(dest)
}
}

impl<R: Rng> Gen for StdGen<R> {
impl<R: RngCore> Gen for StdGen<R> {
fn size(&self) -> usize { self.size }
}

Expand Down