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 /tests/auto/opengl | |
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 'tests/auto/opengl')
-rw-r--r-- | tests/auto/opengl/qglthreads/tst_qglthreads.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp index 1a7ccba9be..90fc4e0f2a 100644 --- a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp +++ b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp @@ -138,7 +138,7 @@ public: makeCurrent(); QPainter p(this); - p.fillRect(rect(), QColor(rand() % 256, rand() % 256, rand() % 256)); + p.fillRect(rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); p.setPen(Qt::red); p.setFont(QFont("SansSerif", 24)); p.drawText(rect(), Qt::AlignCenter, "This is an autotest"); @@ -229,7 +229,7 @@ public: int height = 300; QImage image(width, height, QImage::Format_RGB32); QPainter p(&image); - p.fillRect(image.rect(), QColor(rand() % 256, rand() % 256, rand() % 256)); + p.fillRect(image.rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); p.setPen(Qt::red); p.setFont(QFont("SansSerif", 24)); p.drawText(image.rect(), Qt::AlignCenter, "This is an autotest"); @@ -271,7 +271,7 @@ public: public slots: void receiveImage(const QImage &image) { m_images << image; - m_positions << QPoint(-rand() % width() / 2, -rand() % height() / 2); + m_positions << QPoint(-QRandomGenerator::global()->bounded(width() / 2), -QRandomGenerator::global()->bounded(height() / 2)); m_semaphore->release(1); @@ -326,7 +326,7 @@ void tst_QGLThreads::textureUploadInThread() if that works, we're in good shape.. */ -static inline float qrandom() { return (rand() % 100) / 100.f; } +static inline float qrandom() { return (QRandomGenerator::global()->bounded(100)) / 100.f; } void renderAScene(int w, int h) { @@ -345,12 +345,12 @@ void renderAScene(int w, int h) for (int i=0; i<1000; ++i) { GLfloat pos[] = { - (rand() % 100) / 100.f, - (rand() % 100) / 100.f, - (rand() % 100) / 100.f, - (rand() % 100) / 100.f, - (rand() % 100) / 100.f, - (rand() % 100) / 100.f + (QRandomGenerator::global()->bounded(100)) / 100.f, + (QRandomGenerator::global()->bounded(100)) / 100.f, + (QRandomGenerator::global()->bounded(100)) / 100.f, + (QRandomGenerator::global()->bounded(100)) / 100.f, + (QRandomGenerator::global()->bounded(100)) / 100.f, + (QRandomGenerator::global()->bounded(100)) / 100.f }; funcs->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos); |