summaryrefslogtreecommitdiff
path: root/src/mongo/platform
diff options
context:
space:
mode:
authorRishab Joshi <rishab.joshi@mongodb.com>2022-01-30 22:05:05 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-30 22:38:32 +0000
commitd726a1820bef623a3220bf69bb77d8c5be069f42 (patch)
treee7dce5388aa9a04b83be16347cd284e91c1c37e0 /src/mongo/platform
parent4f5c7688766e550d32863923ae6c23c09e2cb5e3 (diff)
downloadmongo-d726a1820bef623a3220bf69bb77d8c5be069f42.tar.gz
SERVER-62902 Fix type conversion issue in JSSRand.
Diffstat (limited to 'src/mongo/platform')
-rw-r--r--src/mongo/platform/random.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/mongo/platform/random.h b/src/mongo/platform/random.h
index 3521399c896..def8ddf9067 100644
--- a/src/mongo/platform/random.h
+++ b/src/mongo/platform/random.h
@@ -131,6 +131,16 @@ public:
return std::uniform_int_distribution<int64_t>(0, max - 1)(_urbg);
}
+ /**
+ A number uniformly distributed over all possible values that can be safely represented as
+ double without loosing precision.
+ */
+ int64_t nextInt64SafeDoubleRepresentable() {
+ const int64_t maxRepresentableLimit =
+ static_cast<int64_t>(std::ldexp(1, std::numeric_limits<double>::digits)) + 1;
+ return nextInt64(maxRepresentableLimit);
+ }
+
/** Fill array `buf` with `n` random bytes. */
void fill(void* buf, size_t n) {
const auto p = static_cast<uint8_t*>(buf);