mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
[move] Move PoissonNextSend to src/random and update comment
PoissonNextSend is used by net and net_processing and is stateless, so place it in the utility random.cpp translation unit.
This commit is contained in:
parent
801aaac2b3
commit
9e64d69bf7
4 changed files with 20 additions and 10 deletions
|
|
@ -19,6 +19,7 @@
|
|||
#include <sync.h> // for Mutex
|
||||
#include <util/time.h> // for GetTimeMicros()
|
||||
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
#include <thread>
|
||||
|
||||
|
|
@ -714,3 +715,9 @@ void RandomInit()
|
|||
|
||||
ReportHardwareRand();
|
||||
}
|
||||
|
||||
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
|
||||
{
|
||||
double unscaled = -log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */);
|
||||
return now + std::chrono::duration_cast<std::chrono::microseconds>(unscaled * average_interval + 0.5us);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue