From 3b9f00cd755bc38b50e658473e69ef6b1167c1f5 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Thu, 8 May 2025 23:48:38 +0700 Subject: [PATCH] fix: account for rand crate changes --- src/ratecontroller.rs | 9 ++++----- src/reflector_selector.rs | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ratecontroller.rs b/src/ratecontroller.rs index 8d5ea0a..340952a 100644 --- a/src/ratecontroller.rs +++ b/src/ratecontroller.rs @@ -1,9 +1,8 @@ use crate::netlink::{Netlink, NetlinkError, Qdisc}; use crate::{Config, ReflectorStats}; use log::{debug, error, info, warn}; -use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::RngCore; +use rand::seq::IndexedRandom; +use rand::{rng, RngCore}; use std::collections::HashMap; use std::fs::File; use std::io::Write; @@ -52,7 +51,7 @@ fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec { let mut rates = Vec::new(); for _ in 0..size { - rates.push((thread_rng().next_u64() as f64 * 0.2 + 0.75) * base_speed); + rates.push((rng().next_u64() as f64 * 0.2 + 0.75) * base_speed); } rates @@ -190,7 +189,7 @@ impl Ratecontroller { } if state.delta_stat > delay_ms { - let mut rng = thread_rng(); + let mut rng = rng(); match state.safe_rates.choose(&mut rng) { Some(rnd_rate) => { state.next_rate = diff --git a/src/reflector_selector.rs b/src/reflector_selector.rs index ada5302..4859eae 100644 --- a/src/reflector_selector.rs +++ b/src/reflector_selector.rs @@ -1,7 +1,7 @@ use crate::{Config, ReflectorStats}; use log::{debug, info}; -use rand::seq::SliceRandom; -use rand::{thread_rng, Rng}; +use rand::{rng, Rng}; +use rand::seq::IndexedRandom; use std::collections::HashMap; use std::net::IpAddr; use std::sync::mpsc::Receiver; @@ -24,7 +24,7 @@ impl ReflectorSelector { let baseline_sleep_time = Duration::from_secs_f64(self.config.tick_interval * std::f64::consts::PI); - let mut rng = thread_rng(); + let mut rng = rng(); // Initial wait of several seconds to allow some OWD data to build up sleep(baseline_sleep_time); @@ -107,7 +107,7 @@ impl ReflectorSelector { // Shuffle the deck so we avoid overwhelming good reflectors (Fisher-Yates) for i in (1_usize..candidates.len()).rev() { - let j = rng.gen_range(0..(i + 1)); + let j = rng.random_range(0..(i + 1)); candidates.swap(i, j); }