Skip to content

Commit

Permalink
Ranges for indices
Browse files Browse the repository at this point in the history
  • Loading branch information
ErakhtinB committed Dec 26, 2024
1 parent d65d680 commit 7714e61
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/network/impl/synchronizer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,11 +1224,13 @@ namespace kagome::network {
selected_peers.push_back(p_id);
}
} else {
std::vector<uint32_t> indices(active_peers_size);
std::iota(indices.begin(), indices.end(), 0);
std::vector<int> indices;
for (int i = 0; i < active_peers_size; ++i) {
indices.push_back(i);
}
std::random_device rd;
std::mt19937 gen(rd());
std::ranges::shuffle(indices.begin(), indices.end(), gen);
std::ranges::shuffle(indices, gen);
for (uint32_t i = 0; i < number_of_peers_to_add; ++i) {
selected_peers.push_back(active_peers[indices[i]]);
}
Expand Down

0 comments on commit 7714e61

Please sign in to comment.