summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/gui
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-04-13 21:13:52 -0700
committerLars Knoll <lars.knoll@qt.io>2017-11-08 09:14:03 +0000
commit19b0ce5daa31e2ffebfcf2701143742302f1deb4 (patch)
tree730cccd80947c60ee4872e16f71d4d48d906c354 /tests/benchmarks/gui
parent59c5f7bd9da63621887260fc45e6669282d71ecd (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/benchmarks/gui')
-rw-r--r--tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp16
-rw-r--r--tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp2
-rw-r--r--tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp5
-rw-r--r--tests/benchmarks/gui/painting/qtbench/benchmarktests.h9
4 files changed, 18 insertions, 14 deletions
diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp
index e3ee0f8e45..7809b38050 100644
--- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp
+++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include <QFile>
+#include <QRandomGenerator>
#include "theme.h"
#include "dummydatagen.h"
@@ -65,12 +66,11 @@ DummyDataGenerator::~DummyDataGenerator()
void DummyDataGenerator::Reset()
{
- qsrand(100);
}
QString DummyDataGenerator::randomPhoneNumber(QString indexNumber)
{
- int index = qrand()%m_countryCodes.count();
+ int index = QRandomGenerator::global()->bounded(m_countryCodes.count());
QString countryCode = m_countryCodes.at(index);
QString areaCode = QString::number(index) + QString("0").repeated(2-QString::number(index).length());
QString beginNumber = QString::number(555-index*2);
@@ -84,13 +84,13 @@ QString DummyDataGenerator::randomFirstName()
{
m_isMale = !m_isMale;
if (m_isMale)
- return m_firstNamesM.at(qrand()%m_firstNamesM.count());
- return m_firstNamesF.at(qrand()%m_firstNamesF.count());
+ return m_firstNamesM.at(QRandomGenerator::global()->bounded(m_firstNamesM.count()));
+ return m_firstNamesF.at(QRandomGenerator::global()->bounded(m_firstNamesF.count()));
}
QString DummyDataGenerator::randomLastName()
{
- return m_lastNames.at(qrand()%m_lastNames.count());
+ return m_lastNames.at(QRandomGenerator::global()->bounded(m_lastNames.count()));
}
QString DummyDataGenerator::randomName()
@@ -101,8 +101,8 @@ QString DummyDataGenerator::randomName()
QString DummyDataGenerator::randomIconItem()
{
QString avatar = Theme::p()->pixmapPath() + "contact_default_icon.svg";
- if (qrand()%4) {
- int randVal = 1+qrand()%25;
+ if (QRandomGenerator::global()->bounded(4)) {
+ int randVal = 1+QRandomGenerator::global()->bounded(25);
if (m_isMale && randVal > 15) {
randVal -= 15;
@@ -118,7 +118,7 @@ QString DummyDataGenerator::randomIconItem()
QString DummyDataGenerator::randomStatusItem()
{
- switch (qrand()%3) {
+ switch (QRandomGenerator::global()->bounded(3)) {
case 0: return Theme::p()->pixmapPath() + "contact_status_online.svg";
case 1: return Theme::p()->pixmapPath() + "contact_status_offline.svg";
case 2: return Theme::p()->pixmapPath() + "contact_status_idle.svg";
diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp
index 6c97f94683..e0cc0f8eb4 100644
--- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp
+++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
for (int i = 0; i < atoi(argv[1]); ++i) {
QGraphicsRectItem *child = scene.addRect(-5, -5, 10, 10, QPen(Qt::NoPen), QBrush(Qt::blue));
- child->setPos(-50 + qrand() % 100, -50 + qrand() % 100);
+ child->setPos(-50 + QRandomGenerator::global()->bounded(100), -50 + QRandomGenerator::global()->bounded(100));
child->setParentItem(item);
}
diff --git a/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
index c2f41a7557..d9bc7f21b6 100644
--- a/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -31,6 +31,7 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsWidget>
+#include <QRandomGenerator>
class tst_QGraphicsWidget : public QObject
{
@@ -72,7 +73,9 @@ void tst_QGraphicsWidget::move()
QGraphicsView view(&scene);
view.show();
QBENCHMARK {
- widget->setPos(qrand(),qrand());
+ // truncate the random values to 24 bits to
+ // avoid overflowing
+ widget->setPos(QRandomGenerator::global()->generate() & 0xffffff, QRandomGenerator::global()->generate() & 0xffffff);
}
}
diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h
index e4b98336c7..42b06778f9 100644
--- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h
+++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h
@@ -37,6 +37,7 @@
#include <QDebug>
#include <QStaticText>
#include <QPainter>
+#include <QRandomGenerator>
class Benchmark
{
@@ -47,9 +48,9 @@ public:
: m_size(size)
{
for (int i=0; i<16; ++i) {
- m_colors[i] = QColor::fromRgbF((rand() % 4) / 3.0,
- (rand() % 4) / 3.0,
- (rand() % 4) / 3.0,
+ m_colors[i] = QColor::fromRgbF((QRandomGenerator::global()->bounded(4)) / 3.0,
+ (QRandomGenerator::global()->bounded(4)) / 3.0,
+ (QRandomGenerator::global()->bounded(4)) / 3.0,
1);
}
}
@@ -142,7 +143,7 @@ public:
ImageFillRectBenchmark(int size)
: Benchmark(QSize(size, size))
{
- int s = rand() % 24 + 8;
+ int s = QRandomGenerator::global()->bounded(24) + 8;
m_content = QImage(s, s, QImage::Format_ARGB32_Premultiplied);
QPainter p(&m_content);
p.fillRect(0, 0, s, s, Qt::white);