OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 // Vastly simplified ACM random class meant to only be used for testing. |
| 9 |
| 10 namespace media { |
| 11 |
| 12 class TestRandom { |
| 13 public: |
| 14 explicit TestRandom(uint32 seed) { |
| 15 seed_ = seed & 0x7fffffff; // make this a non-negative number |
| 16 if (seed_ == 0 || seed_ == M) { |
| 17 seed_ = 1; |
| 18 } |
| 19 } |
| 20 |
| 21 int32 Rand() { |
| 22 static const uint64 A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 |
| 23 seed_ = static_cast<int32>((seed_ * A) % M); |
| 24 CHECK_GT(seed_, 0); |
| 25 return seed_; |
| 26 } |
| 27 |
| 28 private: |
| 29 static const uint64 M = 2147483647L; // 2^32-1 |
| 30 int32 seed_; |
| 31 }; |
| 32 |
| 33 } // namespace media |
| 34 |
| 35 #endif // MEDIA_BLINK_TEST_RANDOM_H_ |
OLD | NEW |