mirror of
https://github.com/monero-project/monero.git
synced 2025-05-12 09:22:13 -04:00
crypto: replace rand<T>()%N idiom with unbiased rand_idx(N)
This commit is contained in:
parent
b6726aaa6c
commit
a2195b9b7f
5 changed files with 36 additions and 12 deletions
|
@ -33,7 +33,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "include_base_utils.h"
|
||||
#include "common/threadpool.h"
|
||||
#include <random>
|
||||
#include "crypto/crypto.h"
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -517,10 +517,7 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
|
|||
std::vector<std::vector<std::string> > records;
|
||||
records.resize(dns_urls.size());
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<int> dis(0, dns_urls.size() - 1);
|
||||
size_t first_index = dis(gen);
|
||||
size_t first_index = crypto::rand_idx(dns_urls.size());
|
||||
|
||||
// send all requests in parallel
|
||||
std::deque<bool> avail(dns_urls.size(), false), valid(dns_urls.size(), false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue