Skip to content

Commit

Permalink
Fixed clippy lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
astocko committed Feb 12, 2017
1 parent c3865a1 commit e4ffc81
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xorshift"
version = "0.1.2"
version = "0.1.3"
authors = ["Alexander Stocko <[email protected]>"]
license = "CC0-1.0"
readme = "README.md"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ fn main() {
// Generate 20 random u32s
let vals = rng.gen_iter::<u32>().take(20).collect::<Vec<u32>>();
println!("Xorshift1024* random u32: {:?}", vals);

// Generate 50 random u64s
let vals = rng.gen_iter::<u64>().take(50).collect::<Vec<u64>>();
println!("Xorshift1024* random u64: {:?}", vals);
}

```
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
//! // Generate 20 random u32s
//! let vals = rng.gen_iter::<u32>().take(20).collect::<Vec<u32>>();
//! println!("Xorshift1024* random u32: {:?}", vals);
//!
//! // Generate 50 random u64s
//! let vals = rng.gen_iter::<u64>().take(50).collect::<Vec<u64>>();
//! println!("Xorshift1024* random u64: {:?}", vals);
//! }
//!
//! ```
Expand Down
6 changes: 3 additions & 3 deletions src/splitmix64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// See <LICENSE or http:https://creativecommons.org/publicdomain/zero/1.0/>

//! The SplitMix64 random number generator.
//! The `SplitMix64` random number generator.

use std::num::Wrapping as w;
use rand::{Rand, Rng, SeedableRng};
Expand All @@ -16,10 +16,10 @@ use rand::{Rand, Rng, SeedableRng};
/// # Description
/// Quoted from [1].
///
/// This is a fixed-increment version of Java 8's SplittableRandom
/// This is a fixed-increment version of Java 8's `SplittableRandom`
/// generator [2] and [3].
///
/// It is a very fast generator passing BigCrush, and it can be useful if
/// It is a very fast generator passing `BigCrush`, and it can be useful if
/// for some reason you absolutely want 64 bits of state; otherwise, we
/// rather suggest to use a xoroshiro128+ (for moderately parallel
/// computations) or xorshift1024* (for massively parallel computations)
Expand Down
14 changes: 8 additions & 6 deletions src/xoroshiro128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//! The Xoroshiro128+ random number generator.

use std::num::Wrapping as w;

use rand::{Rand, Rng, SeedableRng};

use RngJump;

