From 193c1574a119605e4d9081d481a6bb03e7bf26cc Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 28 May 2025 13:32:24 +0200 Subject: [PATCH] examples: update rand crate to 0.9.1 (#7371) --- benches/Cargo.toml | 4 ++-- benches/copy.rs | 2 +- benches/sync_broadcast.rs | 2 +- benches/sync_watch.rs | 2 +- examples/Cargo.toml | 1 - stress-test/Cargo.toml | 2 +- tokio/Cargo.toml | 2 +- tokio/tests/sync_broadcast.rs | 4 +--- tokio/tests/time_pause.rs | 2 +- 9 files changed, 9 insertions(+), 12 deletions(-) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index de39565b3..87163be15 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -11,8 +11,8 @@ test-util = ["tokio/test-util"] [dependencies] tokio = { version = "1.5.0", path = "../tokio", features = ["full"] } criterion = "0.5.1" -rand = "0.8" -rand_chacha = "0.3" +rand = "0.9" +rand_chacha = "0.9" [dev-dependencies] tokio-util = { version = "0.7.0", path = "../tokio-util", features = ["full"] } diff --git a/benches/copy.rs b/benches/copy.rs index 5c4eab489..92846d466 100644 --- a/benches/copy.rs +++ b/benches/copy.rs @@ -77,7 +77,7 @@ impl SlowHddWriter { ) -> std::task::Poll> { let service_res = self.as_mut().service_write(cx); - if service_res.is_pending() && self.blocking_rng.gen_bool(PROBABILITY_FLUSH_WAIT) { + if service_res.is_pending() && self.blocking_rng.random_bool(PROBABILITY_FLUSH_WAIT) { return Poll::Pending; } let available = self.buffer_size - self.buffer_used; diff --git a/benches/sync_broadcast.rs b/benches/sync_broadcast.rs index a7dc2e372..3e82c0e5d 100644 --- a/benches/sync_broadcast.rs +++ b/benches/sync_broadcast.rs @@ -17,7 +17,7 @@ fn do_work(rng: &mut impl RngCore) -> u32 { use std::fmt::Write; let mut message = String::new(); for i in 1..=10 { - let _ = write!(&mut message, " {i}={}", rng.gen::()); + let _ = write!(&mut message, " {i}={}", rng.random::()); } message .as_bytes() diff --git a/benches/sync_watch.rs b/benches/sync_watch.rs index 94f3339fb..93dcbc118 100644 --- a/benches/sync_watch.rs +++ b/benches/sync_watch.rs @@ -17,7 +17,7 @@ fn do_work(rng: &mut impl RngCore) -> u32 { use std::fmt::Write; let mut message = String::new(); for i in 1..=10 { - let _ = write!(&mut message, " {i}={}", rng.gen::()); + let _ = write!(&mut message, " {i}={}", rng.random::()); } message .as_bytes() diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 0a9400981..d11a2380d 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -23,7 +23,6 @@ serde_json = "1.0" httparse = "1.0" httpdate = "1.0" once_cell = "1.5.2" -rand = "0.8.3" [target.'cfg(windows)'.dev-dependencies.windows-sys] version = "0.52" diff --git a/stress-test/Cargo.toml b/stress-test/Cargo.toml index 79db8ce1d..3efc7d53f 100644 --- a/stress-test/Cargo.toml +++ b/stress-test/Cargo.toml @@ -12,7 +12,7 @@ publish = false tokio = { version = "1.0.0", path = "../tokio/", features = ["full"] } [dev-dependencies] -rand = "0.8" +rand = "0.9" [lints] workspace = true diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index e4be60d0e..8444de7a9 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -147,7 +147,7 @@ tempfile = "3.1.0" proptest = "1" [target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies] -rand = "0.8.0" +rand = "0.9" [target.'cfg(all(target_family = "wasm", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index a5c782884..0d657ff77 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -565,13 +565,11 @@ fn sender_len() { #[test] #[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] fn sender_len_random() { - use rand::Rng; - let (tx, mut rx1) = broadcast::channel(16); let mut rx2 = tx.subscribe(); for _ in 0..1000 { - match rand::thread_rng().gen_range(0..4) { + match rand::random_range(0..4) { 0 => { let _ = rx1.try_recv(); } diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index 879d1b72a..be993b4c8 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -63,7 +63,7 @@ async fn paused_time_stress_run() -> Vec { let mut times = vec![]; let start = Instant::now(); for _ in 0..10_000 { - let sleep = rng.gen_range(Duration::from_secs(0)..Duration::from_secs(1)); + let sleep = rng.random_range(Duration::from_secs(0)..Duration::from_secs(1)); time::sleep(sleep).await; times.push(start.elapsed()); }