mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
random: convert GetExponentialRand into rand_exp_duration
This commit is contained in:
parent
4eaa239dc3
commit
cfb0dfe2cf
4 changed files with 33 additions and 25 deletions
|
|
@ -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 */);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue