summaryrefslogtreecommitdiff
path: root/src/mongo/platform/random.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/platform/random.cpp')
-rw-r--r--src/mongo/platform/random.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/mongo/platform/random.cpp b/src/mongo/platform/random.cpp
index b7fd984c411..ea641460037 100644
--- a/src/mongo/platform/random.cpp
+++ b/src/mongo/platform/random.cpp
@@ -40,6 +40,7 @@
#include <cstdlib>
#include <iostream>
#include <fstream>
+#include <limits>
#include "mongo/platform/basic.h"
@@ -93,6 +94,15 @@ int64_t PseudoRandom::nextInt64() {
return (a << 32) | b;
}
+double PseudoRandom::nextCanonicalDouble() {
+ double result;
+ do {
+ auto generated = static_cast<uint64_t>(nextInt64());
+ result = static_cast<double>(generated) / std::numeric_limits<uint64_t>::max();
+ } while (result == 1.0);
+ return result;
+}
+
// --- SecureRandom ----
SecureRandom::~SecureRandom() {}