diff -r e69b70e188a9 -r 802856c61da9 src/base/random.cc --- a/src/base/random.cc Thu Dec 01 00:29:45 2011 -0800 +++ b/src/base/random.cc Thu Dec 01 00:30:05 2011 -0800 @@ -29,6 +29,7 @@ * Ali Saidi */ +#include #include "base/fenv.hh" #include "base/intmath.hh" #include "base/misc.hh" @@ -67,7 +68,10 @@ { if (max == 0) return 0; - int log = ceilLog2(max) + 1; + if (max == std::numeric_limits::max()) + return genrand(); + + int log = ceilLog2(max + 1); int shift = (sizeof(uint32_t) * 8 - log); uint32_t random; @@ -83,7 +87,10 @@ { if (max == 0) return 0; - int log = ceilLog2(max) + 1; + if (max == std::numeric_limits::max()) + return genrand(); + + int log = ceilLog2(max + 1); int shift = (sizeof(uint64_t) * 8 - log); uint64_t random;