diff options
author | Ali Saidi <Ali.Saidi@ARM.com> | 2010-08-23 11:18:39 -0500 |
---|---|---|
committer | Ali Saidi <Ali.Saidi@ARM.com> | 2010-08-23 11:18:39 -0500 |
commit | 7d191366e1b8c3efaf2a08b26483bca82c00e4de (patch) | |
tree | b0fd576a91dd109006d915a7c8e846236686a352 /src/base/random.cc | |
parent | 77937738096e227ebfe5bd2fb999c35032c2c8c4 (diff) | |
download | gem5-7d191366e1b8c3efaf2a08b26483bca82c00e4de.tar.xz |
BASE: Fix genrand to generate both 0s and 1s when max equals one.
previously was only generating 0s.
Diffstat (limited to 'src/base/random.cc')
-rw-r--r-- | src/base/random.cc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/base/random.cc b/src/base/random.cc index 7daa90b9c..457b0c98b 100644 --- a/src/base/random.cc +++ b/src/base/random.cc @@ -65,7 +65,9 @@ Random::~Random() uint32_t Random::genrand(uint32_t max) { - int log = ceilLog2(max); + if (max == 0) + return 0; + int log = ceilLog2(max) + 1; int shift = (sizeof(uint32_t) * 8 - log); uint32_t random; @@ -79,7 +81,9 @@ Random::genrand(uint32_t max) uint64_t Random::genrand(uint64_t max) { - int log = ceilLog2(max); + if (max == 0) + return 0; + int log = ceilLog2(max) + 1; int shift = (sizeof(uint64_t) * 8 - log); uint64_t random; |