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

Unified Diff: test/cctest/test-api.cc

Issue 2760393002: Enable deterministic random number generation (Closed)
Patch Set: Initialize state directly Created 3 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:
Download patch
« no previous file with comments | « src/runtime/runtime-maths.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 85e877fc0d713d31d7fb555d68b096e5bdff5d72..aefcc5e2ad8f211007c12222ee095cb62eef0442 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -26369,3 +26369,28 @@ UNINITIALIZED_TEST(IncreaseHeapLimitForDebugging) {
}
isolate->Dispose();
}
+
+TEST(DeterministicRandomNumberGeneration) {
+ v8::HandleScope scope(CcTest::isolate());
+
+ int previous_seed = v8::internal::FLAG_random_seed;
+ v8::internal::FLAG_random_seed = 1234;
+
+ double first_value;
+ double second_value;
+ {
+ v8::Local<Context> context = Context::New(CcTest::isolate());
+ Context::Scope context_scope(context);
+ v8::Local<Value> result = CompileRun("Math.random();");
+ first_value = result->ToNumber(context).ToLocalChecked()->Value();
+ }
+ {
+ v8::Local<Context> context = Context::New(CcTest::isolate());
+ Context::Scope context_scope(context);
+ v8::Local<Value> result = CompileRun("Math.random();");
+ second_value = result->ToNumber(context).ToLocalChecked()->Value();
+ }
+ CHECK_EQ(first_value, second_value);
+
+ v8::internal::FLAG_random_seed = previous_seed;
+}
« no previous file with comments | « src/runtime/runtime-maths.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698