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

use crypto::rand instead of libc rand in a few tests #5529

Merged
merged 1 commit into from Jul 24, 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
4 changes: 2 additions & 2 deletions tests/unit_tests/mnemonics.cpp
Expand Up @@ -82,7 +82,7 @@ namespace
crypto::secret_key randkey;
for (size_t ii = 0; ii < sizeof(randkey); ++ii)
{
randkey.data[ii] = rand();
randkey.data[ii] = crypto::rand<uint8_t>();
}
crypto::ElectrumWords::bytes_to_words(randkey, w_seed, language.get_language_name());
seed = std::string(w_seed.data(), w_seed.size());
Expand Down Expand Up @@ -256,4 +256,4 @@ TEST(mnemonics, partial_word_tolerance)
res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1);
ASSERT_EQ(true, res);
ASSERT_STREQ(language_name_1.c_str(), "English");
}
}
4 changes: 2 additions & 2 deletions tests/unit_tests/output_selection.cpp
Expand Up @@ -138,7 +138,7 @@ TEST(select_outputs, density)
static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets;

MKOFFSETS(300000, 1 + (rand() & 0x1f));
MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets);

std::vector<int> picks(/*n_outs*/offsets.size(), 0);
Expand Down Expand Up @@ -181,7 +181,7 @@ TEST(select_outputs, same_distribution)
static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets;

MKOFFSETS(300000, 1 + (rand() & 0x1f));
MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets);

std::vector<int> chain_picks(offsets.size(), 0);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/rolling_median.cpp
Expand Up @@ -69,7 +69,7 @@ TEST(rolling_median, series)
v.reserve(100);
for (int i = 0; i < 10000; ++i)
{
uint64_t r = rand();
uint64_t r = crypto::rand<uint64_t>();
v.push_back(r);
if (v.size() > 100)
v.erase(v.begin());
Expand All @@ -87,7 +87,7 @@ TEST(rolling_median, clear_whole)
median.reserve(10000);
for (int i = 0; i < 10000; ++i)
{
random.push_back(rand());
random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
median.push_back(m.median());
}
Expand All @@ -107,7 +107,7 @@ TEST(rolling_median, clear_partway)
median.reserve(10000);
for (int i = 0; i < 10000; ++i)
{
random.push_back(rand());
random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
median.push_back(m.median());
}
Expand All @@ -126,7 +126,7 @@ TEST(rolling_median, order)
random.reserve(1000);
for (int i = 0; i < 1000; ++i)
{
random.push_back(rand());
random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
}
const uint64_t med = m.median();
Expand Down