Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
xhwang
2015/11/10 00:50:01
2015
hubbe
2015/11/10 18:26:15
Done.
| |
| 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. | |
|
xhwang
2015/11/10 00:50:01
Could you please provide more context here why met
hubbe
2015/11/10 18:26:15
Done.
| |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 class TestRandom { | |
| 13 public: | |
| 14 explicit TestRandom(uint32 seed) { | |
|
xhwang
2015/11/10 00:50:01
nit: for new files use uint32_t as per style guide
hubbe
2015/11/10 18:26:15
Done.
| |
| 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 |