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

Unified Diff: webrtc/test/random.cc

Issue 1413053002: Change to use local Random object instead of global rand() in the RtcEventLog unit test. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updated WebRTC unit tests to use the new functions in Random 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
« webrtc/test/random.h ('K') | « 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 c4c405f6b8884732de3d3bc7e95ddb80f026190a..211439b6447309bcc9d2165ee65b60f73624c743 100644
--- a/webrtc/test/random.cc
+++ b/webrtc/test/random.cc
@@ -29,10 +29,18 @@ float Random::Rand() {
return static_cast<float>(result);
}
stefan-webrtc 2015/10/22 09:41:22 Should this be implemented using Uniform() instead
the sun 2015/10/22 12:30:38 Maybe the a_ ^= b_; b_ += a_; part could be put in
terelius 2015/10/26 18:18:41 Using Uniform(MAX_INT) would give the exact same r
terelius 2015/10/26 18:18:41 Considering it is only 2 simple lines I think it i
-int Random::Rand(int low, int high) {
+uint32_t Random::Uniform(uint32_t t) {
+ uint64_t result = t;
+ result = b_ * (result + 1);
+ result = result >> 32;
the sun 2015/10/22 12:30:38 Nice!
+ a_ ^= b_;
+ b_ += a_;
+ return result;
+}
+
+uint32_t Random::Uniform(uint32_t low, uint32_t high) {
RTC_DCHECK(low <= high);
- float uniform = Rand() * (high - low + 1) + low;
- return static_cast<int>(uniform);
+ return Uniform(high - low) + low;
}
int Random::Gaussian(int mean, int standard_deviation) {
« webrtc/test/random.h ('K') | « webrtc/test/random.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698