summaryrefslogtreecommitdiff
path: root/rand/rand_xoshiro/src
diff options
context:
space:
mode:
Diffstat (limited to 'rand/rand_xoshiro/src')
-rw-r--r--rand/rand_xoshiro/src/common.rs2
-rw-r--r--rand/rand_xoshiro/src/lib.rs18
-rw-r--r--rand/rand_xoshiro/src/splitmix64.rs7
-rw-r--r--rand/rand_xoshiro/src/xoroshiro128plus.rs8
-rw-r--r--rand/rand_xoshiro/src/xoroshiro128starstar.rs8
-rw-r--r--rand/rand_xoshiro/src/xoroshiro64star.rs13
-rw-r--r--rand/rand_xoshiro/src/xoroshiro64starstar.rs17
-rw-r--r--rand/rand_xoshiro/src/xoshiro128plus.rs8
-rw-r--r--rand/rand_xoshiro/src/xoshiro128starstar.rs8
-rw-r--r--rand/rand_xoshiro/src/xoshiro256plus.rs8
-rw-r--r--rand/rand_xoshiro/src/xoshiro256starstar.rs8
-rw-r--r--rand/rand_xoshiro/src/xoshiro512plus.rs10
-rw-r--r--rand/rand_xoshiro/src/xoshiro512starstar.rs10
13 files changed, 53 insertions, 72 deletions
diff --git a/rand/rand_xoshiro/src/common.rs b/rand/rand_xoshiro/src/common.rs
index 9ee09e2..b188dd6 100644
--- a/rand/rand_xoshiro/src/common.rs
+++ b/rand/rand_xoshiro/src/common.rs
@@ -9,7 +9,7 @@
/// Initialize a RNG from a `u64` seed using `SplitMix64`.
macro_rules! from_splitmix {
($seed:expr) => { {
- let mut rng = ::SplitMix64::seed_from_u64($seed);
+ let mut rng = crate::SplitMix64::seed_from_u64($seed);
Self::from_rng(&mut rng).unwrap()
} }
}
diff --git a/rand/rand_xoshiro/src/lib.rs b/rand/rand_xoshiro/src/lib.rs
index 634db31..3047e92 100644
--- a/rand/rand_xoshiro/src/lib.rs
+++ b/rand/rand_xoshiro/src/lib.rs
@@ -55,28 +55,15 @@
//!
//! [xoshiro]: http://xoshiro.di.unimi.it/
//! [low linear complexity]: http://xoshiro.di.unimi.it/lowcomp.php
-//! [`Xoshiro256StarStar`]: ./struct.Xoshiro256StarStar.html
-//! [`Xoshiro256Plus`]: ./struct.Xoshiro256Plus.html
-//! [`Xoroshiro128StarStar`]: ./struct.Xoroshiro128StarStar.html
-//! [`Xoroshiro128Plus`]: ./struct.Xoroshiro128Plus.html
-//! [`Xoshiro512StarStar`]: ./struct.Xoshiro512StarStar.html
-//! [`Xoshiro512Plus`]: ./struct.Xoshiro512Plus.html
-//! [`SplitMix64`]: ./struct.SplitMix64.html
-//! [`Xoshiro128StarStar`]: ./struct.Xoshiro128StarStar.html
-//! [`Xoshiro128Plus`]: ./struct.Xoshiro128Plus.html
-//! [`Xoroshiro64StarStar`]: ./struct.Xoroshiro64StarStar.html
-//! [`Xoroshiro64Star`]: ./struct.Xoroshiro64Star.html
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
- html_root_url = "https://docs.rs/rand_xoshiro/0.1.0")]
+ html_root_url = "https://docs.rs/rand_xoshiro/0.3.1")]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
-#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
+#![allow(clippy::unreadable_literal)]
#![no_std]
-extern crate byteorder;
-pub extern crate rand_core;
#[macro_use]
mod common;
@@ -92,6 +79,7 @@ mod xoroshiro128starstar;
mod xoroshiro64starstar;
mod xoroshiro64star;
+pub use rand_core;
pub use splitmix64::SplitMix64;
pub use xoshiro128starstar::Xoshiro128StarStar;
pub use xoshiro128plus::Xoshiro128Plus;
diff --git a/rand/rand_xoshiro/src/splitmix64.rs b/rand/rand_xoshiro/src/splitmix64.rs
index a7cac9f..3a41450 100644
--- a/rand/rand_xoshiro/src/splitmix64.rs
+++ b/rand/rand_xoshiro/src/splitmix64.rs
@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use byteorder::{ByteOrder, LittleEndian};
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::le::read_u64_into;
use rand_core::impls::fill_bytes_via_next;
use rand_core::{RngCore, SeedableRng, Error};
@@ -22,6 +22,7 @@ use rand_core::{RngCore, SeedableRng, Error};
/// from [`dsiutils`](http://dsiutils.di.unimi.it/) is used.
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct SplitMix64 {
x: u64,
}
@@ -77,9 +78,7 @@ impl SeedableRng for SplitMix64 {
/// Seed a `SplitMix64` from a `u64`.
fn seed_from_u64(seed: u64) -> SplitMix64 {
- let mut x = [0; 8];
- LittleEndian::write_u64(&mut x, seed);
- SplitMix64::from_seed(x)
+ SplitMix64::from_seed(seed.to_le_bytes())
}
}
diff --git a/rand/rand_xoshiro/src/xoroshiro128plus.rs b/rand/rand_xoshiro/src/xoroshiro128plus.rs
index df032c8..a7b4ebc 100644
--- a/rand/rand_xoshiro/src/xoroshiro128plus.rs
+++ b/rand/rand_xoshiro/src/xoroshiro128plus.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core;
use rand_core::le::read_u64_into;
use rand_core::impls::fill_bytes_via_next;
@@ -22,6 +23,7 @@ use rand_core::{RngCore, SeedableRng};
/// David Blackman and Sebastiano Vigna.
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoroshiro128Plus {
s0: u64,
s1: u64,
@@ -34,10 +36,7 @@ impl Xoroshiro128Plus {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoroshiro128Plus;
///
/// let rng1 = Xoroshiro128Plus::seed_from_u64(0);
@@ -45,7 +44,6 @@ impl Xoroshiro128Plus {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]);
diff --git a/rand/rand_xoshiro/src/xoroshiro128starstar.rs b/rand/rand_xoshiro/src/xoroshiro128starstar.rs
index 2d27850..21823f5 100644
--- a/rand/rand_xoshiro/src/xoroshiro128starstar.rs
+++ b/rand/rand_xoshiro/src/xoroshiro128starstar.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core;
use rand_core::le::read_u64_into;
use rand_core::impls::fill_bytes_via_next;
@@ -21,6 +22,7 @@ use rand_core::{RngCore, SeedableRng};
/// David Blackman and Sebastiano Vigna.
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoroshiro128StarStar {
s0: u64,
s1: u64,
@@ -33,10 +35,7 @@ impl Xoroshiro128StarStar {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoroshiro128StarStar;
///
/// let rng1 = Xoroshiro128StarStar::seed_from_u64(0);
@@ -44,7 +43,6 @@ impl Xoroshiro128StarStar {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]);
diff --git a/rand/rand_xoshiro/src/xoroshiro64star.rs b/rand/rand_xoshiro/src/xoroshiro64star.rs
index 86338fd..6bb708a 100644
--- a/rand/rand_xoshiro/src/xoroshiro64star.rs
+++ b/rand/rand_xoshiro/src/xoroshiro64star.rs
@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use byteorder::{ByteOrder, LittleEndian};
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core;
use rand_core::le::read_u32_into;
use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32};
@@ -23,6 +23,7 @@ use rand_core::{RngCore, SeedableRng};
/// David Blackman and Sebastiano Vigna.
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoroshiro64Star {
s0: u32,
s1: u32,
@@ -71,9 +72,7 @@ impl SeedableRng for Xoroshiro64Star {
/// Seed a `Xoroshiro64Star` from a `u64` using `SplitMix64`.
fn seed_from_u64(seed: u64) -> Xoroshiro64Star {
- let mut s = [0; 8];
- LittleEndian::write_u64(&mut s, seed);
- Xoroshiro64Star::from_seed(s)
+ from_splitmix!(seed)
}
}
@@ -94,4 +93,10 @@ mod tests {
assert_eq!(rng.next_u32(), e);
}
}
+
+ #[test]
+ fn zero_seed() {
+ let mut rng = Xoroshiro64Star::seed_from_u64(0);
+ assert_ne!(rng.next_u64(), 0);
+ }
}
diff --git a/rand/rand_xoshiro/src/xoroshiro64starstar.rs b/rand/rand_xoshiro/src/xoroshiro64starstar.rs
index a40baee..8e1aea1 100644
--- a/rand/rand_xoshiro/src/xoroshiro64starstar.rs
+++ b/rand/rand_xoshiro/src/xoroshiro64starstar.rs
@@ -6,13 +6,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use byteorder::{ByteOrder, LittleEndian};
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core;
use rand_core::le::read_u32_into;
use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32};
use rand_core::{RngCore, SeedableRng};
-/// A Xoroshiro64** random number generator.
+/// A xoroshiro64** random number generator.
///
/// The xoshiro64** algorithm is not suitable for cryptographic purposes, but
/// is very fast and has excellent statistical properties.
@@ -22,6 +22,7 @@ use rand_core::{RngCore, SeedableRng};
/// David Blackman and Sebastiano Vigna.
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoroshiro64StarStar {
s0: u32,
s1: u32,
@@ -68,11 +69,9 @@ impl SeedableRng for Xoroshiro64StarStar {
}
}
- /// Seed a `Xoroshiro64StarStar` from a `u64`.
+ /// Seed a `Xoroshiro64StarStar` from a `u64` using `SplitMix64`.
fn seed_from_u64(seed: u64) -> Xoroshiro64StarStar {
- let mut s = [0; 8];
- LittleEndian::write_u64(&mut s, seed);
- Xoroshiro64StarStar::from_seed(s)
+ from_splitmix!(seed)
}
}
@@ -93,4 +92,10 @@ mod tests {
assert_eq!(rng.next_u32(), e);
}
}
+
+ #[test]
+ fn zero_seed() {
+ let mut rng = Xoroshiro64StarStar::seed_from_u64(0);
+ assert_ne!(rng.next_u64(), 0);
+ }
}
diff --git a/rand/rand_xoshiro/src/xoshiro128plus.rs b/rand/rand_xoshiro/src/xoshiro128plus.rs
index b0c7cc7..7cbd612 100644
--- a/rand/rand_xoshiro/src/xoshiro128plus.rs
+++ b/rand/rand_xoshiro/src/xoshiro128plus.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::{next_u64_via_u32, fill_bytes_via_next};
use rand_core::le::read_u32_into;
use rand_core::{SeedableRng, RngCore, Error};
@@ -20,6 +21,7 @@ use rand_core::{SeedableRng, RngCore, Error};
/// reference source code](http://xoshiro.di.unimi.it/xoshiro128starstar.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro128Plus {
s: [u32; 4],
}
@@ -31,10 +33,7 @@ impl Xoshiro128Plus {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoroshiro128StarStar;
///
/// let rng1 = Xoroshiro128StarStar::seed_from_u64(0);
@@ -42,7 +41,6 @@ impl Xoshiro128Plus {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]);
diff --git a/rand/rand_xoshiro/src/xoshiro128starstar.rs b/rand/rand_xoshiro/src/xoshiro128starstar.rs
index 836864e..7af1e50 100644
--- a/rand/rand_xoshiro/src/xoshiro128starstar.rs
+++ b/rand/rand_xoshiro/src/xoshiro128starstar.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::{next_u64_via_u32, fill_bytes_via_next};
use rand_core::le::read_u32_into;
use rand_core::{SeedableRng, RngCore, Error};
@@ -19,6 +20,7 @@ use rand_core::{SeedableRng, RngCore, Error};
/// reference source code](http://xoshiro.di.unimi.it/xoshiro128starstar.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro128StarStar {
s: [u32; 4],
}
@@ -30,10 +32,7 @@ impl Xoshiro128StarStar {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoroshiro128StarStar;
///
/// let rng1 = Xoroshiro128StarStar::seed_from_u64(0);
@@ -41,7 +40,6 @@ impl Xoshiro128StarStar {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]);
diff --git a/rand/rand_xoshiro/src/xoshiro256plus.rs b/rand/rand_xoshiro/src/xoshiro256plus.rs
index 08da5a8..396f588 100644
--- a/rand/rand_xoshiro/src/xoshiro256plus.rs
+++ b/rand/rand_xoshiro/src/xoshiro256plus.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::fill_bytes_via_next;
use rand_core::le::read_u64_into;
use rand_core::{SeedableRng, RngCore, Error};
@@ -20,6 +21,7 @@ use rand_core::{SeedableRng, RngCore, Error};
/// reference source code](http://xoshiro.di.unimi.it/xoshiro256plus.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro256Plus {
s: [u64; 4],
}
@@ -31,10 +33,7 @@ impl Xoshiro256Plus {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoshiro256Plus;
///
/// let rng1 = Xoshiro256Plus::seed_from_u64(0);
@@ -42,7 +41,6 @@ impl Xoshiro256Plus {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [
diff --git a/rand/rand_xoshiro/src/xoshiro256starstar.rs b/rand/rand_xoshiro/src/xoshiro256starstar.rs
index fc0a208..2cc2029 100644
--- a/rand/rand_xoshiro/src/xoshiro256starstar.rs
+++ b/rand/rand_xoshiro/src/xoshiro256starstar.rs
@@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::fill_bytes_via_next;
use rand_core::le::read_u64_into;
use rand_core::{SeedableRng, RngCore, Error};
@@ -19,6 +20,7 @@ use rand_core::{SeedableRng, RngCore, Error};
/// reference source code](http://xoshiro.di.unimi.it/xoshiro256starstar.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro256StarStar {
s: [u64; 4],
}
@@ -30,10 +32,7 @@ impl Xoshiro256StarStar {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoshiro256StarStar;
///
/// let rng1 = Xoshiro256StarStar::seed_from_u64(0);
@@ -41,7 +40,6 @@ impl Xoshiro256StarStar {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [
diff --git a/rand/rand_xoshiro/src/xoshiro512plus.rs b/rand/rand_xoshiro/src/xoshiro512plus.rs
index fe982e4..4b589f2 100644
--- a/rand/rand_xoshiro/src/xoshiro512plus.rs
+++ b/rand/rand_xoshiro/src/xoshiro512plus.rs
@@ -6,11 +6,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::fill_bytes_via_next;
use rand_core::le::read_u64_into;
use rand_core::{SeedableRng, RngCore, Error};
-use Seed512;
+use crate::Seed512;
/// A xoshiro512+ random number generator.
///
@@ -22,6 +23,7 @@ use Seed512;
/// reference source code](http://xoshiro.di.unimi.it/xoshiro512plus.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro512Plus {
s: [u64; 8],
}
@@ -33,10 +35,7 @@ impl Xoshiro512Plus {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoshiro512Plus;
///
/// let rng1 = Xoshiro512Plus::seed_from_u64(0);
@@ -44,7 +43,6 @@ impl Xoshiro512Plus {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [
diff --git a/rand/rand_xoshiro/src/xoshiro512starstar.rs b/rand/rand_xoshiro/src/xoshiro512starstar.rs
index 1a33f0a..2db9ac1 100644
--- a/rand/rand_xoshiro/src/xoshiro512starstar.rs
+++ b/rand/rand_xoshiro/src/xoshiro512starstar.rs
@@ -6,11 +6,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use rand_core::impls::fill_bytes_via_next;
use rand_core::le::read_u64_into;
use rand_core::{SeedableRng, RngCore, Error};
-use Seed512;
+use crate::Seed512;
/// A xoshiro512** random number generator.
///
@@ -21,6 +22,7 @@ use Seed512;
/// reference source code](http://xoshiro.di.unimi.it/xoshiro512starstar.c) by
/// David Blackman and Sebastiano Vigna.
#[derive(Debug, Clone)]
+#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))]
pub struct Xoshiro512StarStar {
s: [u64; 8],
}
@@ -32,10 +34,7 @@ impl Xoshiro512StarStar {
/// parallel computations.
///
/// ```
- /// # extern crate rand;
- /// # extern crate rand_xoshiro;
- /// # fn main() {
- /// use rand::SeedableRng;
+ /// use rand_xoshiro::rand_core::SeedableRng;
/// use rand_xoshiro::Xoshiro512StarStar;
///
/// let rng1 = Xoshiro512StarStar::seed_from_u64(0);
@@ -43,7 +42,6 @@ impl Xoshiro512StarStar {
/// rng2.jump();
/// let mut rng3 = rng2.clone();
/// rng3.jump();
- /// # }
/// ```
pub fn jump(&mut self) {
impl_jump!(u64, self, [