const STATE_SIZE: usize = 2;
Expand All @@ -20,11 +22,11 @@ const STATE_SIZE: usize = 2;
/// Quoted from [1].
///
/// This is the successor to xorshift128+. It is the fastest full-period
/// generator passing BigCrush without systematic failures, but due to the
/// generator passing `BigCrush` without systematic failures, but due to the
/// relatively short period it is acceptable only for applications with a
/// mild amount of parallelism; otherwise, use a xorshift1024* generator.
///
/// Beside passing BigCrush, this generator passes the PractRand test suite
/// Beside passing `BigCrush`, this generator passes the `PractRand` test suite
/// up to (and included) 16TB, with the exception of binary rank tests,
/// which fail due to the lowest bit being an LFSR; all other bits pass all
/// tests. We suggest to use a sign test to extract a random Boolean value.
Expand All @@ -42,7 +44,7 @@ const STATE_SIZE: usize = 2;
/// (http:https://xoroshiro.di.unimi.it/xoroshiro128plus.c)
///
/// # Parallelism
/// The RngJump implementation is equivalent to 2^64 calls to next_u64().
/// The `RngJump` implementation is equivalent to 2^64 calls to `next_u64`().
/// Used to generate 2^64 non-overlapping subsequences for parallel
/// computations.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -94,7 +96,7 @@ impl<'a> SeedableRng<&'a [u64]> for Xoroshiro128 {
impl Rand for Xoroshiro128 {
fn rand<R: Rng>(other: &mut R) -> Xoroshiro128 {
let mut key: [u64; STATE_SIZE] = [0; STATE_SIZE];
for word in key.iter_mut() {
for word in &mut key {
*word = other.gen();
}
SeedableRng::from_seed(&key[..])
Expand All @@ -107,9 +109,9 @@ impl RngJump for Xoroshiro128 {
let mut s0: u64 = 0;
let mut s1: u64 = 0;

for i in 0..JUMP.len() {
for i in &JUMP {
for b in 0..64 {
if (JUMP[i] & 1 << b) != 0 {
if (i & 1 << b) != 0 {
s0 ^= self.0[0];
s1 ^= self.0[1];
}
Expand Down
14 changes: 8 additions & 6 deletions src/xorshift1024.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

//! The Xorshift1024* random number generator.

#![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]

use std::num::Wrapping as w;

use rand::{Rand, Rng, SeedableRng};
Expand Down Expand Up @@ -36,7 +38,7 @@ const STATE_SIZE: usize = 16;
/// (http:https://xoroshiro.di.unimi.it/xorshift1024star.c)
///
/// # Parallelism
/// The RngJump implementation is equivalent to 2^512 calls to next_u64().
/// The `RngJump` implementation is equivalent to 2^512 calls to `next_u64`().
/// Used to generate 2^512 non-overlapping subsequences for parallel
/// computations.
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -108,7 +110,7 @@ impl<'a> SeedableRng<&'a [u64]> for Xorshift1024 {
impl Rand for Xorshift1024 {
fn rand<R: Rng>(other: &mut R) -> Xorshift1024 {
let mut key: [u64; STATE_SIZE] = [0; STATE_SIZE];
for word in key.iter_mut() {
for word in &mut key {
*word = other.gen();
}
SeedableRng::from_seed(&key[..])
Expand All @@ -119,11 +121,11 @@ impl RngJump for Xorshift1024 {
fn jump(&mut self, count: usize) {
for _ in 0..count {
let mut t: [u64; 16] = [0; 16];
for i in 0..JUMP.len() {
for i in &JUMP {
for b in 0..64 {
if (JUMP[i] & 1 << b) != 0 {
for j in 0..16 {
t[j] ^= self.state[(j + self.p) & 15];
if (i & 1 << b) != 0 {
for (j, t_elem) in t.iter_mut().enumerate().take(16) {
*t_elem ^= self.state[(j + self.p) & 15];
}
}
self.next_u64();
Expand Down
10 changes: 6 additions & 4 deletions src/xorshift128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//! The Xorshift128+ random number generator.

use std::num::Wrapping as w;

use rand::{Rand, Rng, SeedableRng};

use RngJump;

const STATE_SIZE: usize = 2;
Expand Down Expand Up @@ -39,7 +41,7 @@ const STATE_SIZE: usize = 2;
/// (http:https://xoroshiro.di.unimi.it/xorshift128plus.c)
///
/// # Parallelism
/// The RngJump implementation is equivalent to 2^64 calls to next_u64().
/// The `RngJump` implementation is equivalent to 2^64 calls to `next_u64`().
/// Used to generate 2^64 non-overlapping subsequences for parallel
/// computations.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -86,7 +88,7 @@ impl<'a> SeedableRng<&'a [u64]> for Xorshift128 {
impl Rand for Xorshift128 {
fn rand<R: Rng>(other: &mut R) -> Xorshift128 {
let mut key: [u64; STATE_SIZE] = [0; STATE_SIZE];
for word in key.iter_mut() {
for word in &mut key {
*word = other.gen();
}
SeedableRng::from_seed(&key[..])
Expand All @@ -102,9 +104,9 @@ impl RngJump for Xorshift128 {
let mut s0: u64 = 0;
let mut s1: u64 = 0;

for i in 0..JUMP.len() {
for i in &JUMP {
for b in 0..64 {
if (JUMP[i] & 1 << b) != 0 {
if (i & 1 << b) != 0 {
s0 ^= self.0[0];
s1 ^= self.0[1];
}
Expand Down

0 comments on commit e4ffc81

Please sign in to comment.