diff --git a/Cargo.toml b/Cargo.toml index 5bf7199..70a26c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ ndarray = { default-features = false, optional = true, version = "0.15.6" } num-traits = { default-features = false, features = ["i128"], version = "0.2" } postgres = { default-features = false, optional = true, version = "0.19" } proptest = { default-features = false, optional = true, features = ["std"], version = "1.0" } -rand = { default-features = false, optional = true, version = "0.8" } +rand = { default-features = false, optional = true, version = "0.9" } rkyv = { default-features = false, features = ["size_32", "std"], optional = true, version = "0.7.42" } rocket = { default-features = false, optional = true, version = "0.5.0-rc.3" } rust_decimal_macros = { default-features = false, optional = true, version = "1.33" } # This needs to be the n-1 published version @@ -43,7 +43,7 @@ bytes = { default-features = false, version = "1.0" } criterion = { default-features = false, version = "0.5" } csv = "1" futures = { default-features = false, version = "0.3" } -rand = { default-features = false, features = ["getrandom"], version = "0.8" } +rand = { default-features = false, features = ["thread_rng"], version = "0.9" } rust_decimal_macros = { default-features = false, version = "1.33" } serde = { default-features = false, features = ["derive"], version = "1.0" } serde_json = "1.0" diff --git a/src/rand.rs b/src/rand.rs index afd8a64..29dea68 100644 --- a/src/rand.rs +++ b/src/rand.rs @@ -1,13 +1,13 @@ use crate::Decimal; use rand::{ - distributions::{ + distr::{ uniform::{SampleBorrow, SampleUniform, UniformInt, UniformSampler}, - Distribution, Standard, + Distribution, StandardUniform, }, Rng, }; -impl Distribution for Standard { +impl Distribution for StandardUniform { fn sample(&self, rng: &mut R) -> Decimal where R: Rng + ?Sized, @@ -16,7 +16,7 @@ impl Distribution for Standard { rng.next_u32(), rng.next_u32(), rng.next_u32(), - rng.gen(), + rng.random(), rng.next_u32(), ) } @@ -52,7 +52,7 @@ impl UniformSampler for DecimalSampler { /// assert_eq!(random.scale(), 2); /// ``` #[inline] - fn new(low: B1, high: B2) -> Self + fn new(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, @@ -79,7 +79,7 @@ impl UniformSampler for DecimalSampler { /// assert_eq!(random.scale(), 2); /// ``` #[inline] - fn new_inclusive(low: B1, high: B2) -> Self + fn new_inclusive(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, @@ -88,10 +88,10 @@ impl UniformSampler for DecimalSampler { // Return our sampler, which contains an underlying i128 sampler so we // outsource the actual randomness implementation. - Self { - mantissa_sampler: UniformInt::new_inclusive(low.mantissa(), high.mantissa()), + Ok(Self { + mantissa_sampler: UniformInt::new_inclusive(low.mantissa(), high.mantissa())?, scale: low.scale(), - } + }) } #[inline] @@ -138,16 +138,16 @@ mod tests { #[test] fn has_random_decimal_instances() { - let mut rng = rand::rngs::OsRng; - let random: [Decimal; 32] = rng.gen(); + let mut rng = rand::rng(); + let random: [Decimal; 32] = rng.random(); assert!(random.windows(2).any(|slice| { slice[0] != slice[1] })); } #[test] fn generates_within_range() { - let mut rng = rand::rngs::OsRng; + let mut rng = rand::rng(); for _ in 0..128 { - let random = rng.gen_range(dec!(1.00)..dec!(1.05)); + let random = rng.random_range(dec!(1.00)..dec!(1.05)); assert!(random < dec!(1.05)); assert!(random >= dec!(1.00)); } @@ -155,10 +155,10 @@ mod tests { #[test] fn generates_within_inclusive_range() { - let mut rng = rand::rngs::OsRng; + let mut rng = rand::rng(); let mut values: HashSet = HashSet::new(); for _ in 0..256 { - let random = rng.gen_range(dec!(1.00)..=dec!(1.01)); + let random = rng.random_range(dec!(1.00)..=dec!(1.01)); // The scale is 2, so 1.00 and 1.01 are the only two valid choices. assert!(random == dec!(1.00) || random == dec!(1.01)); values.insert(random);