Skip to content

Commit 180417d

Browse files
committed
Update rand to 0.7
Fix some test code accordingly. Note, this includes fix for the test code of bitset-fixed. The test expected the number sequences generated from the same seed is always the same. It seems the rand 0.7 produces different sequence for the seed, so change the result value to fit for rand 0.7.
1 parent ceafaa6 commit 180417d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ im-rc = "=13.0.0"
6161
num = "=0.2.0"
6262

6363
# RNG 疑似乱数生成器 (randファミリー)
64-
rand = "=0.6.5"
65-
rand_chacha = "=0.1.1"
66-
rand_pcg = "=0.1.2"
64+
rand = { version = "=0.7.0", features = ["small_rng"] }
65+
rand_chacha = "=0.2.1"
66+
rand_pcg = "=0.2.0"
6767

6868
# 正規表現
6969
regex = "=1.2.1"

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn run_bitset_fixed() {
246246
use rand::distributions::Uniform;
247247
use rand::prelude::*;
248248

249-
let mut rng = StdRng::seed_from_u64(114514);
249+
let rng = StdRng::seed_from_u64(114514);
250250
let dist = Uniform::from(0..2000);
251251

252252
let n = rng
@@ -265,7 +265,7 @@ fn run_bitset_fixed() {
265265
let ans = ((sum + 1) / 2..).find(|&i| bitset[i]).unwrap();
266266

267267
println!("N = {:?}\nAnswer = {}", n, ans);
268-
assert_eq!(ans, 14675);
268+
assert_eq!(ans, 13465);
269269
}
270270

271271
#[test]
@@ -403,6 +403,8 @@ fn test_rand_family() -> UnitResult {
403403
}
404404

405405
fn calc_mean(rng: &mut impl rand::Rng) -> f64 {
406+
// to see `impl Rng for &mut R where R: Rng`, which prevent moving in `rng.sample_iter()`
407+
use rand::Rng as _;
406408
const ITERATIONS: usize = 10000;
407409

408410
// the stardard distribution for f64 generates a random rumber in interval [0, 1)

0 commit comments

Comments
 (0)