diff options
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/doc/src/cppintegration/definetypes.qdoc | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 14 |
2 files changed, 3 insertions, 14 deletions
diff --git a/src/qml/doc/src/cppintegration/definetypes.qdoc b/src/qml/doc/src/cppintegration/definetypes.qdoc index 1ce00c6ad0..91f916c699 100644 --- a/src/qml/doc/src/cppintegration/definetypes.qdoc +++ b/src/qml/doc/src/cppintegration/definetypes.qdoc @@ -606,7 +606,6 @@ public: RandomNumberGenerator(QObject *parent) : QObject(parent), m_maxValue(100) { - qsrand(QDateTime::currentMSecsSinceEpoch() / 1000); QObject::connect(&m_timer, SIGNAL(timeout()), SLOT(updateProperty())); m_timer.start(500); } @@ -621,7 +620,7 @@ signals: private slots: void updateProperty() { - m_targetProperty.write(qrand() % m_maxValue); + m_targetProperty.write(QRandomGenerator::bounded(m_maxValue)); } private: diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 2d9d81c64b..6fd1509d77 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -42,6 +42,7 @@ #include <QtCore/qdatetime.h> #include <QtCore/qmath.h> +#include <QtCore/qrandom.h> #include <QtCore/private/qnumeric_p.h> #include <QtCore/qthreadstorage.h> @@ -271,20 +272,9 @@ void MathObject::method_pow(const BuiltinFunction *, Scope &scope, CallData *cal RETURN_RESULT(Encode(qt_qnan())); } -Q_GLOBAL_STATIC(QThreadStorage<bool *>, seedCreatedStorage); - void MathObject::method_random(const BuiltinFunction *, Scope &scope, CallData *) { - if (!seedCreatedStorage()->hasLocalData()) { - int msecs = QTime(0,0,0).msecsTo(QTime::currentTime()); - Q_ASSERT(msecs >= 0); - qsrand(uint(uint(msecs) ^ reinterpret_cast<quintptr>(scope.engine))); - seedCreatedStorage()->setLocalData(new bool(true)); - } - // rand()/qrand() return a value where the upperbound is RAND_MAX inclusive. So, instead of - // dividing by RAND_MAX (which would return 0..RAND_MAX inclusive), we divide by RAND_MAX + 1. - qint64 upperLimit = qint64(RAND_MAX) + 1; - RETURN_RESULT(Encode(qrand() / double(upperLimit))); + RETURN_RESULT(Encode(QRandomGenerator::getReal())); } void MathObject::method_round(const BuiltinFunction *, Scope &scope, CallData *callData) |