diff options
author | Thiago Macieira <[email protected]> | 2017-06-12 15:28:13 -0700 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2017-08-23 04:47:59 +0000 |
commit | 2b7b24a0e039a18db8ab23475fbab44718f758a2 (patch) | |
tree | 0cfb916871a7e48d843dcd371d723a7d6083f2a6 /src/qml/jsruntime/qv4mathobject.cpp | |
parent | 46ed14da325c6c0382c0bc54cacc347d2d7f2b0a (diff) |
Use QRandomGenerator instead of q?rand
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4mathobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 14 |
1 files changed, 2 insertions, 12 deletions
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) |