Fix off-by-one error in PRNG.

BUG=

Review URL: https://codereview.webrtc.org/1412183002

Cr-Commit-Position: refs/heads/master@{#10328}
This commit is contained in:
solenberg 2015-10-19 14:07:44 -07:00 committed by Commit bot
parent 86721fef6c
commit 0d97d53808
2 changed files with 5 additions and 5 deletions

View File

@ -22,11 +22,11 @@ Random::Random(uint32_t seed) : a_(0x531FDB97 ^ seed), b_(0x6420ECA8 + seed) {
}
float Random::Rand() {
const float kScale = 1.0f / 0xffffffff;
float result = kScale * b_;
const double kScale = 1.0f / (static_cast<uint64_t>(1) << 32);
double result = kScale * b_;
a_ ^= b_;
b_ += a_;
return result;
return static_cast<float>(result);
}
int Random::Rand(int low, int high) {

View File

@ -22,10 +22,10 @@ class Random {
public:
explicit Random(uint32_t seed);
// Return pseudo-random number in the interval [0.0, 1.0].
// Return pseudo-random number in the interval [0.0, 1.0).
float Rand();
// Return pseudo rounded random number in interval [low, high].
// Return pseudo-random number mapped to the interval [low, high].
int Rand(int low, int high);
// Normal Distribution.