Summary: | REGRESSION(r192855): Math.random() always produces the same first 7 decimal points the first two invocations | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Joseph Pecoraro <joepeck> | ||||
Component: | JavaScriptCore | Assignee: | Joseph Pecoraro <joepeck> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | achristensen, benjamin, cdumez, cmarcelo, commit-queue, fpizlo, ggaren, joepeck, mark.lam, sam, webkit-bug-importer | ||||
Priority: | P2 | Keywords: | InRadar | ||||
Version: | WebKit Nightly Build | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
Attachments: |
|
Description
Joseph Pecoraro
2016-05-17 11:48:28 PDT
Wow, that's hilarious. Caused by r192855: <http://trac.webkit.org/changeset/192855> Probably too many zeroes in the initial seed, since our seed API is 32 bit. You can probably fix this by: uint64_t seed64 = seed; m_low = (seed64 << 32) | seed64; m_high = (seed64 << 32) | seed64; Or you could update the seed API to be 128bit. (In reply to comment #3) > Probably too many zeroes in the initial seed, since our seed API is 32 bit. > You can probably fix this by: > > uint64_t seed64 = seed; > m_low = (seed64 << 32) | seed64; > m_high = (seed64 << 32) | seed64; > After this the first 4 digits stayed nearly identical: >>> Math.random() 0.41647092963078913 >>> Math.random() 0.41646612834590113 >>> Math.random() 0.47840231815551537 >>> Math.random() 0.47839187513838377 How about we just advance once after setting the seed? m_low = seed; m_high = seed; advance(); Do you see any disadvantages to this? > How about we just advance once after setting the seed?
>
> m_low = seed;
> m_high = seed;
> advance();
>
> Do you see any disadvantages to this?
LOL. Brain fart. It's guaranteed that no better solution is possible.
We have 128 bits of state that we want to set based on 32 bits of input. All solutions to this problem include some kind of bias unless they are... random!
Created attachment 279167 [details]
[PATCH] Proposed Fix
An alternative test approach could be TestWebKitAPI creating a WeakRandom, or a jsc API that allows setting the random seed. But this tests Math.random which is web exposed so probably the safest. Comment on attachment 279167 [details]
[PATCH] Proposed Fix
EWS failure seems spurious.
Comment on attachment 279167 [details] [PATCH] Proposed Fix Clearing flags on attachment: 279167 Committed r201053: <http://trac.webkit.org/changeset/201053> All reviewed patches have been landed. Closing bug. |