]> granicus.if.org Git - libvpx/blob - test/acm_random.h
Merge "Reordering frame header probs." into experimental
[libvpx] / test / acm_random.h
1 /*
2  *  Copyright (c) 2012 The WebM 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
11 #ifndef LIBVPX_TEST_ACM_RANDOM_H_
12 #define LIBVPX_TEST_ACM_RANDOM_H_
13
14 #include <stdlib.h>
15
16 #include "vpx/vpx_integer.h"
17
18 namespace libvpx_test {
19
20 class ACMRandom {
21  public:
22   ACMRandom() {
23     Reset(DeterministicSeed());
24   }
25
26   explicit ACMRandom(int seed) {
27     Reset(seed);
28   }
29
30   void Reset(int seed) {
31     srand(seed);
32   }
33
34   uint8_t Rand8(void) {
35     return (rand() >> 8) & 0xff;
36   }
37
38   uint8_t Rand8Extremes(void) {
39     // Returns a random value near 0 or near 255, to better exercise
40     // saturation behavior.
41     const uint8_t r = Rand8();
42     return r < 128 ? r << 4 : r >> 4;
43   }
44
45   int PseudoUniform(int range) {
46     return (rand() >> 8) % range;
47   }
48
49   int operator()(int n) {
50     return PseudoUniform(n);
51   }
52
53   static int DeterministicSeed(void) {
54     return 0xbaba;
55   }
56 };
57
58 }  // namespace libvpx_test
59
60 #endif  // LIBVPX_TEST_ACM_RANDOM_H_