Commit 2443c09d authored by ggaren's avatar ggaren

Reviewed by mjs.

        - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4026
        Math.random() not seeded.

        Added call to sranddev() -- it executes the first time a process
        calls Math.random().

        * kjs/math_object.cpp:
        (MathFuncImp::callAsFunction):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@11801 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4392ffac
2005-12-29 Geoffrey Garen <ggaren@apple.com>
Reviewed by mjs.
- Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4026
Math.random() not seeded.
Added call to sranddev() -- it executes the first time a process
calls Math.random().
* kjs/math_object.cpp:
(MathFuncImp::callAsFunction):
2005-12-29 Geoffrey Garen <ggaren@apple.com>
Reviewed by darin.
......
......@@ -23,6 +23,7 @@
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include "value.h"
#include "object.h"
......@@ -150,6 +151,8 @@ JSValue *MathObjectImp::getValueProperty(ExecState *, int token) const
// ------------------------------ MathObjectImp --------------------------------
static bool randomSeeded = false;
MathFuncImp::MathFuncImp(ExecState *exec, int i, int l)
: InternalFunctionImp(
static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())
......@@ -258,9 +261,12 @@ JSValue *MathFuncImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, con
result = ::pow(arg, arg2);
break;
case MathObjectImp::Random:
result = ::rand();
result = result / RAND_MAX;
break;
if (!randomSeeded) {
sranddev();
randomSeeded = true;
}
result = (double)rand() / RAND_MAX;
break;
case MathObjectImp::Round:
if (signbit(arg) && arg >= -0.5)
result = -0.0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment