Johann | c0e8095 | 2012-07-20 11:51:06 -0700 | [diff] [blame] | 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 | |
Johann | c0e8095 | 2012-07-20 11:51:06 -0700 | [diff] [blame] | 14 | #include <stdlib.h> |
| 15 | |
Johann | fce8f06 | 2012-07-24 10:19:44 -0700 | [diff] [blame] | 16 | #include "vpx/vpx_integer.h" |
| 17 | |
Johann | c0e8095 | 2012-07-20 11:51:06 -0700 | [diff] [blame] | 18 | namespace libvpx_test { |
| 19 | |
| 20 | class ACMRandom { |
| 21 | public: |
Johann | fbea897 | 2012-06-28 11:43:58 -0700 | [diff] [blame^] | 22 | ACMRandom() { |
| 23 | Reset(DeterministicSeed()); |
| 24 | } |
| 25 | |
Johann | c0e8095 | 2012-07-20 11:51:06 -0700 | [diff] [blame] | 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_ |