Index: webrtc/test/random.h |
diff --git a/webrtc/test/random.h b/webrtc/test/random.h |
index 5cc54f212970c8269cf2093c199ef6be55fb4a45..c7254a9b4946e41f6e62d333af79bfd45dad5e96 100644 |
--- a/webrtc/test/random.h |
+++ b/webrtc/test/random.h |
@@ -11,6 +11,8 @@ |
#ifndef WEBRTC_TEST_RANDOM_H_ |
#define WEBRTC_TEST_RANDOM_H_ |
+#include <limits> |
+ |
#include "webrtc/typedefs.h" |
#include "webrtc/base/constructormagic.h" |
@@ -22,11 +24,22 @@ class Random { |
public: |
explicit Random(uint32_t seed); |
- // Return pseudo-random number in the interval [0.0, 1.0). |
- float Rand(); |
+ // Return pseudo-random integer of the specified type. |
+ template <typename T> |
+ T Rand() { |
+ static_assert(std::numeric_limits<T>::is_integer && |
+ std::numeric_limits<T>::radix == 2 && |
+ std::numeric_limits<T>::digits <= 32, |
+ "Rand is only supported for built-in integer types that are " |
+ "32 bits or smaller."); |
+ return static_cast<T>(Rand(std::numeric_limits<uint32_t>::max())); |
+ } |
+ |
+ // Uniformly distributed pseudo-random number in the interval [0, t]. |
+ uint32_t Rand(uint32_t t); |
- // Return pseudo-random number mapped to the interval [low, high]. |
- int Rand(int low, int high); |
+ // Uniformly distributed pseudo-random number in the interval [low, high]. |
+ uint32_t Rand(uint32_t low, uint32_t high); |
// Normal Distribution. |
int Gaussian(int mean, int standard_deviation); |
@@ -43,6 +56,15 @@ class Random { |
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Random); |
}; |
+ |
+// Return pseudo-random number in the interval [0.0, 1.0). |
+template <> |
+float Random::Rand<float>(); |
+ |
+// Return pseudo-random boolean value. |
+template <> |
+bool Random::Rand<bool>(); |
+ |
} // namespace test |
} // namespace webrtc |