Commit 7a861287 authored by lrn@chromium.org's avatar lrn@chromium.org

Added flag for seeding the random generator deterministically.

Review URL: http://codereview.chromium.org/1247003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4245 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d219d68b
......@@ -205,6 +205,9 @@ DEFINE_bool(cleanup_ics_at_gc, true,
"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.")
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment