blob: c7254a9b4946e41f6e62d333af79bfd45dad5e96 [file] [log] [blame]
stefanc62642c2015-07-07 04:20:34 -07001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
solenberg5bdddf92015-10-15 05:10:30 -070011#ifndef WEBRTC_TEST_RANDOM_H_
12#define WEBRTC_TEST_RANDOM_H_
stefanc62642c2015-07-07 04:20:34 -070013
terelius56b11282015-11-06 05:13:55 -080014#include <limits>
15
stefanc62642c2015-07-07 04:20:34 -070016#include "webrtc/typedefs.h"
17#include "webrtc/base/constructormagic.h"
18
19namespace webrtc {
20
solenberg5bdddf92015-10-15 05:10:30 -070021namespace test {
22
stefanc62642c2015-07-07 04:20:34 -070023class Random {
24 public:
25 explicit Random(uint32_t seed);
26
terelius56b11282015-11-06 05:13:55 -080027 // Return pseudo-random integer of the specified type.
28 template <typename T>
29 T Rand() {
30 static_assert(std::numeric_limits<T>::is_integer &&
31 std::numeric_limits<T>::radix == 2 &&
32 std::numeric_limits<T>::digits <= 32,
33 "Rand is only supported for built-in integer types that are "
34 "32 bits or smaller.");
35 return static_cast<T>(Rand(std::numeric_limits<uint32_t>::max()));
36 }
stefanc62642c2015-07-07 04:20:34 -070037
terelius56b11282015-11-06 05:13:55 -080038 // Uniformly distributed pseudo-random number in the interval [0, t].
39 uint32_t Rand(uint32_t t);
40
41 // Uniformly distributed pseudo-random number in the interval [low, high].
42 uint32_t Rand(uint32_t low, uint32_t high);
solenberg5bdddf92015-10-15 05:10:30 -070043
stefanc62642c2015-07-07 04:20:34 -070044 // Normal Distribution.
45 int Gaussian(int mean, int standard_deviation);
46
solenberg5bdddf92015-10-15 05:10:30 -070047 // Exponential Distribution.
48 int Exponential(float lambda);
49
stefanc62642c2015-07-07 04:20:34 -070050 // TODO(solenberg): Random from histogram.
51 // template<typename T> int Distribution(const std::vector<T> histogram) {
52
53 private:
54 uint32_t a_;
55 uint32_t b_;
56
henrikg3c089d72015-09-16 05:37:44 -070057 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Random);
stefanc62642c2015-07-07 04:20:34 -070058};
terelius56b11282015-11-06 05:13:55 -080059
60// Return pseudo-random number in the interval [0.0, 1.0).
61template <>
62float Random::Rand<float>();
63
64// Return pseudo-random boolean value.
65template <>
66bool Random::Rand<bool>();
67
solenberg5bdddf92015-10-15 05:10:30 -070068} // namespace test
stefanc62642c2015-07-07 04:20:34 -070069} // namespace webrtc
70
solenberg5bdddf92015-10-15 05:10:30 -070071#endif // WEBRTC_TEST_RANDOM_H_