Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std::random_shuffle with std::shuffle #5727

Merged
merged 1 commit into from Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cryptonote_core/cryptonote_tx_utils.cpp
Expand Up @@ -354,7 +354,7 @@ namespace cryptonote

if (shuffle_outs)
{
std::shuffle(destinations.begin(), destinations.end(), std::default_random_engine(crypto::rand<unsigned int>()));
std::shuffle(destinations.begin(), destinations.end(), crypto::random_device{});
}

// sort ins by their key image
Expand Down
2 changes: 1 addition & 1 deletion src/p2p/net_peerlist.h
Expand Up @@ -290,7 +290,7 @@ namespace nodetool

if (anonymize)
{
std::random_shuffle(bs_head.begin(), bs_head.end());
std::shuffle(bs_head.begin(), bs_head.end(), crypto::random_device{});
if (bs_head.size() > depth)
bs_head.resize(depth);
for (auto &e: bs_head)
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet2.cpp
Expand Up @@ -7448,7 +7448,7 @@ void wallet2::light_wallet_get_outs(std::vector<std::vector<tools::wallet2::get_
order.resize(light_wallet_requested_outputs_count);
for (size_t n = 0; n < order.size(); ++n)
order[n] = n;
std::shuffle(order.begin(), order.end(), std::default_random_engine(crypto::rand<unsigned>()));
std::shuffle(order.begin(), order.end(), crypto::random_device{});


LOG_PRINT_L2("Looking for " << (fake_outputs_count+1) << " outputs with amounts " << print_money(td.is_rct() ? 0 : td.amount()));
Expand Down Expand Up @@ -8023,7 +8023,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
order.resize(requested_outputs_count);
for (size_t n = 0; n < order.size(); ++n)
order[n] = n;
std::shuffle(order.begin(), order.end(), std::default_random_engine(crypto::rand<unsigned>()));
std::shuffle(order.begin(), order.end(), crypto::random_device{});

LOG_PRINT_L2("Looking for " << (fake_outputs_count+1) << " outputs of size " << print_money(td.is_rct() ? 0 : td.amount()));
for (size_t o = 0; o < requested_outputs_count && outs.back().size() < fake_outputs_count + 1; ++o)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/ringct.cpp
Expand Up @@ -779,8 +779,8 @@ TEST(ringct, range_proofs_accept_very_long_simple)
inputs[n] = n;
outputs[n] = n;
}
std::random_shuffle(inputs, inputs + N);
std::random_shuffle(outputs, outputs + N);
std::shuffle(inputs, inputs + N, crypto::random_device{});
std::shuffle(outputs, outputs + N, crypto::random_device{});
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/rolling_median.cpp
Expand Up @@ -143,7 +143,7 @@ TEST(rolling_median, order)
m.insert(random[i]);
ASSERT_EQ(med, m.median());

std::shuffle(random.begin(), random.end(), std::default_random_engine(crypto::rand<unsigned>()));
std::shuffle(random.begin(), random.end(), crypto::random_device{});
m.clear();
for (int i = 0; i < 1000; ++i)
m.insert(random[i]);
Expand Down