Skip to content

Commit

Permalink
Merge pull request #823 from dhardy/master
Browse files Browse the repository at this point in the history
Bump versions + Edition 2018 + Pcg64
  • Loading branch information
dhardy committed Jun 12, 2019
2 parents db60b35 + 7690c21 commit 5610bda
Show file tree
Hide file tree
Showing 44 changed files with 356 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -268,7 +268,7 @@ before_install:

script:
- cargo test --tests --no-default-features
- cargo test --no-default-features --features getrandom
- cargo test --tests --no-default-features --features getrandom
# TODO: add simd_support feature:
- cargo test --features=serde1,log
- cargo test --examples
Expand Down
40 changes: 8 additions & 32 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rand"
version = "0.7.0-pre.0"
version = "0.7.0-pre.1"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand Down Expand Up @@ -55,7 +55,7 @@ members = [

[dependencies]
rand_core = { path = "rand_core", version = "0.5" }
rand_pcg = { path = "rand_pcg", version = "0.1", optional = true }
rand_pcg = { path = "rand_pcg", version = "0.2", optional = true }
# Do not depend on 'getrandom_package' directly; use the 'getrandom' feature!
getrandom_package = { version = "0.1.1", package = "getrandom", optional = true }
log = { version = "0.4", optional = true }
Expand All @@ -76,42 +76,18 @@ libc = { version = "0.2.22", default-features = false }
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
rand_chacha = { path = "rand_chacha", version = "0.2" }
[target.'cfg(target_os = "emscripten")'.dependencies]
rand_hc = { path = "rand_hc", version = "0.1" }
rand_hc = { path = "rand_hc", version = "0.2" }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "0.1" }
rand_pcg = { path = "rand_pcg", version = "0.2" }
# Only for benches:
rand_hc = { path = "rand_hc", version = "0.1" }
rand_xoshiro = { path = "rand_xoshiro", version = "0.2" }
rand_isaac = { path = "rand_isaac", version = "0.1" }
rand_xorshift = { path = "rand_xorshift", version = "0.1" }
rand_distr = { path = "rand_distr", version = "0.2" }
rand_hc = { path = "rand_hc", version = "0.2" }
rand_xoshiro = { path = "rand_xoshiro", version = "0.3" }
rand_isaac = { path = "rand_isaac", version = "0.2" }
rand_xorshift = { path = "rand_xorshift", version = "0.2" }

[build-dependencies]
autocfg = "0.1"

[[bench]]
name = "distributions"
path = "benches/distributions.rs"
required-features = ["small_rng"]

[[bench]]
name = "generators"
path = "benches/generators.rs"
required-features = ["small_rng"]

[[bench]]
name = "misc"
path = "benches/misc.rs"
required-features = ["small_rng"]

[[bench]]
name = "seq"
path = "benches/seq.rs"
required-features = ["small_rng"]

[package.metadata.docs.rs]
all-features = true

[patch.crates-io]
rand_core = { path = "rand_core", version = "0.5" }
25 changes: 16 additions & 9 deletions benches/generators.rs
Expand Up @@ -30,7 +30,7 @@ use rand::rngs::OsRng;
use rand_isaac::{IsaacRng, Isaac64Rng};
use rand_chacha::{ChaCha20Core, ChaCha8Rng, ChaCha12Rng, ChaCha20Rng};
use rand_hc::{Hc128Rng};
use rand_pcg::{Lcg64Xsh32, Mcg128Xsl64};
use rand_pcg::{Pcg32, Pcg64, Pcg64Mcg};
use rand_xorshift::XorShiftRng;
use rand_xoshiro::{Xoshiro256StarStar, Xoshiro256Plus, Xoshiro128StarStar,
Xoshiro128Plus, Xoroshiro128StarStar, Xoroshiro128Plus, SplitMix64,
Expand Down Expand Up @@ -63,15 +63,17 @@ gen_bytes!(gen_bytes_xoroshiro128plus, Xoroshiro128Plus::from_entropy());
gen_bytes!(gen_bytes_xoroshiro64starstar, Xoroshiro64StarStar::from_entropy());
gen_bytes!(gen_bytes_xoroshiro64star, Xoroshiro64Star::from_entropy());
gen_bytes!(gen_bytes_splitmix64, SplitMix64::from_entropy());
gen_bytes!(gen_bytes_lcg64_xsh32, Lcg64Xsh32::from_entropy());
gen_bytes!(gen_bytes_mcg128_xsh64, Mcg128Xsl64::from_entropy());
gen_bytes!(gen_bytes_pcg32, Pcg32::from_entropy());
gen_bytes!(gen_bytes_pcg64, Pcg64::from_entropy());
gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_entropy());
gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_entropy());
gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_entropy());
gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_entropy());
gen_bytes!(gen_bytes_hc128, Hc128Rng::from_entropy());
gen_bytes!(gen_bytes_isaac, IsaacRng::from_entropy());
gen_bytes!(gen_bytes_isaac64, Isaac64Rng::from_entropy());
gen_bytes!(gen_bytes_std, StdRng::from_entropy());
#[cfg(feature="small_rng")]
gen_bytes!(gen_bytes_small, SmallRng::from_entropy());
gen_bytes!(gen_bytes_os, OsRng);

