File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -236,23 +236,23 @@ void peerWatchdog(ConnectionPool& conns_)
236236 }
237237 }
238238 }
239-
239+ std::random_device rd;
240+ std::mt19937 gen (rd ());
241+ std::uniform_int_distribution<int > dist (0 , N - 1 );
240242 // if there is no worst, randomly pick 1
241243 if (!worst) {
242244 if (N > 0 ) {
243- std::random_device rd;
244- std::mt19937 gen (rd ());
245- std::uniform_int_distribution<int > dist (0 , N - 1 );
246245 int randomIdx = dist (gen);
247246 conns_.get (randomIdx, worst);
248247 }
249248 }
250249 if (worst) {
251250 std::vector<std::string> newPeer;
251+ std::string mode = dist (gen) % 2 == 0 ? " closest" : " random" ;
252252 if (worst->isBM ()) {
253- newPeer = GetPeerFromDNS (1 , 0 , " closest " );
253+ newPeer = GetPeerFromDNS (1 , 0 , mode );
254254 } else {
255- newPeer = GetPeerFromDNS (0 , 1 , " random " );
255+ newPeer = GetPeerFromDNS (0 , 1 , mode );
256256 }
257257 ParsedEndpoint parsed;
258258 if (!newPeer.empty () && parseEndpoint (newPeer[0 ], parsed)) {
You can’t perform that action at this time.
0 commit comments