Move PRNG from BWE test framework to webrtc/test.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#10285}
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc b/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
index c7d1297..dcad04b 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
@@ -20,8 +20,8 @@
 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h"
 #include "webrtc/modules/remote_bitrate_estimator/rate_statistics.h"
-#include "webrtc/modules/remote_bitrate_estimator/test/random.h"
 #include "webrtc/test/field_trial.h"
+#include "webrtc/test/random.h"
 #include "webrtc/test/testsupport/gtest_disable.h"
 
 namespace webrtc {
@@ -114,7 +114,7 @@
   rtc::scoped_ptr<OveruseDetector> overuse_detector_;
   rtc::scoped_ptr<OveruseEstimator> overuse_estimator_;
   rtc::scoped_ptr<InterArrival> inter_arrival_;
-  Random random_;
+  test::Random random_;
 };
 
 TEST_F(OveruseDetectorTest, GaussianRandom) {
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
index dbc5882..d2af81e 100644
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
@@ -85,8 +85,6 @@
             'test/packet_sender.cc',
             'test/packet_sender.h',
             'test/packet.h',
-            'test/random.cc',
-            'test/random.h',
             'test/estimators/nada.cc',
             'test/estimators/nada.h',
             'test/estimators/remb.cc',
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test.cc b/webrtc/modules/remote_bitrate_estimator/test/bwe_test.cc
index 72283b9..9d71323 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test.cc
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test.cc
@@ -947,7 +947,7 @@
   const int kMinKbytes = 100;
   const int kMaxKbytes = 1000;
 
-  Random random(0x12345678);
+  test::Random random(0x12345678);
   std::vector<int> tcp_file_sizes_bytes;
 
   while (num_files-- > 0) {
@@ -960,7 +960,7 @@
 std::vector<int64_t> BweTest::GetStartingTimesMs(int num_files) {
   // OFF state behaves as an exp. distribution with mean = 10 seconds.
   const float kMeanMs = 10000.0f;
-  Random random(0x12345678);
+  test::Random random(0x12345678);
 
   std::vector<int64_t> tcp_starting_times_ms;
 
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc
index d420193..4574d3d 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc
@@ -92,41 +92,6 @@
   return static_cast<double>(window_size_us_) / (1000 * 1000);
 }
 
-Random::Random(uint32_t seed) : a_(0x531FDB97 ^ seed), b_(0x6420ECA8 + seed) {
-}
-
-float Random::Rand() {
-  const float kScale = 1.0f / 0xffffffff;
-  float result = kScale * b_;
-  a_ ^= b_;
-  b_ += a_;
-  return result;
-}
-
-int Random::Rand(int low, int high) {
-  float uniform = Rand() * (high - low + 1) + low;
-  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
-  // interval (0, 1], hence the mask+add below.
-  const double kPi = 3.14159265358979323846;
-  const double kScale = 1.0 / 0x80000000ul;
-  double u1 = kScale * ((a_ & 0x7ffffffful) + 1);
-  double u2 = kScale * ((b_ & 0x7ffffffful) + 1);
-  a_ ^= b_;
-  b_ += a_;
-  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);
-}
-
 Packet::Packet()
     : flow_id_(0),
       creation_time_us_(-1),
@@ -426,7 +391,7 @@
 }
 
 namespace {
-inline int64_t TruncatedNSigmaGaussian(Random* const random,
+inline int64_t TruncatedNSigmaGaussian(test::Random* const random,
                                        int64_t mean,
                                        int64_t std_dev) {
   int64_t gaussian_random = random->Gaussian(mean, std_dev);
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h
index 77b03fe..1362c87 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h
@@ -29,9 +29,9 @@
 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
 #include "webrtc/modules/remote_bitrate_estimator/test/packet.h"
-#include "webrtc/modules/remote_bitrate_estimator/test/random.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
 #include "webrtc/system_wrappers/interface/clock.h"
+#include "webrtc/test/random.h"
 
 namespace webrtc {
 
@@ -173,32 +173,6 @@
   T max_;
 };
 
-class Random {
- public:
-  explicit Random(uint32_t seed);
-
-  // Return pseudo random number in the interval [0.0, 1.0].
-  float Rand();
-
-  // Return pseudo rounded random number in interval [low, high].
-  int Rand(int low, int high);
-
-  // Normal Distribution.
-  int Gaussian(int mean, int standard_deviation);
-
-  // Exponential Distribution.
-  int Exponential(float lambda);
-
-  // TODO(solenberg): Random from histogram.
-  // template<typename T> int Distribution(const std::vector<T> histogram) {
-
- private:
-  uint32_t a_;
-  uint32_t b_;
-
-  RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Random);
-};
-
 bool IsTimeSorted(const Packets& packets);
 
 class PacketProcessor;
@@ -291,7 +265,7 @@
   virtual void RunFor(int64_t time_ms, Packets* in_out);
 
  private:
-  Random random_;
+  test::Random random_;
   float loss_fraction_;
 
   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LossFilter);
@@ -325,7 +299,7 @@
   int64_t MeanUs();
 
  private:
-  Random random_;
+  test::Random random_;
   int64_t stddev_jitter_us_;
   int64_t last_send_time_us_;
   bool reordering_;  // False by default.
@@ -344,7 +318,7 @@
   virtual void RunFor(int64_t time_ms, Packets* in_out);
 
  private:
-  Random random_;
+  test::Random random_;
   float reorder_fraction_;
 
   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ReorderFilter);
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc
index 6cd6ee7..6272606 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc
@@ -30,7 +30,7 @@
     kStddev = 10
   };
 
