]> granicus.if.org Git - libvpx/blob - test/acm_random.h
Merge with upstream experimental changes (2)
[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   int PseudoUniform(int range) {
39     return (rand() >> 8) % range;
40   }
41
42   int operator()(int n) {
43     return PseudoUniform(n);
44   }
45
46   static int DeterministicSeed(void) {
47     return 0xbaba;
48   }
49 };
50
51 }  // namespace libvpx_test
52
53 #endif  // LIBVPX_TEST_ACM_RANDOM_H_