From 19b0ce5daa31e2ffebfcf2701143742302f1deb4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 13 Apr 2017 21:13:52 -0700 Subject: 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 --- examples/widgets/widgets/tooltips/main.cpp | 1 - examples/widgets/widgets/tooltips/sortingbox.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'examples/widgets/widgets/tooltips') diff --git a/examples/widgets/widgets/tooltips/main.cpp b/examples/widgets/widgets/tooltips/main.cpp index 3c64a33a4c..8276b3dc8d 100644 --- a/examples/widgets/widgets/tooltips/main.cpp +++ b/examples/widgets/widgets/tooltips/main.cpp @@ -57,7 +57,6 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(tooltips); QApplication app(argc, argv); - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); SortingBox sortingBox; sortingBox.show(); return app.exec(); diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp index c15fdcf95b..4769a30c64 100644 --- a/examples/widgets/widgets/tooltips/sortingbox.cpp +++ b/examples/widgets/widgets/tooltips/sortingbox.cpp @@ -292,7 +292,7 @@ QPoint SortingBox::initialItemPosition(const QPainterPath &path) //! [24] QPoint SortingBox::randomItemPosition() { - return QPoint(qrand() % (width() - 120), qrand() % (height() - 120)); + return QPoint(QRandomGenerator::global()->bounded(width() - 120), QRandomGenerator::global()->bounded(height() - 120)); } //! [24] @@ -306,6 +306,6 @@ QColor SortingBox::initialItemColor() //! [26] QColor SortingBox::randomItemColor() { - return QColor::fromHsv(qrand() % 256, 255, 190); + return QColor::fromHsv(QRandomGenerator::global()->bounded(256), 255, 190); } //! [26] -- cgit v1.2.3