File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -775,5 +775,14 @@ void RandomInit()
775
775
776
776
double MakeExponentiallyDistributed (uint64_t uniform) noexcept
777
777
{
778
- return -std::log1p ((uniform >> 16 ) * -0.0000000000000035527136788 /* -1/2^48 */ );
778
+ // To convert uniform into an exponentially-distributed double, we use two steps:
779
+ // - Convert uniform into a uniformly-distributed double in range [0, 1), use the expression
780
+ // ((uniform >> 11) * 0x1.0p-53), as described in https://prng.di.unimi.it/ under
781
+ // "Generating uniform doubles in the unit interval". Call this value x.
782
+ // - Given an x in uniformly distributed in [0, 1), we find an exponentially distributed value
783
+ // by applying the quantile function to it. For the exponential distribution with mean 1 this
784
+ // is F(x) = -log(1 - x).
785
+ //
786
+ // Combining the two, and using log1p(x) = log(1 + x), we obtain the following:
787
+ return -std::log1p ((uniform >> 11 ) * -0x1 .0p-53 );
779
788
}
You can’t perform that action at this time.
0 commit comments