Revision: 4245
Author: [email protected]
Date: Wed Mar 24 03:32:23 2010
Log: Added flag for seeding the random generator deterministically.

Review URL: http://codereview.chromium.org/1247003
http://code.google.com/p/v8/source/detail?r=4245

Modified:
 /branches/bleeding_edge/src/flag-definitions.h
 /branches/bleeding_edge/src/v8.cc

=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Tue Mar 23 08:04:45 2010
+++ /branches/bleeding_edge/src/flag-definitions.h      Wed Mar 24 03:32:23 2010
@@ -205,6 +205,9 @@
             "Flush inline caches prior to mark compact collection.")
 DEFINE_bool(cleanup_caches_in_maps_at_gc, true,
             "Flush code caches in maps during mark compact cycle.")
+DEFINE_int(random_seed, 0,
+           "Default seed for initializing random generator "
+           "(0, the default, means to use system random).")

 DEFINE_bool(canonicalize_object_literal_maps, true,
             "Canonicalize maps for object literals.")
=======================================
--- /branches/bleeding_edge/src/v8.cc   Wed Mar 17 07:53:16 2010
+++ /branches/bleeding_edge/src/v8.cc   Wed Mar 24 03:32:23 2010
@@ -153,6 +153,14 @@
   is_running_ = false;
   has_been_disposed_ = true;
 }
+
+
+static uint32_t random_seed() {
+  if (FLAG_random_seed == 0) {
+    return random();
+  }
+  return FLAG_random_seed;
+}


 uint32_t V8::Random() {
@@ -164,8 +172,8 @@
   // 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);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

To unsubscribe from this group, send email to v8-dev+unsubscribegooglegroups.com or reply 
to this email with the words "REMOVE ME" as the subject.

Reply via email to