From 3c9017ed9afe01e16e90028085533c2a48db3eba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:45:54 +0100 Subject: [PATCH] Update rand requirement from 0.8 to 0.9 (#693) Co-authored-by: Chris Laplante --- Cargo.toml | 2 +- examples/cargo.rs | 6 +++--- examples/finebars.rs | 4 ++-- examples/multi-tree-ext.rs | 4 ++-- examples/multi-tree.rs | 2 +- examples/multi.rs | 4 +--- examples/yarnish.rs | 10 +++++----- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa1878b3..bd263cab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ vt100 = { version = "0.15.1", optional = true } [dev-dependencies] clap = { version = "4", features = ["color", "derive"] } once_cell = "1" -rand = "0.8" +rand = "0.9" tokio = { version = "1", features = ["fs", "time", "rt"] } futures = "0.3" # so the doctest for wrap_stream is nice pretty_assertions = "1.4.0" diff --git a/examples/cargo.rs b/examples/cargo.rs index 1e2ff2e9..e29f7fe7 100644 --- a/examples/cargo.rs +++ b/examples/cargo.rs @@ -64,7 +64,7 @@ fn main() { let tx = tx.clone(); let crates = crates.clone(); thread::spawn(move || { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); loop { let krate = crates.lock().unwrap().next(); // notify main thread if n thread is processing a crate @@ -73,9 +73,9 @@ fn main() { thread::sleep(Duration::from_millis( // last compile and linking is always slow, let's mimic that if CRATES.last() == Some(krate) { - rng.gen_range(1_000..2_000) + rng.random_range(1_000..2_000) } else { - rng.gen_range(250..1_000) + rng.random_range(250..1_000) }, )); } else { diff --git a/examples/finebars.rs b/examples/finebars.rs index dffb967b..06a1a2dc 100644 --- a/examples/finebars.rs +++ b/examples/finebars.rs @@ -2,7 +2,7 @@ use std::thread; use std::time::Duration; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; -use rand::{thread_rng, Rng}; +use rand::Rng; fn main() { let styles = [ @@ -25,7 +25,7 @@ fn main() { .progress_chars(s.1), ); pb.set_prefix(s.0); - let wait = Duration::from_millis(thread_rng().gen_range(10..30)); + let wait = Duration::from_millis(rand::rng().random_range(10..30)); thread::spawn(move || { for i in 0..512 { thread::sleep(wait); diff --git a/examples/multi-tree-ext.rs b/examples/multi-tree-ext.rs index 06515489..b769f381 100644 --- a/examples/multi-tree-ext.rs +++ b/examples/multi-tree-ext.rs @@ -266,9 +266,9 @@ fn get_action(rng: &mut dyn RngCore, items: &[&Item]) -> Action { }) .map(|(idx, _)| idx) .collect::>(); - let k = rng.gen_range(0..16); + let k = rng.random_range(0..16); if (k > 0 || k == 0 && elem_idx == ELEMENTS.len()) && !uncompleted.is_empty() { - let idx = rng.gen_range(0..uncompleted.len() as u64) as usize; + let idx = rng.random_range(0..uncompleted.len() as u64) as usize; Action::IncProgressBar(uncompleted[idx]) } else if elem_idx < ELEMENTS.len() { ELEM_IDX.fetch_add(1, Ordering::SeqCst); diff --git a/examples/multi-tree.rs b/examples/multi-tree.rs index 3435424a..ac1f0609 100644 --- a/examples/multi-tree.rs +++ b/examples/multi-tree.rs @@ -173,7 +173,7 @@ fn get_action(rng: &mut dyn RngCore, tree: &Mutex>) -> Option } else { loop { let list = tree.lock().unwrap(); - let k = rng.gen_range(0..17); + let k = rng.random_range(0..17); if k == 0 && list_len < elem_len { return Some(Action::AddProgressBar(list.len())); } else { diff --git a/examples/multi.rs b/examples/multi.rs index dfb71ff0..4a7eb536 100644 --- a/examples/multi.rs +++ b/examples/multi.rs @@ -47,9 +47,7 @@ fn main() { pb.inc(1); let pb2 = pb2.clone(); threads.push(thread::spawn(move || { - thread::sleep( - rand::thread_rng().gen_range(Duration::from_secs(1)..Duration::from_secs(5)), - ); + thread::sleep(rand::rng().random_range(Duration::from_secs(1)..Duration::from_secs(5))); pb2.inc(1); })); } diff --git a/examples/yarnish.rs b/examples/yarnish.rs index 6b7c29b1..129c0f5b 100644 --- a/examples/yarnish.rs +++ b/examples/yarnish.rs @@ -3,7 +3,7 @@ use std::time::{Duration, Instant}; use console::{style, Emoji}; use indicatif::{HumanDuration, MultiProgress, ProgressBar, ProgressStyle}; -use rand::seq::SliceRandom; +use rand::prelude::IndexedRandom; use rand::Rng; static PACKAGES: &[&str] = &[ @@ -33,7 +33,7 @@ static PAPER: Emoji<'_, '_> = Emoji("📃 ", ""); static SPARKLE: Emoji<'_, '_> = Emoji("✨ ", ":-)"); pub fn main() { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let started = Instant::now(); let spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}") .unwrap() @@ -71,16 +71,16 @@ pub fn main() { let m = MultiProgress::new(); let handles: Vec<_> = (0..4u32) .map(|i| { - let count = rng.gen_range(30..80); + let count = rng.random_range(30..80); let pb = m.add(ProgressBar::new(count)); pb.set_style(spinner_style.clone()); pb.set_prefix(format!("[{}/?]", i + 1)); thread::spawn(move || { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let pkg = PACKAGES.choose(&mut rng).unwrap(); for _ in 0..count { let cmd = COMMANDS.choose(&mut rng).unwrap(); - thread::sleep(Duration::from_millis(rng.gen_range(25..200))); + thread::sleep(Duration::from_millis(rng.random_range(25..200))); pb.set_message(format!("{pkg}: {cmd}")); pb.inc(1); }