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/gui/painting | |
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/gui/painting')
-rw-r--r-- | tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 3 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 779783d5ec..b8243a2b54 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -45,6 +45,7 @@ #include <qdesktopwidget.h> #endif #include <qpixmap.h> +#include <qrandom.h> #include <private/qdrawhelper_p.h> #include <qpainter.h> @@ -3052,7 +3053,7 @@ void tst_QPainter::fpe_steepSlopes_data() qreal randf() { - return rand() / (RAND_MAX + 1.0); + return QRandomGenerator::global()->bounded(1.0); } QPointF randInRect(const QRectF &rect) diff --git a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp index 14ba9c5c84..93035af7d3 100644 --- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp +++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp @@ -35,6 +35,7 @@ #include <qpolygon.h> #include <qdebug.h> #include <qpainter.h> +#include <qrandom.h> #include <math.h> @@ -423,8 +424,8 @@ void tst_QPathClipper::clip() static inline QPointF randomPointInRect(const QRectF &rect) { - qreal rx = qrand() / (RAND_MAX + 1.); - qreal ry = qrand() / (RAND_MAX + 1.); + qreal rx = QRandomGenerator::global()->bounded(1.0); + qreal ry = QRandomGenerator::global()->bounded(1.0); return QPointF(rect.left() + rx * rect.width(), rect.top() + ry * rect.height()); |