Skip to content

Commit

Permalink
Merge pull request #557 from vks/xorshift-crate
Browse files Browse the repository at this point in the history
Move `XorShiftRng` to its own crate
  • Loading branch information
dhardy authored Jul 24, 2018
2 parents 686ba14 + b846c30 commit f8fd39d
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ matrix:
# TODO: use --tests instead of --lib on more recent compiler
- cargo test --lib --no-default-features
- cargo test --package rand_core --no-default-features
- cargo test --package rand_isaac --features serde1
- cargo test --package rand_xorshift --features serde1
- cargo test --features serde1,log
- rust: stable
os: osx
install:
script:
- cargo test --tests --no-default-features
- cargo test --package rand_core --no-default-features
- cargo test --package rand_isaac --features serde1
- cargo test --package rand_xorshift --features serde1
- cargo test --features serde1,log
- rust: beta
install:
script:
- cargo test --tests --no-default-features
- cargo test --package rand_core --no-default-features
- cargo test --package rand_isaac --features serde1
- cargo test --package rand_xorshift --features serde1
- cargo test --features serde1,log
- rust: nightly
install:
Expand Down
14 changes: 4 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
i128_support = [] # enables i128 and u128 support
simd_support = [] # enables SIMD support
serde1 = ["serde", "serde_derive", "rand_core/serde1"] # enables serialization for PRNGs
serde1 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs

[workspace]
members = ["rand_core", "rand_isaac"]
members = ["rand_core", "rand_isaac", "rand_xorshift"]

[dependencies]
rand_core = { path = "rand_core", version = "0.2", default-features = false }
# only for deprecations and benches:
rand_isaac = { path = "rand_isaac", version = "0.1", default-features = false }
rand_isaac = { path = "rand_isaac", version = "0.1" }
rand_xorshift = { path = "rand_xorshift", version = "0.1" }
log = { version = "0.4", optional = true }
serde = { version = "1", optional = true }
serde_derive = { version = "1", optional = true }

[target.'cfg(unix)'.dependencies]
libc = { version = "0.2", optional = true }
Expand All @@ -54,10 +53,5 @@ fuchsia-zircon = { version = "0.3.2", optional = true }
stdweb = { version = "0.4", optional = true }
wasm-bindgen = { version = "0.2.12", optional = true }

[dev-dependencies]
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
bincode = "1.0"

[package.metadata.docs.rs]
all-features = true
14 changes: 7 additions & 7 deletions benches/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use std::mem::size_of;
use test::Bencher;

use rand::{Rng, FromEntropy};
use rand::prng::XorShiftRng;
use rand::rngs::SmallRng;
use rand::distributions::*;

macro_rules! distr_int {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();
let distr = $distr;

b.iter(|| {
Expand All @@ -38,7 +38,7 @@ macro_rules! distr_float {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();
let distr = $distr;

b.iter(|| {
Expand All @@ -58,7 +58,7 @@ macro_rules! distr {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();
let distr = $distr;

b.iter(|| {
Expand Down Expand Up @@ -126,7 +126,7 @@ macro_rules! gen_range_int {
($fnn:ident, $ty:ident, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();

b.iter(|| {
let mut high = $high;
Expand Down Expand Up @@ -155,7 +155,7 @@ macro_rules! gen_range_float {
($fnn:ident, $ty:ident, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();

b.iter(|| {
let mut high = $high;
Expand All @@ -179,7 +179,7 @@ gen_range_float!(gen_range_f64, f64, 123.456f64, 7890.12);

#[bench]
fn dist_iter(b: &mut Bencher) {
let mut rng = XorShiftRng::from_entropy();
let mut rng = SmallRng::from_entropy();
let distr = Normal::new(-2.71828, 3.14159);
let mut iter = distr.sample_iter(&mut rng);

Expand Down
4 changes: 3 additions & 1 deletion benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate test;
extern crate rand;
extern crate rand_isaac;
extern crate rand_xorshift;

const RAND_BENCH_N: u64 = 1000;
const BYTES_LEN: usize = 1024;
Expand All @@ -11,11 +12,12 @@ use std::mem::size_of;
use test::{black_box, Bencher};

use rand::prelude::*;
use rand::prng::{XorShiftRng, Hc128Rng, ChaChaRng};
use rand::prng::{Hc128Rng, ChaChaRng};
use rand::prng::hc128::Hc128Core;
use rand::rngs::adapter::ReseedingRng;
use rand::rngs::{OsRng, JitterRng, EntropyRng};
use rand_isaac::{IsaacRng, Isaac64Rng};
use rand_xorshift::XorShiftRng;

macro_rules! gen_bytes {
($fnn:ident, $gen:expr) => {
Expand Down
7 changes: 6 additions & 1 deletion rand_isaac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ travis-ci = { repository = "rust-lang-nursery/rand" }
appveyor = { repository = "alexcrichton/rand" }

[features]
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
serde1 = ["serde", "serde_derive", "rand_core/serde1"]

[dependencies]
rand_core = { path = "../rand_core", version = "0.2", default-features=false }
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }

[dev-dependencies]
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
bincode = "1"
2 changes: 1 addition & 1 deletion rand_isaac/src/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mod test {
}

#[test]
#[cfg(all(feature="serde1", feature="std"))]
#[cfg(feature="serde1")]
fn test_isaac_serde() {
use bincode;
use std::io::{BufWriter, BufReader};
Expand Down
2 changes: 1 addition & 1 deletion rand_isaac/src/isaac64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ mod test {
}

#[test]
#[cfg(all(feature="serde1", feature="std"))]
#[cfg(feature="serde1")]
fn test_isaac64_serde() {
use bincode;
use std::io::{BufWriter, BufReader};
Expand Down
7 changes: 5 additions & 2 deletions rand_isaac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
#![deny(missing_debug_implementations)]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]

#![no_std]
#![cfg_attr(not(all(feature="serde1", test)), no_std)]

extern crate rand_core;

#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode;
#[cfg(feature="serde1")] extern crate serde;
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;

// To test serialization we need bincode and the standard library
#[cfg(all(feature="serde1", test))] extern crate bincode;
#[cfg(all(feature="serde1", test))] extern crate std as core;

pub mod isaac;
pub mod isaac64;

Expand Down
8 changes: 8 additions & 0 deletions rand_xorshift/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2018-07-16
- Initial release
31 changes: 31 additions & 0 deletions rand_xorshift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "rand_xorshift"
version = "0.1.0" # NB: When modifying, also modify html_root_url in lib.rs
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rand"
documentation = "https://docs.rs/rand_isaac"
homepage = "https://crates.io/crates/rand_isaac"
description = """
Xorshift random number generator
"""
keywords = ["random", "rng", "xorshift"]
categories = ["algorithms", "no-std"]

[badges]
travis-ci = { repository = "rust-lang-nursery/rand" }
appveyor = { repository = "alexcrichton/rand" }

[features]
serde1 = ["serde", "serde_derive"]

[dependencies]
rand_core = { path = "../rand_core", version = "0.2", default-features=false }
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }

[dev-dependencies]
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
bincode = "1"
Loading

0 comments on commit f8fd39d

Please sign in to comment.