summaryrefslogtreecommitdiff
path: root/src/mongo/platform/random.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-08-25 17:17:39 -0400
committerMathias Stearn <mathias@10gen.com>2015-08-28 15:23:54 -0400
commit1c5fdf89ee6fd377096b9369b94ee490792a22b8 (patch)
tree661e7a672e417375cc7685c0d11c98b7f1442c2d /src/mongo/platform/random.h
parent1eca10057d98aa46e9adf3b06edac74c437edfd3 (diff)
downloadmongo-1c5fdf89ee6fd377096b9369b94ee490792a22b8.tar.gz
SERVER-20121 Use unsigned arithmetic in PsuedoRandom
Diffstat (limited to 'src/mongo/platform/random.h')
-rw-r--r--src/mongo/platform/random.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/mongo/platform/random.h b/src/mongo/platform/random.h
index 8d43284b9a1..76094e97690 100644
--- a/src/mongo/platform/random.h
+++ b/src/mongo/platform/random.h
@@ -57,20 +57,20 @@ public:
* @return a number between 0 and max
*/
int32_t nextInt32(int32_t max) {
- return nextInt32() % max;
+ return static_cast<uint32_t>(nextInt32()) % static_cast<uint32_t>(max);
}
/**
* @return a number between 0 and max
*/
int64_t nextInt64(int64_t max) {
- return nextInt64() % max;
+ return static_cast<uint64_t>(nextInt64()) % static_cast<uint64_t>(max);
}
/**
* @return a number between 0 and max
*
- * This makes PsuedoRandom instances passable as the third argument to std::random_shuffle
+ * This makes PseudoRandom instances passable as the third argument to std::random_shuffle
*/
intptr_t operator()(intptr_t max) {
if (sizeof(intptr_t) == 4)
@@ -79,10 +79,12 @@ public:
}
private:
- int32_t _x;
- int32_t _y;
- int32_t _z;
- int32_t _w;
+ uint32_t nextUInt32();
+
+ uint32_t _x;
+ uint32_t _y;
+ uint32_t _z;
+ uint32_t _w;
};
/**
@@ -98,4 +100,4 @@ public:
static SecureRandom* create();
};
-}
+} // namespace mongo