-  Random random(0x12345678);
+  test::Random random(0x12345678);
 
   int buckets[kBuckets] = {0};
   for (int i = 0; i < kN; ++i) {
diff --git a/webrtc/modules/remote_bitrate_estimator/test/random.cc b/webrtc/test/random.cc
similarity index 76%
rename from webrtc/modules/remote_bitrate_estimator/test/random.cc
rename to webrtc/test/random.cc
index d803be0..8877ed4 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 @@
   return result;
 }
 
+int Random::Rand(int low, int high) {
+  RTC_DCHECK(low <= high);
+  float uniform = Rand() * (high - low + 1) + low;
+  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 @@
   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
diff --git a/webrtc/modules/remote_bitrate_estimator/test/random.h b/webrtc/test/random.h
similarity index 76%
rename from webrtc/modules/remote_bitrate_estimator/test/random.h
rename to webrtc/test/random.h
index 31c1ec1..9a0bc9e 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/random.h
+++ b/webrtc/test/random.h
@@ -8,14 +8,16 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_RANDOM_H_
-#define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_RANDOM_H_
+#ifndef WEBRTC_TEST_RANDOM_H_
+#define WEBRTC_TEST_RANDOM_H_
 
 #include "webrtc/typedefs.h"
 #include "webrtc/base/constructormagic.h"
 
 namespace webrtc {
 
+namespace test {
+
 class Random {
  public:
   explicit Random(uint32_t seed);
@@ -23,9 +25,15 @@
   // Return pseudo-random number in the interval [0.0, 1.0].
   float Rand();
 
+  // Return pseudo rounded random number in interval [low, high].
+  int Rand(int low, int high);
+
   // Normal Distribution.
   int Gaussian(int mean, int standard_deviation);
 
+  // Exponential Distribution.
+  int Exponential(float lambda);
+
   // TODO(solenberg): Random from histogram.
   // template<typename T> int Distribution(const std::vector<T> histogram) {
 
@@ -35,6 +43,7 @@
 
   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Random);
 };
+}  // namespace test
 }  // namespace webrtc
 
-#endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_RANDOM_H_
+#endif  // WEBRTC_TEST_RANDOM_H_
diff --git a/webrtc/test/webrtc_test_common.gyp b/webrtc/test/webrtc_test_common.gyp
index 17f4551..f8d3365 100644
--- a/webrtc/test/webrtc_test_common.gyp
+++ b/webrtc/test/webrtc_test_common.gyp
@@ -37,6 +37,8 @@
         'mock_transport.h',
         'null_transport.cc',
         'null_transport.h',
+        'random.cc',
+        'random.h',
         'rtp_rtcp_observer.h',
         'run_loop.cc',
         'run_loop.h',