Repository: tower-rs/tower
Pull request #811 (2025-01-27 19:13:33)

Bump rand to v0.9


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index e1a94d2..688c187 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ http = "1"
 indexmap = "2.0.2"
 pin-project-lite = "0.2.7"
 quickcheck = "1"
-rand = "0.8"
+rand = "0.9"
 slab = "0.4.9"
 sync_wrapper = "1"
 tokio = "1.6.2"
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
index b8faa46..e9fcf1e 100644
--- a/examples/Cargo.toml
+++ b/examples/Cargo.toml
@@ -10,7 +10,7 @@ edition = "2018"
 tower = { version = "0.4", path = "../tower", features = ["full"] }
 tower-service = "0.3"
 tokio = { version = "1.0", features = ["full"] }
-rand = "0.8"
+rand = "0.9"
 pin-project = "1.0"
 futures = "0.3.22"
 tracing = "0.1"
diff --git a/tower/examples/tower-balance.rs b/tower/examples/tower-balance.rs
index 851f3ec..f220a90 100644
--- a/tower/examples/tower-balance.rs
+++ b/tower/examples/tower-balance.rs
@@ -4,7 +4,6 @@ use futures_core::{Stream, TryStream};
 use futures_util::{stream, stream::StreamExt, stream::TryStreamExt};
 use hdrhistogram::Histogram;
 use pin_project_lite::pin_project;
-use rand::{self, Rng};
 use std::hash::Hash;
 use std::time::Duration;
 use std::{
@@ -124,7 +123,7 @@ fn gen_disco() -> impl Discover<
 
                     let maxms = u64::from(latency.subsec_millis())
                         .saturating_add(latency.as_secs().saturating_mul(1_000));
-                    let latency = Duration::from_millis(rand::thread_rng().gen_range(0..maxms));
+                    let latency = Duration::from_millis(rand::random_range(0..maxms));
 
                     async move {
                         time::sleep_until(start + latency).await;


Test patch:
diff --git a/tower/tests/balance/main.rs b/tower/tests/balance/main.rs
index ff19eab..9675e3f 100644
--- a/tower/tests/balance/main.rs
+++ b/tower/tests/balance/main.rs
@@ -28,7 +28,7 @@ impl Service<Req> for Mock {
 impl tower::load::Load for Mock {
     type Metric = usize;
     fn load(&self) -> Self::Metric {
-        rand::random()
+        rand::random_range(usize::MIN..=usize::MAX)
     }
 }
 
@@ -43,7 +43,7 @@ fn stress() {
     let mut services = slab::Slab::<(mock::Handle<Req, Req>, bool)>::new();
     let mut retired = Vec::<mock::Handle<Req, Req>>::new();
     for _ in 0..100_000 {
-        for _ in 0..(rand::random::<u8>() % 8) {
+        for _ in 0..rand::random_range(0u8..8) {
             if !services.is_empty() && rand::random() {
                 if nready == 0 || rand::random::<u8>() > u8::MAX / 4 {
                     // ready a service
@@ -114,8 +114,7 @@ fn stress() {
                 } else {
                     // remove
                     while !services.is_empty() {
-                        let k =
-                            rand::random::<usize>() % (services.iter().next_back().unwrap().0 + 1);
+                        let k = rand::random_range(0..=services.iter().next_back().unwrap().0);
                         if services.contains(k) {
                             let (handle, ready) = services.remove(k);
                             if ready {
@@ -130,7 +129,7 @@ fn stress() {
             } else {
                 // fail a service
                 while !services.is_empty() {
-                    let k = rand::random::<usize>() % (services.iter().next_back().unwrap().0 + 1);
+                    let k = rand::random_range(0..=services.iter().next_back().unwrap().0);
                     if services.contains(k) {
                         let (mut handle, ready) = services.remove(k);
                         if ready {