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/manual/textrendering | |
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/manual/textrendering')
-rw-r--r-- | tests/manual/textrendering/textperformance/main.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/tests/manual/textrendering/textperformance/main.cpp b/tests/manual/textrendering/textperformance/main.cpp index 9bd6d036af..eb6d09b9c8 100644 --- a/tests/manual/textrendering/textperformance/main.cpp +++ b/tests/manual/textrendering/textperformance/main.cpp @@ -30,6 +30,7 @@ #include <QDialog> #include <QFontDatabase> #include <QPainter> +#include <QRandomGenerator> #include <QTime> #include <QTimer> @@ -93,17 +94,17 @@ public: static const QString text = QLatin1String("Qt rocks!!!"); static const int textsPerPaint = 30; for (int i = 0; i < textsPerPaint; i++) { - const int fontSize = 4 + (qrand() % 5); - const int fontWeight = (qrand() % 2) == 1 ? QFont::Normal : QFont::Bold; - const bool fontItalic = (qrand() % 2) == 1; + const int fontSize = 4 + QRandomGenerator::global()->bounded(5); + const int fontWeight = QRandomGenerator::global()->bounded(2) == 1 ? QFont::Normal : QFont::Bold; + const bool fontItalic = QRandomGenerator::global()->bounded(2) == 1; const QFont font("Default", fontSize, fontWeight, fontItalic); p.setFont(font); - p.setPen(QColor::fromHsv(qrand() % 359, 155 + qrand() % 100, - 155 + qrand() % 100, 100 + qrand() % 155)); + p.setPen(QColor::fromHsv(QRandomGenerator::global()->bounded(359), 155 + QRandomGenerator::global()->bounded(100), + 155 + QRandomGenerator::global()->bounded(100), 100 + QRandomGenerator::global()->bounded(155))); const QSize textSize(p.fontMetrics().boundingRect(text).size()); const QPoint position( - -textSize.width() / 2 + (qrand() % size.width()), - textSize.height() / 2 + (qrand() % size.height())); + -textSize.width() / 2 + QRandomGenerator::global()->bounded(size.width()), + textSize.height() / 2 + QRandomGenerator::global()->bounded(size.height())); p.drawText(position, text); } } @@ -126,8 +127,8 @@ public: QString text; for (int i = 0; i < piecesPerPaint; ++i) { - QString piece = QLatin1String(pieces[qrand() % piecesCount]); - if (i == 0 || qrand() % 2) { + QString piece = QLatin1String(pieces[QRandomGenerator::global()->bounded(piecesCount)]); + if (i == 0 || QRandomGenerator::global()->bounded(2)) { // Make this piece the beginning of a new sentence. piece[0] = piece[0].toUpper(); if (i > 0) @@ -160,7 +161,7 @@ public: for (int i = 0; i < systemsPerPaint; i++) { if (i > 0) text.append(QLatin1Char(' ')); - text.append(samples.at(qrand() % samples.count())); + text.append(samples.at(QRandomGenerator::global()->bounded(samples.count()))); } p.drawText(QRectF(QPointF(0, 0), QSizeF(size)), Qt::AlignTop | Qt::AlignAbsolute | Qt::TextWordWrap, text); |