summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/random.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/base/random.cc b/src/base/random.cc
index 457b0c98b..cffeddec9 100644
--- a/src/base/random.cc
+++ b/src/base/random.cc
@@ -29,6 +29,7 @@
* Ali Saidi
*/
+#include <limits>
#include "base/fenv.hh"
#include "base/intmath.hh"
#include "base/misc.hh"
@@ -67,7 +68,10 @@ Random::genrand(uint32_t max)
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint32_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint32_t) * 8 - log);
uint32_t random;
@@ -83,7 +87,10 @@ Random::genrand(uint64_t max)
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint64_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint64_t) * 8 - log);
uint64_t random;