Replace more rand() % NUM by randranges

This commit is contained in:
Pieter Wuille
2017-06-07 11:34:55 -07:00
parent efee1db21a
commit 3ecabae363
7 changed files with 19 additions and 19 deletions

View File

@ -34,8 +34,8 @@ BOOST_AUTO_TEST_CASE(skiplist_test)
}
for (int i=0; i < 1000; i++) {
int from = insecure_rand() % (SKIPLIST_LENGTH - 1);
int to = insecure_rand() % (from + 1);
int from = insecure_randrange(SKIPLIST_LENGTH - 1);
int to = insecure_randrange(from + 1);
BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]);
BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]);
@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test)
} else {
// randomly choose something in the range [MTP, MTP*2]
int64_t medianTimePast = vBlocksMain[i].GetMedianTimePast();
int r = insecure_rand() % medianTimePast;
int r = insecure_randrange(medianTimePast);
vBlocksMain[i].nTime = r + medianTimePast;
vBlocksMain[i].nTimeMax = std::max(vBlocksMain[i].nTime, vBlocksMain[i-1].nTimeMax);
}
@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test)
// Verify that FindEarliestAtLeast is correct.
for (unsigned int i=0; i<10000; ++i) {
// Pick a random element in vBlocksMain.
int r = insecure_rand() % vBlocksMain.size();
int r = insecure_randrange(vBlocksMain.size());
int64_t test_time = vBlocksMain[r].nTime;
CBlockIndex *ret = chain.FindEarliestAtLeast(test_time);
BOOST_CHECK(ret->nTimeMax >= test_time);