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/opengl/legacy/overpainting/glwidget.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/opengl/legacy/overpainting/glwidget.cpp')
-rw-r--r-- | examples/opengl/legacy/overpainting/glwidget.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp index 7e9f4a5beb..1ec7bd731c 100644 --- a/examples/opengl/legacy/overpainting/glwidget.cpp +++ b/examples/opengl/legacy/overpainting/glwidget.cpp @@ -53,6 +53,7 @@ #include "glwidget.h" #include <QMouseEvent> +#include <QRandomGenerator> #include <QTime> #include <math.h> @@ -67,7 +68,6 @@ GLWidget::GLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent) { QTime midnight(0, 0, 0); - qsrand(midnight.secsTo(QTime::currentTime())); logo = 0; xRot = 0; @@ -234,11 +234,11 @@ QSize GLWidget::sizeHint() const void GLWidget::createBubbles(int number) { for (int i = 0; i < number; ++i) { - QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))), - height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0)))); - qreal radius = qMin(width(), height())*(0.0125 + 0.0875*qrand()/(RAND_MAX+1.0)); - QPointF velocity(width()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0)), - height()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0))); + QPointF position(width()*(0.1 + QRandomGenerator::global()->bounded(0.8)), + height()*(0.1 + QRandomGenerator::global()->bounded(0.8))); + qreal radius = qMin(width(), height())*(0.0125 + QRandomGenerator::global()->bounded(0.0875)); + QPointF velocity(width()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0)), + height()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0))); bubbles.append(new Bubble(position, radius, velocity)); } |