aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4mathobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4mathobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4mathobject.cpp11
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);
}