2012-07-20 22:51:06 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
2013-09-05 19:45:56 +04:00
|
|
|
#ifndef TEST_ACM_RANDOM_H_
|
|
|
|
#define TEST_ACM_RANDOM_H_
|
2012-07-20 22:51:06 +04:00
|
|
|
|
2013-04-05 06:00:31 +04:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2012-07-20 22:51:06 +04:00
|
|
|
|
2012-07-24 21:19:44 +04:00
|
|
|
#include "vpx/vpx_integer.h"
|
|
|
|
|
2012-07-20 22:51:06 +04:00
|
|
|
namespace libvpx_test {
|
|
|
|
|
|
|
|
class ACMRandom {
|
|
|
|
public:
|
2013-04-05 06:00:31 +04:00
|
|
|
ACMRandom() : random_(DeterministicSeed()) {}
|
2012-06-28 22:43:58 +04:00
|
|
|
|
2013-04-05 06:00:31 +04:00
|
|
|
explicit ACMRandom(int seed) : random_(seed) {}
|
2012-07-20 22:51:06 +04:00
|
|
|
|
|
|
|
void Reset(int seed) {
|
2013-04-05 06:00:31 +04:00
|
|
|
random_.Reseed(seed);
|
2012-07-20 22:51:06 +04:00
|
|
|
}
|
2013-12-13 22:05:40 +04:00
|
|
|
uint16_t Rand16(void) {
|
|
|
|
const uint32_t value =
|
|
|
|
random_.Generate(testing::internal::Random::kMaxRange);
|
2014-12-02 02:10:00 +03:00
|
|
|
return (value >> 15) & 0xffff;
|
2013-12-13 22:05:40 +04:00
|
|
|
}
|
2012-07-20 22:51:06 +04:00
|
|
|
|
|
|
|
uint8_t Rand8(void) {
|
2013-04-05 06:00:31 +04:00
|
|
|
const uint32_t value =
|
|
|
|
random_.Generate(testing::internal::Random::kMaxRange);
|
|
|
|
// There's a bit more entropy in the upper bits of this implementation.
|
2014-11-27 02:17:49 +03:00
|
|
|
return (value >> 23) & 0xff;
|
2012-07-20 22:51:06 +04:00
|
|
|
}
|
|
|
|
|
2013-04-19 00:05:38 +04:00
|
|
|
uint8_t Rand8Extremes(void) {
|
|
|
|
// Returns a random value near 0 or near 255, to better exercise
|
|
|
|
// saturation behavior.
|
|
|
|
const uint8_t r = Rand8();
|
|
|
|
return r < 128 ? r << 4 : r >> 4;
|
|
|
|
}
|
|
|
|
|
2012-07-20 22:51:06 +04:00
|
|
|
int PseudoUniform(int range) {
|
2013-04-05 06:00:31 +04:00
|
|
|
return random_.Generate(range);
|
2012-07-20 22:51:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int operator()(int n) {
|
|
|
|
return PseudoUniform(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int DeterministicSeed(void) {
|
|
|
|
return 0xbaba;
|
|
|
|
}
|
2013-04-05 06:00:31 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
testing::internal::Random random_;
|
2012-07-20 22:51:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace libvpx_test
|
|
|
|
|
2013-09-05 19:45:56 +04:00
|
|
|
#endif // TEST_ACM_RANDOM_H_
|