Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Unified Diff: webrtc/test/random.cc

Issue 1412183002: Fix off-by-one error in PRNG. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: made Rand() interval exclusive of 1.0 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/test/random.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/random.cc
diff --git a/webrtc/test/random.cc b/webrtc/test/random.cc
index 8877ed4c20c5bdfca2fcef03806f8b84d64b92bb..c4c405f6b8884732de3d3bc7e95ddb80f026190a 100644
--- a/webrtc/test/random.cc
+++ b/webrtc/test/random.cc
@@ -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) {
« no previous file with comments | « webrtc/test/random.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698