Skip to content

Commit a87b4cc

Browse files
committed
Update rand_xoshiro
1 parent b441239 commit a87b4cc

17 files changed

+70
-90
lines changed

rand_xoshiro/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Changes
99
- Use Edition 2024 and MSRV 1.85 (#73)
10+
- Update to `rand_core` v0.10 (#82)
1011

1112
## [0.7.0] - 2025-01-27
1213
- Bump the MSRV to 1.63 (#58)

rand_xoshiro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ all-features = true
2020
serde = ["dep:serde"]
2121

2222
[dependencies]
23-
rand_core = "0.10.0-rc-2"
23+
rand_core = "0.10.0-rc-3"
2424
serde = { version = "1", features = ["derive"], optional=true }
2525

2626
[dev-dependencies]

rand_xoshiro/src/splitmix64.rs

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

9-
use rand_core::le::{fill_bytes_via_next, read_u64_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -54,7 +53,7 @@ impl RngCore for SplitMix64 {
5453

5554
#[inline]
5655
fn fill_bytes(&mut self, dest: &mut [u8]) {
57-
fill_bytes_via_next(self, dest);
56+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
5857
}
5958
}
6059

@@ -63,8 +62,7 @@ impl SeedableRng for SplitMix64 {
6362

6463
/// Create a new `SplitMix64`.
6564
fn from_seed(seed: [u8; 8]) -> SplitMix64 {
66-
let mut state = [0; 1];
67-
read_u64_into(&seed, &mut state);
65+
let state: [_; 1] = utils::read_words(&seed);
6866
SplitMix64 { x: state[0] }
6967
}
7068

rand_xoshiro/src/xoroshiro128plus.rs

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

9-
use rand_core::le::{fill_bytes_via_next, read_u64_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -75,7 +74,7 @@ impl RngCore for Xoroshiro128Plus {
7574

7675
#[inline]
7776
fn fill_bytes(&mut self, dest: &mut [u8]) {
78-
fill_bytes_via_next(self, dest);
77+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
7978
}
8079
}
8180
impl SeedableRng for Xoroshiro128Plus {
@@ -85,8 +84,7 @@ impl SeedableRng for Xoroshiro128Plus {
8584
/// mapped to a different seed.
8685
fn from_seed(seed: [u8; 16]) -> Xoroshiro128Plus {
8786
deal_with_zero_seed!(seed, Self, 16);
88-
let mut s = [0; 2];
89-
read_u64_into(&seed, &mut s);
87+
let s: [_; 2] = utils::read_words(&seed);
9088

9189
Xoroshiro128Plus { s0: s[0], s1: s[1] }
9290
}

rand_xoshiro/src/xoroshiro128plusplus.rs

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

9-
use rand_core::le::{fill_bytes_via_next, read_u64_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -72,7 +71,7 @@ impl RngCore for Xoroshiro128PlusPlus {
7271

7372
#[inline]
7473
fn fill_bytes(&mut self, dest: &mut [u8]) {
75-
fill_bytes_via_next(self, dest);
74+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
7675
}
7776
}
7877

@@ -83,8 +82,7 @@ impl SeedableRng for Xoroshiro128PlusPlus {
8382
/// mapped to a different seed.
8483
fn from_seed(seed: [u8; 16]) -> Xoroshiro128PlusPlus {
8584
deal_with_zero_seed!(seed, Self, 16);
86-
let mut s = [0; 2];
87-
read_u64_into(&seed, &mut s);
85+
let s: [_; 2] = utils::read_words(&seed);
8886

8987
Xoroshiro128PlusPlus { s0: s[0], s1: s[1] }
9088
}

rand_xoshiro/src/xoroshiro128starstar.rs

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

9-
use rand_core::le::{fill_bytes_via_next, read_u64_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -72,7 +71,7 @@ impl RngCore for Xoroshiro128StarStar {
7271

7372
#[inline]
7473
fn fill_bytes(&mut self, dest: &mut [u8]) {
75-
fill_bytes_via_next(self, dest);
74+
utils::fill_bytes_via_next_word(dest, || self.next_u64());
7675
}
7776
}
7877

@@ -83,8 +82,7 @@ impl SeedableRng for Xoroshiro128StarStar {
8382
/// mapped to a different seed.
8483
fn from_seed(seed: [u8; 16]) -> Xoroshiro128StarStar {
8584
deal_with_zero_seed!(seed, Self, 16);
86-
let mut s = [0; 2];
87-
read_u64_into(&seed, &mut s);
85+
let s: [_; 2] = utils::read_words(&seed);
8886

8987
Xoroshiro128StarStar { s0: s[0], s1: s[1] }
9088
}

rand_xoshiro/src/xoroshiro64star.rs

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

9-
use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -38,12 +37,12 @@ impl RngCore for Xoroshiro64Star {
3837

3938
#[inline]
4039
fn next_u64(&mut self) -> u64 {
41-
next_u64_via_u32(self)
40+
utils::next_u64_via_u32(self)
4241
}
4342

4443
#[inline]
4544
fn fill_bytes(&mut self, dest: &mut [u8]) {
46-
fill_bytes_via_next(self, dest);
45+
utils::fill_bytes_via_next_word(dest, || self.next_u32());
4746
}
4847
}
4948

@@ -54,8 +53,7 @@ impl SeedableRng for Xoroshiro64Star {
5453
/// mapped to a different seed.
5554
fn from_seed(seed: [u8; 8]) -> Xoroshiro64Star {
5655
deal_with_zero_seed!(seed, Self, 8);
57-
let mut s = [0; 2];
58-
read_u32_into(&seed, &mut s);
56+
let s: [_; 2] = utils::read_words(&seed);
5957

6058
Xoroshiro64Star { s0: s[0], s1: s[1] }
6159
}

rand_xoshiro/src/xoroshiro64starstar.rs

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

9-
use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -37,12 +36,12 @@ impl RngCore for Xoroshiro64StarStar {
3736

3837
#[inline]
3938
fn next_u64(&mut self) -> u64 {
40-
next_u64_via_u32(self)
39+
utils::next_u64_via_u32(self)
4140
}
4241

4342
#[inline]
4443
fn fill_bytes(&mut self, dest: &mut [u8]) {
45-
fill_bytes_via_next(self, dest);
44+
utils::fill_bytes_via_next_word(dest, || self.next_u32());
4645
}
4746
}
4847

@@ -53,8 +52,7 @@ impl SeedableRng for Xoroshiro64StarStar {
5352
/// mapped to a different seed.
5453
fn from_seed(seed: [u8; 8]) -> Xoroshiro64StarStar {
5554
deal_with_zero_seed!(seed, Self, 8);
56-
let mut s = [0; 2];
57-
read_u32_into(&seed, &mut s);
55+
let s: [_; 2] = utils::read_words(&seed);
5856

5957
Xoroshiro64StarStar { s0: s[0], s1: s[1] }
6058
}

rand_xoshiro/src/xoshiro128plus.rs

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

9-
use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -64,9 +63,9 @@ impl SeedableRng for Xoshiro128Plus {
6463
#[inline]
6564
fn from_seed(seed: [u8; 16]) -> Xoshiro128Plus {
6665
deal_with_zero_seed!(seed, Self, 16);
67-
let mut state = [0; 4];
68-
read_u32_into(&seed, &mut state);
69-
Xoshiro128Plus { s: state }
66+
Xoshiro128Plus {
67+
s: utils::read_words(&seed),
68+
}
7069
}
7170

7271
/// Seed a `Xoshiro128Plus` from a `u64` using `SplitMix64`.
@@ -85,12 +84,12 @@ impl RngCore for Xoshiro128Plus {
8584

8685
#[inline]
8786
fn next_u64(&mut self) -> u64 {
88-
next_u64_via_u32(self)
87+
utils::next_u64_via_u32(self)
8988
}
9089

9190
#[inline]
9291
fn fill_bytes(&mut self, dest: &mut [u8]) {
93-
fill_bytes_via_next(self, dest);
92+
utils::fill_bytes_via_next_word(dest, || self.next_u32());
9493
}
9594
}
9695

rand_xoshiro/src/xoshiro128plusplus.rs

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

9-
use rand_core::le::{fill_bytes_via_next, next_u64_via_u32, read_u32_into};
10-
use rand_core::{RngCore, SeedableRng};
9+
use rand_core::{RngCore, SeedableRng, utils};
1110
#[cfg(feature = "serde")]
1211
use serde::{Deserialize, Serialize};
1312

@@ -63,9 +62,9 @@ impl SeedableRng for Xoshiro128PlusPlus {
6362
#[inline]
6463
fn from_seed(seed: [u8; 16]) -> Xoshiro128PlusPlus {
6564
deal_with_zero_seed!(seed, Self, 16);
66-
let mut state = [0; 4];
67-
read_u32_into(&seed, &mut state);
68-
Xoshiro128PlusPlus { s: state }
65+
Xoshiro128PlusPlus {
66+
s: utils::read_words(&seed),
67+
}
6968
}
7069

7170
/// Seed a `Xoshiro128PlusPlus` from a `u64` using `SplitMix64`.
@@ -84,12 +83,12 @@ impl RngCore for Xoshiro128PlusPlus {
8483

8584
#[inline]
8685
fn next_u64(&mut self) -> u64 {
87-
next_u64_via_u32(self)
86+
utils::next_u64_via_u32(self)
8887
}
8988

9089
#[inline]
9190
fn fill_bytes(&mut self, dest: &mut [u8]) {
92-
fill_bytes_via_next(self, dest);
91+
utils::fill_bytes_via_next_word(dest, || self.next_u32());
9392
}
9493
}
9594

0 commit comments

Comments
 (0)