Skip to content

Commit 60637c5

Browse files
bors[bot]Gelbpunktcuviper
authored
Merge #185
185: Bump rand to 0.8 r=cuviper a=Gelbpunkt This updates rand to 0.8, which is required when working with a 0.8 version in the package since the version needs to match for the trait. Co-authored-by: Jens Reidel <adrian@travitia.xyz> Co-authored-by: Josh Stone <cuviper@gmail.com>
2 parents a6e2c07 + 4247abe commit 60637c5

File tree

13 files changed

+68
-56
lines changed

13 files changed

+68
-56
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ jobs:
1414
matrix:
1515
rust: [
1616
1.31.0, # 2018!
17-
1.32.0, # rand
1817
1.34.0, # quickcheck, has_try_from
19-
1.36.0, # alloc
18+
1.36.0, # alloc, rand
2019
stable,
2120
beta,
2221
nightly

Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ categories = [ "algorithms", "data-structures", "science" ]
88
license = "MIT OR Apache-2.0"
99
name = "num-bigint"
1010
repository = "https://github.com/rust-num/num-bigint"
11-
version = "0.3.2"
11+
version = "0.4.0-pre"
12+
publish = false
1213
readme = "README.md"
1314
build = "build.rs"
1415
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
1516
edition = "2018"
1617

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

@@ -47,7 +52,7 @@ features = ["i128"]
4752

4853
[dependencies.rand]
4954
optional = true
50-
version = "0.7"
55+
version = "0.8"
5156
default-features = false
5257

5358
[dependencies.serde]
@@ -65,9 +70,5 @@ optional = true
6570
version = "0.4"
6671
default-features = false
6772

68-
[features]
69-
default = ["std"]
70-
std = ["num-integer/std", "num-traits/std"]
71-
7273
[build-dependencies]
7374
autocfg = "1"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ if your compiler is not new enough.
2929
feature is enabled. To enable it include rand as
3030

3131
```toml
32-
rand = "0.7"
32+
rand = "0.8"
3333
num-bigint = { version = "0.3", features = ["rand"] }
3434
```
3535

3636
Note that you must use the version of `rand` that `num-bigint` is compatible
37-
with: `0.7`.
37+
with: `0.8`.
3838

3939
## Releases
4040

benches/bigint.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ 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;
108
use std::mem::replace;
119
use test::Bencher;
1210

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)
19-
}
11+
mod rng;
12+
use rng::get_rng;
2013

2114
fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
2215
let mut rng = get_rng();

benches/gcd.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ 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;
119
use test::Bencher;
1210

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)
19-
}
11+
mod rng;
12+
use rng::get_rng;
2013

2114
fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {
2215
let mut rng = get_rng();

benches/rng/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use rand::RngCore;
2+
3+
pub(crate) fn get_rng() -> impl RngCore {
4+
XorShiftStar {
5+
a: 0x0123_4567_89AB_CDEF,
6+
}
7+
}
8+
9+
/// Simple `Rng` for benchmarking without additional dependencies
10+
struct XorShiftStar {
11+
a: u64,
12+
}
13+
14+
impl RngCore for XorShiftStar {
15+
fn next_u32(&mut self) -> u32 {
16+
self.next_u64() as u32
17+
}
18+
19+
fn next_u64(&mut self) -> u64 {
20+
// https://en.wikipedia.org/wiki/Xorshift#xorshift*
21+
self.a ^= self.a >> 12;
22+
self.a ^= self.a << 25;
23+
self.a ^= self.a >> 27;
24+
self.a.wrapping_mul(0x2545_F491_4F6C_DD1D)
25+
}
26+
27+
fn fill_bytes(&mut self, dest: &mut [u8]) {
28+
for chunk in dest.chunks_mut(8) {
29+
let bytes = self.next_u64().to_le_bytes();
30+
let slice = &bytes[..chunk.len()];
31+
chunk.copy_from_slice(slice)
32+
}
33+
}
34+
35+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
36+
Ok(self.fill_bytes(dest))
37+
}
38+
}

benches/roots.rs

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

66
use num_bigint::{BigUint, RandBigInt};
7-
use rand::rngs::StdRng;
8-
use rand::SeedableRng;
97
use test::Bencher;
108

9+
mod rng;
10+
use rng::get_rng;
11+
1112
// The `big64` cases demonstrate the speed of cases where the value
1213
// can be converted to a `u64` primitive for faster calculation.
1314
//
@@ -16,14 +17,6 @@ use test::Bencher;
1617
//
1718
// The `big2k` and `big4k` cases are too big for `f64`, and use a simpler guess.
1819

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)
25-
}
26-
2720
fn check(x: &BigUint, n: u32) {
2821
let root = x.nth_root(n);
2922
if n == 2 {

bors.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
status = [
22
"Test (1.31.0)",
3-
"Test (1.32.0)",
43
"Test (1.34.0)",
54
"Test (1.36.0)",
65
"Test (stable)",

ci/big_rand/Cargo.toml

Lines changed: 4 additions & 7 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_chacha = "0.2"
10-
rand_isaac = "0.2"
11-
rand_xorshift = "0.2"
9+
rand = "0.8"
10+
rand_chacha = "0.3"
11+
rand_isaac = "0.3"
12+
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.7"

ci/big_rand/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod torture;
1111
mod biguint {
1212
use num_bigint::{BigUint, RandBigInt, RandomBits};
1313
use num_traits::Zero;
14-
use rand::distributions::Uniform;
14+
use rand::distributions::{Distribution, Uniform};
1515
use rand::thread_rng;
1616
use rand::{Rng, SeedableRng};
1717

@@ -192,7 +192,7 @@ mod biguint {
192192

193193
let mut rng = thread_rng();
194194
let bit_range = Uniform::new(0, 2048);
195-
let sample_bits: Vec<_> = rng.sample_iter(&bit_range).take(100).collect();
195+
let sample_bits: Vec<_> = bit_range.sample_iter(&mut rng).take(100).collect();
196196
for bits in sample_bits {
197197
let x = rng.gen_biguint(bits);
198198
for n in 2..11 {

0 commit comments

Comments
 (0)