Skip to content

Commit

Permalink
Use gen_range rather than modulo
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Apr 25, 2024
1 parent b2e2114 commit 060cd6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
17 changes: 9 additions & 8 deletions zenoh/src/net/routing/hat/linkstate_peer/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::net::runtime::Runtime;
use crate::runtime::WeakRuntime;
use petgraph::graph::NodeIndex;
use petgraph::visit::{VisitMap, Visitable};
use rand::Rng;
use std::convert::TryInto;
use vec_map::VecMap;
use zenoh_buffers::writer::{DidntWrite, HasWriter};
Expand Down Expand Up @@ -498,10 +499,10 @@ impl Network {
.is_none()
{
// random backoff
tokio::time::sleep(std::time::Duration::from_millis(
rand::random::<u64>() % 100,
))
.await;
let sleep_time = std::time::Duration::from_millis(
rand::thread_rng().gen_range(0..100),
);
tokio::time::sleep(sleep_time).await;
runtime.connect_peer(&zid, &locators).await;
}
});
Expand Down Expand Up @@ -622,10 +623,10 @@ impl Network {
.is_none()
{
// random backoff
tokio::time::sleep(std::time::Duration::from_millis(
rand::random::<u64>() % 100,
))
.await;
let sleep_time = std::time::Duration::from_millis(
rand::thread_rng().gen_range(0..100),
);
tokio::time::sleep(sleep_time).await;
runtime.connect_peer(&zid, &locators).await;
}
});
Expand Down
9 changes: 5 additions & 4 deletions zenoh/src/net/routing/hat/p2p_peer/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::net::protocol::linkstate::{LinkState, LinkStateList};
use crate::net::runtime::Runtime;
use crate::runtime::WeakRuntime;
use petgraph::graph::NodeIndex;
use rand::Rng;
use std::convert::TryInto;
use vec_map::VecMap;
use zenoh_buffers::writer::{DidntWrite, HasWriter};
Expand Down Expand Up @@ -418,10 +419,10 @@ impl Network {
.is_none()
{
// random backoff
tokio::time::sleep(std::time::Duration::from_millis(
rand::random::<u64>() % 100,
))
.await;
let sleep_time = std::time::Duration::from_millis(
rand::thread_rng().gen_range(0..100),
);
tokio::time::sleep(sleep_time).await;
runtime.connect_peer(&zid, &locators).await;
}
});
Expand Down
17 changes: 9 additions & 8 deletions zenoh/src/net/routing/hat/router/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::net::routing::dispatcher::tables::NodeId;
use crate::net::runtime::Runtime;
use petgraph::graph::NodeIndex;
use petgraph::visit::{IntoNodeReferences, VisitMap, Visitable};
use rand::Rng;
use std::convert::TryInto;
use vec_map::VecMap;
use zenoh_buffers::writer::{DidntWrite, HasWriter};
Expand Down Expand Up @@ -501,10 +502,10 @@ impl Network {
.is_none()
{
// random backoff
tokio::time::sleep(std::time::Duration::from_millis(
rand::random::<u64>() % 100,
))
.await;
let sleep_time = std::time::Duration::from_millis(
rand::thread_rng().gen_range(0..100),
);
tokio::time::sleep(sleep_time).await;
runtime.connect_peer(&zid, &locators).await;
}
});
Expand Down Expand Up @@ -625,10 +626,10 @@ impl Network {
.is_none()
{
// random backoff
tokio::time::sleep(std::time::Duration::from_millis(
rand::random::<u64>() % 100,
))
.await;
let sleep_time = std::time::Duration::from_millis(
rand::thread_rng().gen_range(0..100),
);
tokio::time::sleep(sleep_time).await;
runtime.connect_peer(&zid, &locators).await;
}
});
Expand Down

0 comments on commit 060cd6f

Please sign in to comment.