mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-20 04:22:53 +02:00
Replace more rand() % NUM by randranges
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user