Merge "VP9: Refactor dec_build_inter_predictors_sb()"
[aom.git] / test / acm_random.h
blobff5c93ea1d4fe3fef7c2e37a1a3205d9906e04b8
1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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 */
11 #ifndef TEST_ACM_RANDOM_H_
12 #define TEST_ACM_RANDOM_H_
14 #include "third_party/googletest/src/include/gtest/gtest.h"
16 #include "vpx/vpx_integer.h"
18 namespace libvpx_test {
20 class ACMRandom {
21 public:
22 ACMRandom() : random_(DeterministicSeed()) {}
24 explicit ACMRandom(int seed) : random_(seed) {}
26 void Reset(int seed) {
27 random_.Reseed(seed);
29 uint16_t Rand16(void) {
30 const uint32_t value =
31 random_.Generate(testing::internal::Random::kMaxRange);
32 return (value >> 15) & 0xffff;
35 uint8_t Rand8(void) {
36 const uint32_t value =
37 random_.Generate(testing::internal::Random::kMaxRange);
38 // There's a bit more entropy in the upper bits of this implementation.
39 return (value >> 23) & 0xff;
42 uint8_t Rand8Extremes(void) {
43 // Returns a random value near 0 or near 255, to better exercise
44 // saturation behavior.
45 const uint8_t r = Rand8();
46 return r < 128 ? r << 4 : r >> 4;
49 int PseudoUniform(int range) {
50 return random_.Generate(range);
53 int operator()(int n) {
54 return PseudoUniform(n);
57 static int DeterministicSeed(void) {
58 return 0xbaba;
61 private:
62 testing::internal::Random random_;
65 } // namespace libvpx_test
67 #endif // TEST_ACM_RANDOM_H_