@@ -217,7 +217,7 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
217
217
return ;
218
218
219
219
// find a bucket it is in now
220
- int nRnd = RandomInt (ADDRMAN_NEW_BUCKET_COUNT);
220
+ int nRnd = insecure_rand. randrange (ADDRMAN_NEW_BUCKET_COUNT);
221
221
int nUBucket = -1 ;
222
222
for (unsigned int n = 0 ; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
223
223
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
@@ -291,7 +291,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
291
291
int nFactor = 1 ;
292
292
for (int n = 0 ; n < pinfo->nRefCount ; n++)
293
293
nFactor *= 2 ;
294
- if (nFactor > 1 && (RandomInt (nFactor) != 0 ))
294
+ if (nFactor > 1 && (insecure_rand. randrange (nFactor) != 0 ))
295
295
return false ;
296
296
} else {
297
297
pinfo = Create (addr, source, &nId);
@@ -356,37 +356,37 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
356
356
357
357
// Use a 50% chance for choosing between tried and new table entries.
358
358
if (!newOnly &&
359
- (nTried > 0 && (nNew == 0 || RandomInt ( 2 ) == 0 ))) {
359
+ (nTried > 0 && (nNew == 0 || insecure_rand. randbool ( ) == 0 ))) {
360
360
// use a tried node
361
361
double fChanceFactor = 1.0 ;
362
362
while (1 ) {
363
- int nKBucket = RandomInt (ADDRMAN_TRIED_BUCKET_COUNT);
364
- int nKBucketPos = RandomInt (ADDRMAN_BUCKET_SIZE);
363
+ int nKBucket = insecure_rand. randrange (ADDRMAN_TRIED_BUCKET_COUNT);
364
+ int nKBucketPos = insecure_rand. randrange (ADDRMAN_BUCKET_SIZE);
365
365
while (vvTried[nKBucket][nKBucketPos] == -1 ) {
366
366
nKBucket = (nKBucket + insecure_rand.randbits (ADDRMAN_TRIED_BUCKET_COUNT_LOG2)) % ADDRMAN_TRIED_BUCKET_COUNT;
367
367
nKBucketPos = (nKBucketPos + insecure_rand.randbits (ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
368
368
}
369
369
int nId = vvTried[nKBucket][nKBucketPos];
370
370
assert (mapInfo.count (nId) == 1 );
371
371
CAddrInfo& info = mapInfo[nId];
372
- if (RandomInt ( 1 << 30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
372
+ if (insecure_rand. randbits ( 30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
373
373
return info;
374
374
fChanceFactor *= 1.2 ;
375
375
}
376
376
} else {
377
377
// use a new node
378
378
double fChanceFactor = 1.0 ;
379
379
while (1 ) {
380
- int nUBucket = RandomInt (ADDRMAN_NEW_BUCKET_COUNT);
381
- int nUBucketPos = RandomInt (ADDRMAN_BUCKET_SIZE);
380
+ int nUBucket = insecure_rand. randrange (ADDRMAN_NEW_BUCKET_COUNT);
381
+ int nUBucketPos = insecure_rand. randrange (ADDRMAN_BUCKET_SIZE);
382
382
while (vvNew[nUBucket][nUBucketPos] == -1 ) {
383
383
nUBucket = (nUBucket + insecure_rand.randbits (ADDRMAN_NEW_BUCKET_COUNT_LOG2)) % ADDRMAN_NEW_BUCKET_COUNT;
384
384
nUBucketPos = (nUBucketPos + insecure_rand.randbits (ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
385
385
}
386
386
int nId = vvNew[nUBucket][nUBucketPos];
387
387
assert (mapInfo.count (nId) == 1 );
388
388
CAddrInfo& info = mapInfo[nId];
389
- if (RandomInt ( 1 << 30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
389
+ if (insecure_rand. randbits ( 30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
390
390
return info;
391
391
fChanceFactor *= 1.2 ;
392
392
}
@@ -482,7 +482,7 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr)
482
482
if (vAddr.size () >= nNodes)
483
483
break ;
484
484
485
- int nRndPos = RandomInt (vRandom.size () - n) + n;
485
+ int nRndPos = insecure_rand. randrange (vRandom.size () - n) + n;
486
486
SwapRandom (n, nRndPos);
487
487
assert (mapInfo.count (vRandom[n]) == 1 );
488
488
@@ -530,10 +530,6 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
530
530
info.nServices = nServices;
531
531
}
532
532
533
- int CAddrMan::RandomInt (int nMax){
534
- return GetRandInt (nMax);
535
- }
536
-
537
533
void CAddrMan::ResolveCollisions_ ()
538
534
{
539
535
for (std::set<int >::iterator it = m_tried_collisions.begin (); it != m_tried_collisions.end ();) {
@@ -593,7 +589,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
593
589
std::set<int >::iterator it = m_tried_collisions.begin ();
594
590
595
591
// Selects a random element from m_tried_collisions
596
- std::advance (it, GetRandInt (m_tried_collisions.size ()));
592
+ std::advance (it, insecure_rand. randrange (m_tried_collisions.size ()));
597
593
int id_new = *it;
598
594
599
595
// If id_new not found in mapInfo remove it from m_tried_collisions
0 commit comments