mirror of
https://github.com/monero-project/monero.git
synced 2025-11-28 01:31:47 -05: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
|
|
@ -1259,7 +1259,7 @@ namespace nodetool
|
|||
}
|
||||
}
|
||||
else
|
||||
random_index = crypto::rand<size_t>() % filtered.size();
|
||||
random_index = crypto::rand_idx(filtered.size());
|
||||
|
||||
CHECK_AND_ASSERT_MES(random_index < filtered.size(), false, "random_index < filtered.size() failed!!");
|
||||
random_index = filtered[random_index];
|
||||
|
|
@ -1313,7 +1313,7 @@ namespace nodetool
|
|||
return true;
|
||||
|
||||
size_t try_count = 0;
|
||||
size_t current_index = crypto::rand<size_t>()%m_seed_nodes.size();
|
||||
size_t current_index = crypto::rand_idx(m_seed_nodes.size());
|
||||
const net_server& server = m_network_zones.at(epee::net_utils::zone::public_).m_net_server;
|
||||
while(true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ namespace nodetool
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t random_index = crypto::rand<size_t>() % m_peers_gray.size();
|
||||
size_t random_index = crypto::rand_idx(m_peers_gray.size());
|
||||
|
||||
peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
|
||||
pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), random_index);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue