Skip to content

Upgrade rand to 0.9 #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
rust: [
1.60.0, # MSRV
1.63.0, # MSRV
stable,
beta,
nightly
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.60.0, stable]
rust: [1.63.0, stable]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.60.0, stable]
rust: [1.63.0, stable]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ categories = [ "algorithms", "data-structures", "science" ]
license = "MIT OR Apache-2.0"
name = "num-bigint"
repository = "https://github.com/rust-num/num-bigint"
version = "0.4.6"
version = "0.5.0-pre"
publish = false
readme = "README.md"
exclude = ["/ci/*", "/.github/*"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.63"

[features]
default = ["std"]
Expand Down Expand Up @@ -56,7 +57,7 @@ features = ["i128"]

[dependencies.rand]
optional = true
version = "0.8"
version = "0.9"
default-features = false

[dependencies.serde]
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![crate](https://img.shields.io/crates/v/num-bigint.svg)](https://crates.io/crates/num-bigint)
[![documentation](https://docs.rs/num-bigint/badge.svg)](https://docs.rs/num-bigint)
[![minimum rustc 1.60](https://img.shields.io/badge/rustc-1.60+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![minimum rustc 1.63](https://img.shields.io/badge/rustc-1.63+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![build status](https://github.com/rust-num/num-bigint/workflows/master/badge.svg)](https://github.com/rust-num/num-bigint/actions)

Big integer types for Rust, `BigInt` and `BigUint`.
Expand All @@ -13,7 +13,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
num-bigint = "0.4"
num-bigint = "0.5"
```

## Features
Expand All @@ -29,20 +29,20 @@ if your compiler is not new enough.
feature is enabled. To enable it include rand as

```toml
rand = "0.8"
num-bigint = { version = "0.4", features = ["rand"] }
rand = "0.9"
num-bigint = { version = "0.5", features = ["rand"] }
```

Note that you must use the version of `rand` that `num-bigint` is compatible
with: `0.8`.
with: `0.9`.

## Releases

Release notes are available in [RELEASES.md](RELEASES.md).

## Compatibility

The `num-bigint` crate is tested for rustc 1.60 and greater.
The `num-bigint` crate is tested for rustc 1.63 and greater.

## Alternatives

Expand All @@ -52,7 +52,7 @@ table offers a brief comparison to a few alternatives.

| Crate | License | Min rustc | Implementation | Features |
| :--------------- | :------------- | :-------- | :------------- | :------- |
| **`num-bigint`** | MIT/Apache-2.0 | 1.60 | pure rust | dynamic width, number theoretical functions |
| **`num-bigint`** | MIT/Apache-2.0 | 1.63 | pure rust | dynamic width, number theoretical functions |
| [`awint`] | MIT/Apache-2.0 | 1.66 | pure rust | fixed width, heap or stack, concatenation macros |
| [`bnum`] | MIT/Apache-2.0 | 1.65 | pure rust | fixed width, parity with Rust primitives including floats |
| [`crypto-bigint`] | MIT/Apache-2.0 | 1.73 | pure rust | fixed width, stack only |
Expand Down
36 changes: 18 additions & 18 deletions benches/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ use rng::get_rng;

fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
let mut rng = get_rng();
let x = rng.gen_bigint(xbits);
let y = rng.gen_bigint(ybits);
let x = rng.random_bigint(xbits);
let y = rng.random_bigint(ybits);

b.iter(|| &x * &y);
}

fn divide_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
let mut rng = get_rng();
let x = rng.gen_bigint(xbits);
let y = rng.gen_bigint(ybits);
let x = rng.random_bigint(xbits);
let y = rng.random_bigint(ybits);

b.iter(|| &x / &y);
}

fn remainder_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
let mut rng = get_rng();
let x = rng.gen_bigint(xbits);
let y = rng.gen_bigint(ybits);
let x = rng.random_bigint(xbits);
let y = rng.random_bigint(ybits);

b.iter(|| &x % &y);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ fn fib_to_string(b: &mut Bencher) {

fn to_str_radix_bench(b: &mut Bencher, radix: u32, bits: u64) {
let mut rng = get_rng();
let x = rng.gen_bigint(bits);
let x = rng.random_bigint(bits);
b.iter(|| x.to_str_radix(radix));
}

Expand Down Expand Up @@ -222,7 +222,7 @@ fn to_str_radix_36(b: &mut Bencher) {

fn from_str_radix_bench(b: &mut Bencher, radix: u32) {
let mut rng = get_rng();
let x = rng.gen_bigint(1009);
let x = rng.random_bigint(1009);
let s = x.to_str_radix(radix);
assert_eq!(x, BigInt::from_str_radix(&s, radix).unwrap());
b.iter(|| BigInt::from_str_radix(&s, radix));
Expand Down Expand Up @@ -256,7 +256,7 @@ fn from_str_radix_36(b: &mut Bencher) {
fn rand_bench(b: &mut Bencher, bits: u64) {
let mut rng = get_rng();

b.iter(|| rng.gen_bigint(bits));
b.iter(|| rng.random_bigint(bits));
}

#[bench]
Expand Down Expand Up @@ -327,7 +327,7 @@ fn shr(b: &mut Bencher) {
fn hash(b: &mut Bencher) {
use std::collections::HashSet;
let mut rng = get_rng();
let v: Vec<BigInt> = (1000..2000).map(|bits| rng.gen_bigint(bits)).collect();
let v: Vec<BigInt> = (1000..2000).map(|bits| rng.random_bigint(bits)).collect();
b.iter(|| {
let h: HashSet<&BigInt> = v.iter().collect();
assert_eq!(h.len(), v.len());
Expand Down Expand Up @@ -399,8 +399,8 @@ const RFC3526_2048BIT_MODP_GROUP: &str = "\
#[bench]
fn modpow(b: &mut Bencher) {
let mut rng = get_rng();
let base = rng.gen_biguint(2048);
let e = rng.gen_biguint(2048);
let base = rng.random_biguint(2048);
let e = rng.random_biguint(2048);
let m = BigUint::from_str_radix(RFC3526_2048BIT_MODP_GROUP, 16).unwrap();

b.iter(|| base.modpow(&e, &m));
Expand All @@ -409,8 +409,8 @@ fn modpow(b: &mut Bencher) {
#[bench]
fn modpow_even(b: &mut Bencher) {
let mut rng = get_rng();
let base = rng.gen_biguint(2048);
let e = rng.gen_biguint(2048);
let base = rng.random_biguint(2048);
let e = rng.random_biguint(2048);
// Make the modulus even, so monty (base-2^32) doesn't apply.
let m = BigUint::from_str_radix(RFC3526_2048BIT_MODP_GROUP, 16).unwrap() - 1u32;

Expand All @@ -420,31 +420,31 @@ fn modpow_even(b: &mut Bencher) {
#[bench]
fn to_u32_digits(b: &mut Bencher) {
let mut rng = get_rng();
let n = rng.gen_biguint(2048);
let n = rng.random_biguint(2048);

b.iter(|| n.to_u32_digits());
}

#[bench]
fn iter_u32_digits(b: &mut Bencher) {
let mut rng = get_rng();
let n = rng.gen_biguint(2048);
let n = rng.random_biguint(2048);

b.iter(|| n.iter_u32_digits().max());
}

#[bench]
fn to_u64_digits(b: &mut Bencher) {
let mut rng = get_rng();
let n = rng.gen_biguint(2048);
let n = rng.random_biguint(2048);

b.iter(|| n.to_u64_digits());
}

#[bench]
fn iter_u64_digits(b: &mut Bencher) {
let mut rng = get_rng();
let n = rng.gen_biguint(2048);
let n = rng.random_biguint(2048);

b.iter(|| n.iter_u64_digits().max());
}
4 changes: 2 additions & 2 deletions benches/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rng::get_rng;

fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {
let mut rng = get_rng();
let x = rng.gen_biguint(bits);
let y = rng.gen_biguint(bits);
let x = rng.random_biguint(bits);
let y = rng.random_biguint(bits);

assert_eq!(euclid(&x, &y), x.gcd(&y));

Expand Down
4 changes: 0 additions & 4 deletions benches/rng/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ impl RngCore for XorShiftStar {
chunk.copy_from_slice(slice)
}
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
Ok(self.fill_bytes(dest))
}
}
6 changes: 3 additions & 3 deletions benches/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn check(x: &BigUint, n: u32) {
}

fn bench_sqrt(b: &mut Bencher, bits: u64) {
let x = get_rng().gen_biguint(bits);
let x = get_rng().random_biguint(bits);
eprintln!("bench_sqrt({})", x);

check(&x, 2);
Expand Down Expand Up @@ -65,7 +65,7 @@ fn big4k_sqrt(b: &mut Bencher) {
}

fn bench_cbrt(b: &mut Bencher, bits: u64) {
let x = get_rng().gen_biguint(bits);
let x = get_rng().random_biguint(bits);
eprintln!("bench_cbrt({})", x);

check(&x, 3);
Expand Down Expand Up @@ -93,7 +93,7 @@ fn big4k_cbrt(b: &mut Bencher) {
}

fn bench_nth_root(b: &mut Bencher, bits: u64, n: u32) {
let x = get_rng().gen_biguint(bits);
let x = get_rng().random_biguint(bits);
eprintln!("bench_{}th_root({})", n, x);

check(&x, n);
Expand Down
8 changes: 4 additions & 4 deletions ci/big_rand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2018"

[dependencies]
num-traits = "0.2.11"
rand = "0.8"
rand_chacha = "0.3"
rand_isaac = "0.3"
rand_xorshift = "0.3"
rand = "0.9"
rand_chacha = "0.9"
rand_isaac = "0.4"
rand_xorshift = "0.4"

[dependencies.num-bigint]
features = ["rand"]
Expand Down
Loading