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

Unified Diff: src/math.js

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index efab63a186d4f8b924894dad9c1f0be59ef9846a..8c26f31a5548b95e1e2eb97798787fb187d36627 100644
--- a/src/math.js
+++ b/src/math.js
@@ -174,8 +174,14 @@ function MathPow(x, y) {
}
// ECMA 262 - 15.8.2.14
+// random0 and random1 are initialized during genesis.
function MathRandom() {
- return %_RandomHeapNumber();
+ var r0 = (MathImul(18273, random0 & 0xFFFF) + (random0 >>> 16)) | 0;
+ random0 = r0;
Michael Starzinger 2013/11/11 14:11:12 I am not sure about the sequence of the initializa
Sven Panne 2013/11/12 07:09:12 Done.
+ var r1 = (MathImul(36969, random1 & 0xFFFF) + (random1 >>> 16)) | 0;
+ random1 = r1;
+ var x = ((r0 << 14) + (r1 & 0x3FFFF)) | 0;
+ return (x < 0 ? (x + 0x100000000) : x) / 0x100000000;
}
// ECMA 262 - 15.8.2.15

Powered by Google App Engine
This is Rietveld 408576698