feat(deps): upgrade to rand@0.6
This commit is contained in:
parent
80ffd7c027
commit
ca8c31e097
11
Cargo.toml
11
Cargo.toml
@ -21,6 +21,8 @@ harness = false
|
||||
name = "bench_main"
|
||||
required-features = ["prime"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dependencies.smallvec]
|
||||
version = "0.6.7"
|
||||
default-features = false
|
||||
@ -37,10 +39,9 @@ default-features = false
|
||||
version = "0.1.37"
|
||||
default-features = false
|
||||
|
||||
|
||||
[dependencies.rand]
|
||||
optional = true
|
||||
version = "0.5"
|
||||
version = "0.6"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
||||
@ -63,6 +64,8 @@ version = "1.2.7"
|
||||
[dev-dependencies]
|
||||
criterion = "0.2"
|
||||
rand_chacha = "0.1"
|
||||
rand_xorshift = "0.1"
|
||||
rand_isaac = "0.1"
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
@ -70,7 +73,7 @@ version = "1.0"
|
||||
[features]
|
||||
default = ["std", "i128", "u64_digit"]
|
||||
i128 = ["num-integer/i128", "num-traits/i128"]
|
||||
std = ["num-integer/std", "num-traits/std", "smallvec/std"]
|
||||
std = ["num-integer/std", "num-traits/std", "smallvec/std", "rand/std"]
|
||||
u64_digit = []
|
||||
prime = ["rand"]
|
||||
nightly = ["zeroize/nightly"]
|
||||
nightly = ["zeroize/nightly", "rand/nightly"]
|
||||
|
@ -325,7 +325,9 @@ mod tests {
|
||||
#[cfg(feature = "rand")]
|
||||
use num_traits::{One, Zero};
|
||||
#[cfg(feature = "rand")]
|
||||
use rand::{SeedableRng, XorShiftRng};
|
||||
use rand::SeedableRng;
|
||||
#[cfg(feature = "rand")]
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
#[cfg(feature = "rand")]
|
||||
fn extended_gcd_euclid(a: Cow<BigUint>, b: Cow<BigUint>) -> (BigInt, BigInt, BigInt) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Randomization of big integers
|
||||
|
||||
use rand::distributions::uniform::{SampleUniform, UniformSampler};
|
||||
use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler};
|
||||
use rand::prelude::*;
|
||||
use rand::AsByteSliceMut;
|
||||
use rand::Rng;
|
||||
@ -128,18 +128,29 @@ impl UniformSampler for UniformBigUint {
|
||||
type X = BigUint;
|
||||
|
||||
#[inline]
|
||||
fn new(low: Self::X, high: Self::X) -> Self {
|
||||
fn new<B1, B2>(low_b: B1, high_b: B2) -> Self
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
let low = low_b.borrow();
|
||||
let high = high_b.borrow();
|
||||
|
||||
assert!(low < high);
|
||||
|
||||
UniformBigUint {
|
||||
len: high - &low,
|
||||
base: low,
|
||||
len: high - low,
|
||||
base: low.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
|
||||
assert!(low <= high);
|
||||
Self::new(low, high + 1u32)
|
||||
fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
Self::new(low_b, high_b.borrow() + 1u32)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -148,8 +159,15 @@ impl UniformSampler for UniformBigUint {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sample_single<R: Rng + ?Sized>(low: Self::X, high: Self::X, rng: &mut R) -> Self::X {
|
||||
rng.gen_biguint_range(&low, &high)
|
||||
fn sample_single<R: Rng + ?Sized, B1, B2>(low_b: B1, high_b: B2, rng: &mut R) -> Self::X
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
let low = low_b.borrow();
|
||||
let high = high_b.borrow();
|
||||
|
||||
rng.gen_biguint_range(low, high)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,16 +186,31 @@ impl UniformSampler for UniformBigInt {
|
||||
type X = BigInt;
|
||||
|
||||
#[inline]
|
||||
fn new(low: Self::X, high: Self::X) -> Self {
|
||||
#[inline]
|
||||
fn new<B1, B2>(low_b: B1, high_b: B2) -> Self
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
let low = low_b.borrow();
|
||||
let high = high_b.borrow();
|
||||
|
||||
assert!(low < high);
|
||||
UniformBigInt {
|
||||
len: into_magnitude(high - &low),
|
||||
base: low,
|
||||
len: into_magnitude(high - low),
|
||||
base: low.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
|
||||
fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
let low = low_b.borrow();
|
||||
let high = high_b.borrow();
|
||||
|
||||
assert!(low <= high);
|
||||
Self::new(low, high + 1u32)
|
||||
}
|
||||
@ -188,8 +221,15 @@ impl UniformSampler for UniformBigInt {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sample_single<R: Rng + ?Sized>(low: Self::X, high: Self::X, rng: &mut R) -> Self::X {
|
||||
rng.gen_bigint_range(&low, &high)
|
||||
fn sample_single<R: Rng + ?Sized, B1, B2>(low_b: B1, high_b: B2, rng: &mut R) -> Self::X
|
||||
where
|
||||
B1: SampleBorrow<Self::X> + Sized,
|
||||
B2: SampleBorrow<Self::X> + Sized,
|
||||
{
|
||||
let low = low_b.borrow();
|
||||
let high = high_b.borrow();
|
||||
|
||||
rng.gen_bigint_range(low, high)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,12 @@
|
||||
|
||||
#[cfg(feature = "rand")]
|
||||
extern crate rand;
|
||||
#[cfg(all(test, feature = "rand"))]
|
||||
extern crate rand_chacha;
|
||||
#[cfg(all(test, feature = "rand"))]
|
||||
extern crate rand_isaac;
|
||||
#[cfg(all(test, feature = "rand"))]
|
||||
extern crate rand_xorshift;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
extern crate serde;
|
||||
|
@ -3,6 +3,9 @@
|
||||
extern crate num_bigint_dig as num_bigint;
|
||||
extern crate num_traits;
|
||||
extern crate rand;
|
||||
extern crate rand_chacha;
|
||||
extern crate rand_isaac;
|
||||
extern crate rand_xorshift;
|
||||
|
||||
mod biguint {
|
||||
use num_bigint::{BigUint, RandBigInt, RandomBits};
|
||||
@ -135,7 +138,7 @@ mod biguint {
|
||||
|
||||
#[test]
|
||||
fn test_chacha_value_stability() {
|
||||
use rand::prng::ChaChaRng;
|
||||
use rand_chacha::ChaChaRng;
|
||||
seeded_value_stability::<ChaChaRng>(EXPECTED_CHACHA);
|
||||
}
|
||||
|
||||
@ -170,7 +173,7 @@ mod biguint {
|
||||
];
|
||||
#[test]
|
||||
fn test_isaac_value_stability() {
|
||||
use rand::prng::IsaacRng;
|
||||
use rand_isaac::IsaacRng;
|
||||
seeded_value_stability::<IsaacRng>(EXPECTED_ISAAC);
|
||||
}
|
||||
|
||||
@ -204,7 +207,7 @@ mod biguint {
|
||||
|
||||
#[test]
|
||||
fn test_xorshift_value_stability() {
|
||||
use rand::prng::XorShiftRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
seeded_value_stability::<XorShiftRng>(EXPECTED_XOR);
|
||||
}
|
||||
}
|
||||
@ -344,7 +347,7 @@ mod bigint {
|
||||
|
||||
#[test]
|
||||
fn test_chacha_value_stability() {
|
||||
use rand::prng::ChaChaRng;
|
||||
use rand_chacha::ChaChaRng;
|
||||
seeded_value_stability::<ChaChaRng>(EXPECTED_CHACHA);
|
||||
}
|
||||
|
||||
@ -379,7 +382,7 @@ mod bigint {
|
||||
|
||||
#[test]
|
||||
fn test_isaac_value_stability() {
|
||||
use rand::prng::IsaacRng;
|
||||
use rand_isaac::IsaacRng;
|
||||
seeded_value_stability::<IsaacRng>(EXPECTED_ISAAC);
|
||||
}
|
||||
|
||||
@ -415,7 +418,7 @@ mod bigint {
|
||||
|
||||
#[test]
|
||||
fn test_xorshift_value_stability() {
|
||||
use rand::prng::XorShiftRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
seeded_value_stability::<XorShiftRng>(EXPECTED_XOR);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user