diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-10-29 11:42:58 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 14:05:57 +0100 |
commit | 9b18946f22b8fc15a1223378112a53b2089380cf (patch) | |
tree | 68c14352dc22456f6af615f411b06508c9fcdd75 /src/qml/jsruntime/qv4mathobject.cpp | |
parent | 192cb97fa6229b8e2b149e90ac49dddd228405d4 (diff) |
Seed Math.random in v4
Task-number: QTBUG-34105
Change-Id: I6cb5c8b80f158677aaf334feeaa206a5eaf9cfc3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4mathobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 6280b7c392..c5cd77fc14 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -46,6 +46,9 @@ #include <qmath.h> #include <qnumeric.h> +#include <QtCore/qdatetime.h> +#include <QtCore/qthreadstorage.h> + using namespace QV4; static const double qt_PI = 2.0 * ::asin(1.0); @@ -278,8 +281,14 @@ ReturnedValue MathObject::method_pow(SimpleCallContext *context) return Encode(qSNaN()); } -ReturnedValue MathObject::method_random(SimpleCallContext *) +Q_GLOBAL_STATIC(QThreadStorage<bool *>, seedCreatedStorage); + +ReturnedValue MathObject::method_random(SimpleCallContext *context) { + if (!seedCreatedStorage()->hasLocalData()) { + qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(context)); + seedCreatedStorage()->setLocalData(new bool(true)); + } return Encode(qrand() / (double) RAND_MAX); } |