mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
random: convert GetExponentialRand into rand_exp_duration
This commit is contained in:
@@ -773,8 +773,7 @@ void RandomInit()
|
||||
ReportHardwareRand();
|
||||
}
|
||||
|
||||
std::chrono::microseconds GetExponentialRand(std::chrono::microseconds now, std::chrono::seconds average_interval)
|
||||
double MakeExponentiallyDistributed(uint64_t uniform) noexcept
|
||||
{
|
||||
double unscaled = -std::log1p(FastRandomContext().randbits<48>() * -0.0000000000000035527136788 /* -1/2^48 */);
|
||||
return now + std::chrono::duration_cast<std::chrono::microseconds>(unscaled * average_interval + 0.5us);
|
||||
return -std::log1p((uniform >> 16) * -0.0000000000000035527136788 /* -1/2^48 */);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user