Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2171)

Unified Diff: src/v8.cc

Issue 1247003: Added flag for seeding the random generator deterministically. (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8.cc
diff --git a/src/v8.cc b/src/v8.cc
index 395401d91b2c575ccfe1ca009e403eb3d7b5cc6f..5af200348b4058e4c65075dc4d58102393f63fd9 100644
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -155,6 +155,14 @@ void V8::TearDown() {
}
+static uint32_t random_seed() {
+ if (FLAG_random_seed == 0) {
+ return random();
+ }
+ return FLAG_random_seed;
+}
+
+
uint32_t V8::Random() {
// Random number generator using George Marsaglia's MWC algorithm.
static uint32_t hi = 0;
@@ -164,8 +172,8 @@ uint32_t V8::Random() {
// should ever become zero again, or if random() returns zero, we
// avoid getting stuck with zero bits in hi or lo by re-initializing
// them on demand.
- if (hi == 0) hi = random();
- if (lo == 0) lo = random();
+ if (hi == 0) hi = random_seed();
+ if (lo == 0) lo = random_seed();
// Mix the bits.
hi = 36969 * (hi & 0xFFFF) + (hi >> 16);
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698