Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

migrate to rand 0.9.0 #12

Closed
wants to merge 1 commit into from
Closed
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
132 changes: 118 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/jonhoo/rust-zipf"
documentation = "https://docs.rs/zipf"

[dependencies]
rand = { version = "0.8.0", default-features = false }
rand = { version = "0.9.0", default-features = false }

[dev-dependencies]
rand = "0.8.0"
rand = "0.9.0"
8 changes: 4 additions & 4 deletions benches/zipf_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use test::Bencher;
#[bench]
fn bench_us(b: &mut Bencher) {
use rand;
use rand::distributions::Distribution;
use rand::distr::Distribution;
use zipf::ZipfDistribution;
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let us = ZipfDistribution::new(1000000, 1.07).unwrap();
b.iter(|| us.sample(&mut rng));
}

#[bench]
fn bench_threadrng(b: &mut Bencher) {
use rand::{self, Rng};
let mut rng = rand::thread_rng();
b.iter(|| rng.gen::<u64>());
let mut rng = rand::rng();
b.iter(|| rng.random::<u64>());
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ZipfDistribution {

loop {
use std::cmp;
let u: f64 = hnum + rng.gen::<f64>() * (self.h_integral_x1 - hnum);
let u: f64 = hnum + rng.random::<f64>() * (self.h_integral_x1 - hnum);
// u is uniformly distributed in (h_integral_x1, h_integral_num_elements]

let x: f64 = ZipfDistribution::h_integral_inv(u, self.exponent);
Expand Down Expand Up @@ -174,7 +174,7 @@ impl ZipfDistribution {
}
}

impl rand::distributions::Distribution<usize> for ZipfDistribution {
impl rand::distr::Distribution<usize> for ZipfDistribution {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
self.next(rng)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ fn helper2(x: f64) -> f64 {
#[cfg(test)]
mod test {
use super::ZipfDistribution;
use rand::distributions::Distribution;
use rand::distr::Distribution;

#[inline]
fn test(alpha: f64) {
Expand All @@ -252,7 +252,7 @@ mod test {
// as the alpha increases, we need more samples, since the frequency in the tail grows so low
let samples = (2.0f64.powf(alpha) * 5000000.0) as usize;

let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let zipf = ZipfDistribution::new(N, alpha).unwrap();

let harmonic: f64 = (1..=N).map(|n| 1.0 / (n as f64).powf(alpha)).sum();
Expand Down