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.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/mongo/platform/random.cpp b/src/mongo/platform/random.cpp
index d1a620d6a74..10c197f6d6a 100644
--- a/src/mongo/platform/random.cpp
+++ b/src/mongo/platform/random.cpp
@@ -35,8 +35,8 @@ namespace mongo {
// ---- PseudoRandom -----
- int32_t PseudoRandom::nextInt32() {
- int32_t t = _x ^ (_x << 11);
+ uint32_t PseudoRandom::nextUInt32() {
+ uint32_t t = _x ^ (_x << 11);
_x = _y;
_y = _z;
_z = _w;
@@ -44,13 +44,13 @@ namespace mongo {
}
namespace {
- const int32_t default_y = 362436069;
- const int32_t default_z = 521288629;
- const int32_t default_w = 88675123;
+ const uint32_t default_y = 362436069;
+ const uint32_t default_z = 521288629;
+ const uint32_t default_w = 88675123;
}
PseudoRandom::PseudoRandom( int32_t seed ) {
- _x = seed;
+ _x = static_cast<uint32_t>(seed);
_y = default_y;
_z = default_z;
_w = default_w;
@@ -58,7 +58,7 @@ namespace mongo {
PseudoRandom::PseudoRandom( uint32_t seed ) {
- _x = static_cast<int32_t>(seed);
+ _x = seed;
_y = default_y;
_z = default_z;
_w = default_w;
@@ -66,8 +66,8 @@ namespace mongo {
PseudoRandom::PseudoRandom( int64_t seed ) {
- int32_t high = seed >> 32;
- int32_t low = seed & 0xFFFFFFFF;
+ uint32_t high = seed >> 32;
+ uint32_t low = seed & 0xFFFFFFFF;
_x = high ^ low;
_y = default_y;
@@ -75,9 +75,13 @@ namespace mongo {
_w = default_w;
}
+ int32_t PseudoRandom::nextInt32() {
+ return nextUInt32();
+ }
+
int64_t PseudoRandom::nextInt64() {
- int64_t a = nextInt32();
- int64_t b = nextInt32();
+ uint64_t a = nextUInt32();
+ uint64_t b = nextUInt32();
return ( a << 32 ) | b;
}