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) { |