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/widgets/graphicsview/boxes | |
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/widgets/graphicsview/boxes')
-rw-r--r-- | examples/widgets/graphicsview/boxes/qtbox.cpp | 2 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/scene.cpp | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp index 9a19985fac..3a184dd0b6 100644 --- a/examples/widgets/graphicsview/boxes/qtbox.cpp +++ b/examples/widgets/graphicsview/boxes/qtbox.cpp @@ -414,7 +414,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y) { - m_color = QColor::fromHsv(rand() % 360, 255, 255); + m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255); } void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 31b9553c75..f51cad99ac 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -50,6 +50,7 @@ #include <QDebug> #include "scene.h" +#include <QtCore/QRandomGenerator> #include <QtGui/qmatrix4x4.h> #include <QtGui/qvector3d.h> #include <qmath.h> @@ -1072,13 +1073,16 @@ void Scene::newItem(ItemDialog::ItemType type) QSize size = sceneRect().size().toSize(); switch (type) { case ItemDialog::QtBoxItem: - addItem(new QtBox(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32)); + addItem(new QtBox(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32, + QRandomGenerator::global()->bounded(size.height() - 64) + 32)); break; case ItemDialog::CircleItem: - addItem(new CircleItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32)); + addItem(new CircleItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32, + QRandomGenerator::global()->bounded(size.height() - 64) + 32)); break; case ItemDialog::SquareItem: - addItem(new SquareItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32)); + addItem(new SquareItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32, + QRandomGenerator::global()->bounded(size.height() - 64) + 32)); break; default: break; |