blob: 514894edaf7758289c42925a28d09f85e92b10aa [file] [log] [blame]
Johannc0e80952012-07-20 11:51:06 -07001/*
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
Johannc0e80952012-07-20 11:51:06 -070014#include <stdlib.h>
15
Johannfce8f062012-07-24 10:19:44 -070016#include "vpx/vpx_integer.h"
17
Johannc0e80952012-07-20 11:51:06 -070018namespace libvpx_test {
19
20class ACMRandom {
21 public:
Johannfbea8972012-06-28 11:43:58 -070022 ACMRandom() {
23 Reset(DeterministicSeed());
24 }
25
Johannc0e80952012-07-20 11:51:06 -070026 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_