Skip to content

Commit 01343e1

Browse files
authored
Merge pull request #791 from vks/zero-seed
Use SplitMix to seed 64-bit generators
2 parents 65b8198 + faf4fec commit 01343e1

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

rand_xoshiro/src/xoroshiro64star.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use byteorder::{ByteOrder, LittleEndian};
109
use rand_core;
1110
use rand_core::le::read_u32_into;
1211
use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32};
@@ -71,9 +70,7 @@ impl SeedableRng for Xoroshiro64Star {
7170

7271
/// Seed a `Xoroshiro64Star` from a `u64` using `SplitMix64`.
7372
fn seed_from_u64(seed: u64) -> Xoroshiro64Star {
74-
let mut s = [0; 8];
75-
LittleEndian::write_u64(&mut s, seed);
76-
Xoroshiro64Star::from_seed(s)
73+
from_splitmix!(seed)
7774
}
7875
}
7976

@@ -94,4 +91,10 @@ mod tests {
9491
assert_eq!(rng.next_u32(), e);
9592
}
9693
}
94+
95+
#[test]
96+
fn zero_seed() {
97+
let mut rng = Xoroshiro64Star::seed_from_u64(0);
98+
assert_ne!(rng.next_u64(), 0);
99+
}
97100
}

rand_xoshiro/src/xoroshiro64starstar.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use byteorder::{ByteOrder, LittleEndian};
109
use rand_core;
1110
use rand_core::le::read_u32_into;
1211
use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32};
@@ -68,11 +67,9 @@ impl SeedableRng for Xoroshiro64StarStar {
6867
}
6968
}
7069

71-
/// Seed a `Xoroshiro64StarStar` from a `u64`.
70+
/// Seed a `Xoroshiro64StarStar` from a `u64` using `SplitMix64`.
7271
fn seed_from_u64(seed: u64) -> Xoroshiro64StarStar {
73-
let mut s = [0; 8];
74-
LittleEndian::write_u64(&mut s, seed);
75-
Xoroshiro64StarStar::from_seed(s)
72+
from_splitmix!(seed)
7673
}
7774
}
7875

@@ -93,4 +90,10 @@ mod tests {
9390
assert_eq!(rng.next_u32(), e);
9491
}
9592
}
93+
94+
#[test]
95+
fn zero_seed() {
96+
let mut rng = Xoroshiro64StarStar::seed_from_u64(0);
97+
assert_ne!(rng.next_u64(), 0);
98+
}
9699
}

0 commit comments

Comments
 (0)