Expand Down Expand Up @@ -102,15 +104,17 @@ gen_uint!(gen_u32_xoroshiro128plus, u32, Xoroshiro128Plus::from_entropy());
gen_uint!(gen_u32_xoroshiro64starstar, u32, Xoroshiro64StarStar::from_entropy());
gen_uint!(gen_u32_xoroshiro64star, u32, Xoroshiro64Star::from_entropy());
gen_uint!(gen_u32_splitmix64, u32, SplitMix64::from_entropy());
gen_uint!(gen_u32_lcg64_xsh32, u32, Lcg64Xsh32::from_entropy());
gen_uint!(gen_u32_mcg128_xsh64, u32, Mcg128Xsl64::from_entropy());
gen_uint!(gen_u32_pcg32, u32, Pcg32::from_entropy());
gen_uint!(gen_u32_pcg64, u32, Pcg64::from_entropy());
gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_entropy());
gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_entropy());
gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_entropy());
gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_entropy());
gen_uint!(gen_u32_hc128, u32, Hc128Rng::from_entropy());
gen_uint!(gen_u32_isaac, u32, IsaacRng::from_entropy());
gen_uint!(gen_u32_isaac64, u32, Isaac64Rng::from_entropy());
gen_uint!(gen_u32_std, u32, StdRng::from_entropy());
#[cfg(feature="small_rng")]
gen_uint!(gen_u32_small, u32, SmallRng::from_entropy());
gen_uint!(gen_u32_os, u32, OsRng);

Expand All @@ -124,15 +128,17 @@ gen_uint!(gen_u64_xoroshiro128plus, u64, Xoroshiro128Plus::from_entropy());
gen_uint!(gen_u64_xoroshiro64starstar, u64, Xoroshiro64StarStar::from_entropy());
gen_uint!(gen_u64_xoroshiro64star, u64, Xoroshiro64Star::from_entropy());
gen_uint!(gen_u64_splitmix64, u64, SplitMix64::from_entropy());
gen_uint!(gen_u64_lcg64_xsh32, u64, Lcg64Xsh32::from_entropy());
gen_uint!(gen_u64_mcg128_xsh64, u64, Mcg128Xsl64::from_entropy());
gen_uint!(gen_u64_pcg32, u64, Pcg32::from_entropy());
gen_uint!(gen_u64_pcg64, u64, Pcg64::from_entropy());
gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_entropy());
gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_entropy());
gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_entropy());
gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_entropy());
gen_uint!(gen_u64_hc128, u64, Hc128Rng::from_entropy());
gen_uint!(gen_u64_isaac, u64, IsaacRng::from_entropy());
gen_uint!(gen_u64_isaac64, u64, Isaac64Rng::from_entropy());
gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
#[cfg(feature="small_rng")]
gen_uint!(gen_u64_small, u64, SmallRng::from_entropy());
gen_uint!(gen_u64_os, u64, OsRng);

