WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 151641
Use a better RNG for Math.random()
https://bugs.webkit.org/show_bug.cgi?id=151641
Summary
Use a better RNG for Math.random()
Jan de Mooij
Reported
2015-11-28 05:51:36 PST
The GameRand-based RNG Safari/JSC uses is very weak. Furthermore, it only uses 32 bits of precision. I blogged about this here:
http://jandemooij.nl/blog/2015/11/27/math-random-and-32-bit-precision/
V8 moved to a better RNG and we're switching the one in SpiderMonkey as well. JSC should probably do the same.
Attachments
Patch
(7.13 KB, patch)
2015-11-30 17:01 PST
,
Geoffrey Garen
andersca
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Oliver Hunt
Comment 1
2015-11-28 09:55:10 PST
If we really do consider more than 32bits necessary id just move up to a 64bit variant of gamerand which should not have a significant perf impact, then value & (2^53-1) / 2^53 (I can recall if the rand includes 1 as a valid result). Has someone done something to find it's aggressively non-uniform in some space?
Geoffrey Garen
Comment 2
2015-11-30 17:01:13 PST
Created
attachment 266302
[details]
Patch
Geoffrey Garen
Comment 3
2015-11-30 17:04:17 PST
I kind of wanted to stick with GameRandom in order to troll the internet commentators who keep confusing / conflating RNG algorithm with number of bits provided by RNG interface. But there's literally no downside to upgrading to Xorshift+, so I've done it.
Anders Carlsson
Comment 4
2015-11-30 17:10:54 PST
Comment on
attachment 266302
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=266302&action=review
> Source/WTF/ChangeLog:10 > + prevents programs that mulitply a random number by a large constant from
typo, multiply.
Geoffrey Garen
Comment 5
2015-11-30 19:40:09 PST
Committed
r192855
: <
http://trac.webkit.org/changeset/192855
>
Jan de Mooij
Comment 6
2015-12-01 00:27:11 PST
(In reply to
comment #3
)
> I kind of wanted to stick with GameRandom in order to troll the internet > commentators who keep confusing / conflating RNG algorithm with number of > bits provided by RNG interface.
It's not just that; GameRand also doesn't do well in statistical tests:
http://jandemooij.nl/blog/2015/11/30/testing-math-random-crushing-the-browser/
No big deal probably, but it shows the algorithm has other issues.
> But there's literally no downside to upgrading to Xorshift+, so I've done it.
\o/
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug