Review Board 2.0.15


BASE: Fix genrand to generate both 0s and 1s when max equals one.

Review Request #157 - Created Aug. 13, 2010 and submitted

Information
Ali Saidi
gem5
Reviewers
Default
BASE: Fix genrand to generate both 0s and 1s when max equals one.
previously was only generating 0s.

   
Posted (Aug. 13, 2010, 8:57 a.m.)
Is this right?  Seems like genrand(1) and genrand(2) will now do the same thing.  Should we be calling ceilLog2(max+1) instead?
  1. You're right Steve, it still fails on powers of two. I tested from 0 to 10 and it was correct with ceilLog2(max) + 1, so I'll go with that.
  2. I'm happy to review an updated diff if you like.
  3. It just turned into:
        if (max == 0)
            return 0;
        int log = ceilLog2(max) + 1;
    
    I tested it for max = 0 to max = 10 and it produced the appropriate results each time. The previous change would fail on powers of two.