diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-04-13 21:13:52 -0700 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-11-08 09:14:03 +0000 |
commit | 19b0ce5daa31e2ffebfcf2701143742302f1deb4 (patch) | |
tree | 730cccd80947c60ee4872e16f71d4d48d906c354 /examples/corelib/threads/queuedcustomtype/renderthread.cpp | |
parent | 59c5f7bd9da63621887260fc45e6669282d71ecd (diff) |
Change almost all other uses of qrand() to QRandomGenerator
The vast majority is actually switched to QRandomGenerator::bounded(),
which gives a mostly uniform distribution over the [0, bound)
range. There are very few floating point cases left, as many of those
that did use floating point did not need to, after all. (I did leave
some that were too ugly for me to understand)
This commit also found a couple of calls to rand() instead of qrand().
This commit does not include changes to SSL code that continues to use
qrand() (job for someone else):
src/network/ssl/qsslkey_qt.cpp
src/network/ssl/qsslsocket_mac.cpp
tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/corelib/threads/queuedcustomtype/renderthread.cpp')
-rw-r--r-- | examples/corelib/threads/queuedcustomtype/renderthread.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.cpp b/examples/corelib/threads/queuedcustomtype/renderthread.cpp index f894dd587f..67cedf1e74 100644 --- a/examples/corelib/threads/queuedcustomtype/renderthread.cpp +++ b/examples/corelib/threads/queuedcustomtype/renderthread.cpp @@ -50,6 +50,8 @@ #include "renderthread.h" +#include <QRandomGenerator> + RenderThread::RenderThread(QObject *parent) : QThread(parent) { @@ -82,9 +84,9 @@ void RenderThread::run() for (int s = size; s > 0; --s) { for (int c = 0; c < 400; ++c) { //![processing the image (start)] - int x1 = qMax(0, (qrand() % m_image.width()) - s/2); + int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2); int x2 = qMin(x1 + s/2 + 1, m_image.width()); - int y1 = qMax(0, (qrand() % m_image.height()) - s/2); + int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2); int y2 = qMin(y1 + s/2 + 1, m_image.height()); int n = 0; int red = 0; |