Chromium Code Reviews| Index: webrtc/test/random.cc |
| diff --git a/webrtc/modules/remote_bitrate_estimator/test/random.cc b/webrtc/test/random.cc |
| similarity index 77% |
| rename from webrtc/modules/remote_bitrate_estimator/test/random.cc |
| rename to webrtc/test/random.cc |
| index d803be063685887b238c4fbd40277cb52cd62e70..8877ed4c20c5bdfca2fcef03806f8b84d64b92bb 100644 |
| --- a/webrtc/modules/remote_bitrate_estimator/test/random.cc |
| +++ b/webrtc/test/random.cc |
| @@ -8,12 +8,16 @@ |
| * be found in the AUTHORS file in the root of the source tree. |
| */ |
| -#include "webrtc/modules/remote_bitrate_estimator/test/random.h" |
| +#include "webrtc/test/random.h" |
| #include <math.h> |
| +#include "webrtc/base/checks.h" |
| + |
| namespace webrtc { |
| +namespace test { |
| + |
| Random::Random(uint32_t seed) : a_(0x531FDB97 ^ seed), b_(0x6420ECA8 + seed) { |
| } |
| @@ -25,6 +29,12 @@ float Random::Rand() { |
| return result; |
| } |
| +int Random::Rand(int low, int high) { |
| + RTC_DCHECK(low <= high); |
| + float uniform = Rand() * (high - low + 1) + low; |
|
pbos-webrtc
2015/10/19 13:33:01
Then this one has off-by-one errors?
for Rand() =
the sun
2015/10/19 15:10:25
Looks like that. Good catch!
https://codereview.we
|
| + return static_cast<int>(uniform); |
| +} |
| + |
| int Random::Gaussian(int mean, int standard_deviation) { |
| // Creating a Normal distribution variable from two independent uniform |
| // variables based on the Box-Muller transform, which is defined on the |
| @@ -38,4 +48,10 @@ int Random::Gaussian(int mean, int standard_deviation) { |
| return static_cast<int>( |
| mean + standard_deviation * sqrt(-2 * log(u1)) * cos(2 * kPi * u2)); |
| } |
| + |
| +int Random::Exponential(float lambda) { |
| + float uniform = Rand(); |
| + return static_cast<int>(-log(uniform) / lambda); |
| +} |
| +} // namespace test |
| } // namespace webrtc |