Expand All @@ -159,8 +165,9 @@ init_gen!(init_xoroshiro128plus, Xoroshiro128Plus);
init_gen!(init_xoroshiro64starstar, Xoroshiro64StarStar);
init_gen!(init_xoroshiro64star, Xoroshiro64Star);
init_gen!(init_splitmix64, SplitMix64);
init_gen!(init_lcg64_xsh32, Lcg64Xsh32);
init_gen!(init_mcg128_xsh64, Mcg128Xsl64);
init_gen!(init_pcg32, Pcg32);
init_gen!(init_pcg64, Pcg64);
init_gen!(init_pcg64mcg, Pcg64Mcg);
init_gen!(init_hc128, Hc128Rng);
init_gen!(init_isaac, IsaacRng);
init_gen!(init_isaac64, Isaac64Rng);
Expand Down
22 changes: 12 additions & 10 deletions benches/misc.rs
Expand Up @@ -10,17 +10,19 @@

extern crate test;
extern crate rand;
extern crate rand_pcg;

const RAND_BENCH_N: u64 = 1000;

use test::Bencher;

use rand::prelude::*;
use rand::distributions::{Distribution, Standard, Bernoulli};
use rand_pcg::{Pcg32, Pcg64Mcg};

#[bench]
fn misc_gen_bool_const(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for _ in 0..::RAND_BENCH_N {
Expand All @@ -32,7 +34,7 @@ fn misc_gen_bool_const(b: &mut Bencher) {

#[bench]
fn misc_gen_bool_var(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
Expand All @@ -46,7 +48,7 @@ fn misc_gen_bool_var(b: &mut Bencher) {

#[bench]
fn misc_gen_ratio_const(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for _ in 0..::RAND_BENCH_N {
Expand All @@ -58,7 +60,7 @@ fn misc_gen_ratio_const(b: &mut Bencher) {

#[bench]
fn misc_gen_ratio_var(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for i in 2..(::RAND_BENCH_N as u32 + 2) {
Expand All @@ -70,7 +72,7 @@ fn misc_gen_ratio_var(b: &mut Bencher) {

#[bench]
fn misc_bernoulli_const(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let d = rand::distributions::Bernoulli::new(0.18).unwrap();
let mut accum = true;
Expand All @@ -83,7 +85,7 @@ fn misc_bernoulli_const(b: &mut Bencher) {

#[bench]
fn misc_bernoulli_var(b: &mut Bencher) {
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
Expand All @@ -99,7 +101,7 @@ fn misc_bernoulli_var(b: &mut Bencher) {
#[bench]
fn gen_1k_iter_repeat(b: &mut Bencher) {
use std::iter;
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let v: Vec<u64> = iter::repeat(()).map(|()| rng.gen()).take(128).collect();
v
Expand All @@ -109,7 +111,7 @@ fn gen_1k_iter_repeat(b: &mut Bencher) {

#[bench]
fn gen_1k_sample_iter(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let v: Vec<u64> = Standard.sample_iter(&mut rng).take(128).collect();
v
Expand All @@ -119,7 +121,7 @@ fn gen_1k_sample_iter(b: &mut Bencher) {

#[bench]
fn gen_1k_gen_array(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
// max supported array length is 32!
let v: [[u64; 32]; 4] = rng.gen();
Expand All @@ -130,7 +132,7 @@ fn gen_1k_gen_array(b: &mut Bencher) {

#[bench]
fn gen_1k_fill(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
let mut buf = [0u64; 128];
b.iter(|| {
rng.fill(&mut buf[..]);
Expand Down
5 changes: 5 additions & 0 deletions benches/seq.rs
Expand Up @@ -11,13 +11,18 @@

extern crate test;
extern crate rand;
extern crate rand_pcg;

use test::Bencher;

use rand::prelude::*;
use rand::seq::*;
use std::mem::size_of;

// We force use of 32-bit RNG since seq code is optimised for use with 32-bit
// generators on all platforms.
use rand_pcg::Pcg32 as SmallRng;

const RAND_BENCH_N: u64 = 1000;

#[bench]
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/Cargo.toml
Expand Up @@ -22,6 +22,6 @@ appveyor = { repository = "rust-random/rand" }
rand = { path = "..", version = ">=0.5, <=0.7.0-pre.9" }

[dev-dependencies]
rand_pcg = { version = "0.1", path = "../rand_pcg" }
rand_pcg = { version = "0.2", path = "../rand_pcg" }
# Histogram implementation for testing uniformity
average = "0.9.2"

0 comments on commit 5610bda

Please sign in to comment.