OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <new> | 10 #include <new> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Assigning a uint64_t to an int64_t is implementation defined, but this | 118 // Assigning a uint64_t to an int64_t is implementation defined, but this |
119 // should be OK. Use a static_cast to explicitly state that we know what we're | 119 // should be OK. Use a static_cast to explicitly state that we know what we're |
120 // doing. (Famous last words...) | 120 // doing. (Famous last words...) |
121 int64_t seed = static_cast<int64_t>((product + kAddend) & kMask); | 121 int64_t seed = static_cast<int64_t>((product + kAddend) & kMask); |
122 seed_ = seed; | 122 seed_ = seed; |
123 return static_cast<int>(seed >> (48 - bits)); | 123 return static_cast<int>(seed >> (48 - bits)); |
124 } | 124 } |
125 | 125 |
126 | 126 |
127 void RandomNumberGenerator::SetSeed(int64_t seed) { | 127 void RandomNumberGenerator::SetSeed(int64_t seed) { |
| 128 initial_seed_ = seed; |
128 seed_ = (seed ^ kMultiplier) & kMask; | 129 seed_ = (seed ^ kMultiplier) & kMask; |
129 } | 130 } |
130 | 131 |
131 } } // namespace v8::base | 132 } } // namespace v8::base |
OLD | NEW |