aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-01-04 02:00:44 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2019-01-16 16:34:57 -0800
commit152146e782d401aa1ce7d989d62306aabc85f22e (patch)
treed53ba894771ed716950149e0d5559e0f2d7d2ecd /src
parenta1f252eda87356fa329c838a7bf569808489648f (diff)
DRY: Implement GetRand using FastRandomContext::randrange
Diffstat (limited to 'src')
-rw-r--r--src/random.cpp12
1 files changed, 1 insertions, 11 deletions
diff --git a/src/random.cpp b/src/random.cpp
index e4c23ceac6..f52b5837aa 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -503,17 +503,7 @@ void RandAddSeedSleep() { ProcRand(nullptr, 0, RNGLevel::SLEEP); }
uint64_t GetRand(uint64_t nMax) noexcept
{
- if (nMax == 0)
- return 0;
-
- // The range of the random source must be a multiple of the modulus
- // to give every possible output value an equal possibility
- uint64_t nRange = (std::numeric_limits<uint64_t>::max() / nMax) * nMax;
- uint64_t nRand = 0;
- do {
- GetRandBytes((unsigned char*)&nRand, sizeof(nRand));
- } while (nRand >= nRange);
- return (nRand % nMax);
+ return FastRandomContext().randrange(nMax);
}
int GetRandInt(int nMax) noexcept