| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BLINK_TEST_RANDOM_H_ | |
| 6 #define MEDIA_BLINK_TEST_RANDOM_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 // Vastly simplified ACM random class meant to only be used for testing. | |
| 11 // This class is meant to generate predictable sequences of pseudorandom | |
| 12 // numbers, unlike the classes in base/rand_util.h which are meant to generate | |
| 13 // unpredictable sequences. | |
| 14 // See | |
| 15 // https://code.google.com/p/szl/source/browse/trunk/src/utilities/acmrandom.h | |
| 16 // for more information. | |
| 17 | |
| 18 namespace media { | |
| 19 | |
| 20 class TestRandom { | |
| 21 public: | |
| 22 explicit TestRandom(uint32_t seed) { | |
| 23 seed_ = seed & 0x7fffffff; // make this a non-negative number | |
| 24 if (seed_ == 0 || seed_ == M) { | |
| 25 seed_ = 1; | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 int32_t Rand() { | |
| 30 static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 | |
| 31 seed_ = static_cast<int32_t>((seed_ * A) % M); | |
| 32 CHECK_GT(seed_, 0); | |
| 33 return seed_; | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 static const uint64_t M = 2147483647L; // 2^32-1 | |
| 38 int32_t seed_; | |
| 39 }; | |
| 40 | |
| 41 } // namespace media | |
| 42 | |
| 43 #endif // MEDIA_BLINK_TEST_RANDOM_H_ | |
| OLD | NEW |