OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 Top::TearDown(); | 131 Top::TearDown(); |
132 | 132 |
133 Heap::TearDown(); | 133 Heap::TearDown(); |
134 Logger::TearDown(); | 134 Logger::TearDown(); |
135 | 135 |
136 is_running_ = false; | 136 is_running_ = false; |
137 has_been_disposed_ = true; | 137 has_been_disposed_ = true; |
138 } | 138 } |
139 | 139 |
140 | 140 |
141 uint32_t V8::Random() { | |
142 // Random number generator using George Marsaglia's | |
143 // multiply-with-carry algorithm. | |
144 static uint32_t hi = 0; | |
145 static uint32_t lo = 0; | |
Dean McNamee
2009/06/15 07:39:25
why not just static uint32_t hi = random() ?
| |
146 | |
147 // Initialize seed using the system random(). | |
148 if (hi == 0) hi = random(); | |
149 if (lo == 0) lo = random(); | |
150 | |
151 // Mix the bits. | |
152 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); | |
153 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); | |
154 return (hi << 16) + (lo & 0xFFFF); | |
155 } | |
156 | |
157 | |
158 Smi* V8::RandomPositiveSmi() { | |
159 uint32_t random = Random(); | |
160 ASSERT(IsPowerOf2(Smi::kMaxValue + 1)); | |
161 return Smi::FromInt(random & Smi::kMaxValue); | |
162 } | |
163 | |
141 } } // namespace v8::internal | 164 } } // namespace v8::internal |
OLD | NEW |