Merge pull request #5529

de27651 use crypto::rand instead of libc rand in a few tests (moneromooo-monero)
This commit is contained in:
luigi1111 2019-07-24 14:06:11 -05:00
commit 7fc76451a5
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
3 changed files with 8 additions and 8 deletions

View file

@ -82,7 +82,7 @@ namespace
crypto::secret_key randkey; crypto::secret_key randkey;
for (size_t ii = 0; ii < sizeof(randkey); ++ii) 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()); crypto::ElectrumWords::bytes_to_words(randkey, w_seed, language.get_language_name());
seed = std::string(w_seed.data(), w_seed.size()); seed = std::string(w_seed.data(), w_seed.size());

View file

@ -138,7 +138,7 @@ TEST(select_outputs, density)
static const size_t NPICKS = 1000000; static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets; std::vector<uint64_t> offsets;
MKOFFSETS(300000, 1 + (rand() & 0x1f)); MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets); tools::gamma_picker picker(offsets);
std::vector<int> picks(/*n_outs*/offsets.size(), 0); std::vector<int> picks(/*n_outs*/offsets.size(), 0);
@ -181,7 +181,7 @@ TEST(select_outputs, same_distribution)
static const size_t NPICKS = 1000000; static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets; std::vector<uint64_t> offsets;
MKOFFSETS(300000, 1 + (rand() & 0x1f)); MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets); tools::gamma_picker picker(offsets);
std::vector<int> chain_picks(offsets.size(), 0); std::vector<int> chain_picks(offsets.size(), 0);

View file

@ -69,7 +69,7 @@ TEST(rolling_median, series)
v.reserve(100); v.reserve(100);
for (int i = 0; i < 10000; ++i) for (int i = 0; i < 10000; ++i)
{ {
uint64_t r = rand(); uint64_t r = crypto::rand<uint64_t>();
v.push_back(r); v.push_back(r);
if (v.size() > 100) if (v.size() > 100)
v.erase(v.begin()); v.erase(v.begin());
@ -87,7 +87,7 @@ TEST(rolling_median, clear_whole)
median.reserve(10000); median.reserve(10000);
for (int i = 0; i < 10000; ++i) for (int i = 0; i < 10000; ++i)
{ {
random.push_back(rand()); random.push_back(crypto::rand<uint64_t>());
m.insert(random.back()); m.insert(random.back());
median.push_back(m.median()); median.push_back(m.median());
} }
@ -107,7 +107,7 @@ TEST(rolling_median, clear_partway)
median.reserve(10000); median.reserve(10000);
for (int i = 0; i < 10000; ++i) for (int i = 0; i < 10000; ++i)
{ {
random.push_back(rand()); random.push_back(crypto::rand<uint64_t>());
m.insert(random.back()); m.insert(random.back());
median.push_back(m.median()); median.push_back(m.median());
} }
@ -126,7 +126,7 @@ TEST(rolling_median, order)
random.reserve(1000); random.reserve(1000);
for (int i = 0; i < 1000; ++i) for (int i = 0; i < 1000; ++i)
{ {
random.push_back(rand()); random.push_back(crypto::rand<uint64_t>());
m.insert(random.back()); m.insert(random.back());
} }
const uint64_t med = m.median(); const uint64_t med = m.median();