[Webkit-unassigned] [Bug 22595] New: Strange Math.random() behavior (firs time almost always returns approx same number)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Dec 2 11:47:44 PST 2008


           Summary: Strange Math.random() behavior (firs time almost always
                    returns approx same number)
           Product: WebKit
           Version: 525.x (Safari 3.1)
          Platform: Macintosh
        OS/Version: Mac OS X 10.5
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: dylanryan at mac.com

Math.random() seems to always return a very similar number the first time it is
called. This happens both in the browser (a serious problem) and in JSC (less
of an issue but easier to test).

First, to verify the problem in the browser. 
Step 1: Set your Safari preferences so that "new windows open with" a blank
Step 2: Quit (you must quit!) Safari.
Step 3: Relaunch Safari. 
Step 4: Enter javascript:alert(Math.random()) into the address bar and press
Step 5: Note the number it spits out (at least the first 4 or 5 digits)
repeat steps 2-5 multiple times (you MUST QUIT between tries). 

Notice how the numbers are almost identical?

The JavaScript shell exhibits the same behavior, and is much easier to test

It looks like the first invocation of Math.random() is on a slow increment,
changing at 4 or 5 places past the decimal approx. every second. The following
bash script shows this nicely [obviously, change if jsc is in a different place
on your computer]:

#! /bin/bash
while (( i < 500 ))
        echo "Math.random();" |

I'd hazard a guess that the first invocation simply returns the current
timestamp, modified in some manner, but I have no basis for this other than
seeing the numbers change every second. 

Firefox does NOT exhibit this same behavior. The WebKit nightlies do exhibit
the same behavior as Safari, but you have to disable the WebKit start page in
order to get a blank page to load.

Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

More information about the webkit-unassigned mailing list