Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port new SeedableRng trait #233

Merged
merged 8 commits into from
Jan 23, 2018
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 benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod distributions;

use std::mem::size_of;
use test::{black_box, Bencher};
use rand::{StdRng, Rng};
use rand::{StdRng, Rng, NewRng};

#[bench]
fn rand_f32(b: &mut Bencher) {
Expand Down
23 changes: 3 additions & 20 deletions benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,10 @@ const BYTES_LEN: usize = 1024;
use std::mem::size_of;
use test::{black_box, Bencher};

use rand::{Rng, StdRng, OsRng, JitterRng};
use rand::{Rng, NewRng, StdRng, OsRng, JitterRng};
use rand::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};

macro_rules! gen_bytes {
($fnn:ident, $gen:ident) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng: $gen = OsRng::new().unwrap().gen();
let mut buf = [0u8; BYTES_LEN];
b.iter(|| {
for _ in 0..RAND_BENCH_N {
rng.fill_bytes(&mut buf);
black_box(buf);
}
});
b.bytes = BYTES_LEN as u64 * RAND_BENCH_N;
}
}
}

macro_rules! gen_bytes_new {
($fnn:ident, $gen:ident) => {
#[bench]
fn $fnn(b: &mut Bencher) {
Expand All @@ -51,8 +34,8 @@ gen_bytes!(gen_bytes_hc128, Hc128Rng);
gen_bytes!(gen_bytes_isaac, IsaacRng);
gen_bytes!(gen_bytes_isaac64, Isaac64Rng);
gen_bytes!(gen_bytes_chacha, ChaChaRng);
gen_bytes_new!(gen_bytes_std, StdRng);
gen_bytes_new!(gen_bytes_os, OsRng);
gen_bytes!(gen_bytes_std, StdRng);
gen_bytes!(gen_bytes_os, OsRng);


macro_rules! gen_uint {
Expand Down
9 changes: 8 additions & 1 deletion src/jitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Non-physical true random number generator based on timing jitter.

use {Rng, impls};
use {Rng, Error, ErrorKind, impls};

use core::{fmt, mem, ptr};
#[cfg(feature="std")]
Expand Down Expand Up @@ -115,6 +115,13 @@ impl ::std::error::Error for TimerError {
}
}

impl From<TimerError> for Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Became necessary because of NewSeeded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like something I forgot.

fn from(err: TimerError) -> Error {
Error::with_cause(ErrorKind::Unavailable,
"timer jitter failed basic quality tests", err)
}
}

// Initialise to zero; must be positive
#[cfg(feature="std")]
static JITTER_ROUNDS: AtomicUsize = ATOMIC_USIZE_INIT;
Expand Down
Loading