Skip to content

Commit 998d4cb

Browse files
committed
seed tests with u64 for platform consistency
1 parent 46aa212 commit 998d4cb

File tree

6 files changed

+23
-39
lines changed

6 files changed

+23
-39
lines changed

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ build = "build.rs"
1515
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
1616
edition = "2018"
1717

18+
[features]
19+
default = ["std"]
20+
std = ["num-integer/std", "num-traits/std"]
21+
1822
[package.metadata.docs.rs]
1923
features = ["std", "serde", "rand", "quickcheck", "arbitrary"]
2024

@@ -66,9 +70,8 @@ optional = true
6670
version = "0.4"
6771
default-features = false
6872

69-
[features]
70-
default = ["std"]
71-
std = ["num-integer/std", "num-traits/std"]
72-
7373
[build-dependencies]
7474
autocfg = "1"
75+
76+
[dev-dependencies]
77+
rand_xorshift = "0.3"

benches/bigint.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ extern crate test;
55

66
use num_bigint::{BigInt, BigUint, RandBigInt};
77
use num_traits::{FromPrimitive, Num, One, Zero};
8-
use rand::rngs::StdRng;
9-
use rand::SeedableRng;
8+
use rand::prelude::*;
9+
use rand_xorshift::XorShiftRng;
1010
use std::mem::replace;
1111
use test::Bencher;
1212

13-
fn get_rng() -> StdRng {
14-
let mut seed = [0; 32];
15-
for i in 1..32 {
16-
seed[usize::from(i)] = i;
17-
}
18-
SeedableRng::from_seed(seed)
13+
fn get_rng() -> impl Rng {
14+
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
1915
}
2016

2117
fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {

benches/gcd.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ extern crate test;
66
use num_bigint::{BigUint, RandBigInt};
77
use num_integer::Integer;
88
use num_traits::Zero;
9-
use rand::rngs::StdRng;
10-
use rand::SeedableRng;
9+
use rand::prelude::*;
10+
use rand_xorshift::XorShiftRng;
1111
use test::Bencher;
1212

13-
fn get_rng() -> StdRng {
14-
let mut seed = [0; 32];
15-
for i in 1..32 {
16-
seed[usize::from(i)] = i;
17-
}
18-
SeedableRng::from_seed(seed)
13+
fn get_rng() -> impl Rng {
14+
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
1915
}
2016

2117
fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {

benches/roots.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
extern crate test;
55

66
use num_bigint::{BigUint, RandBigInt};
7-
use rand::rngs::StdRng;
8-
use rand::SeedableRng;
7+
use rand::prelude::*;
8+
use rand_xorshift::XorShiftRng;
99
use test::Bencher;
1010

1111
// The `big64` cases demonstrate the speed of cases where the value
@@ -16,12 +16,8 @@ use test::Bencher;
1616
//
1717
// The `big2k` and `big4k` cases are too big for `f64`, and use a simpler guess.
1818

19-
fn get_rng() -> StdRng {
20-
let mut seed = [0; 32];
21-
for i in 1..32 {
22-
seed[usize::from(i)] = i;
23-
}
24-
SeedableRng::from_seed(seed)
19+
fn get_rng() -> impl Rng {
20+
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
2521
}
2622

2723
fn check(x: &BigUint, n: u32) {

ci/big_rand/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ edition = "2018"
66

77
[dependencies]
88
num-traits = "0.2.11"
9+
rand = "0.8"
910
rand_chacha = "0.3"
1011
rand_isaac = "0.3"
1112
rand_xorshift = "0.3"
1213

1314
[dependencies.num-bigint]
1415
features = ["rand"]
1516
path = "../.."
16-
17-
[dependencies.rand]
18-
features = ["small_rng"]
19-
version = "0.8"

ci/big_rand/src/torture.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
use num_bigint::RandBigInt;
22
use num_traits::Zero;
33
use rand::prelude::*;
4-
use rand::rngs::SmallRng;
4+
use rand_xorshift::XorShiftRng;
55

6-
fn get_rng() -> SmallRng {
7-
let seed = [
8-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
9-
26, 27, 28, 29, 30, 31, 32,
10-
];
11-
SmallRng::from_seed(seed)
6+
fn get_rng() -> impl Rng {
7+
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
128
}
139

1410
fn test_mul_divide_torture_count(count: usize) {

0 commit comments

Comments
 (0)