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 --- tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp | 2 +- tests/benchmarks/corelib/tools/qcryptographichash/main.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/benchmarks/corelib/tools') diff --git a/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 11e559a298..a4ad3a08a8 100644 --- a/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -57,7 +57,7 @@ QVector generateData(QString dataSetType, const int length) QVector container; if (dataSetType == "Random") { for (int i = 0; i < length; ++i) - container.append(rand()); + container.append(QRandomGenerator::global()->generate()); } else if (dataSetType == "Ascending") { for (int i = 0; i < length; ++i) container.append(i); diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp index 507e2af708..1d414161d1 100644 --- a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp +++ b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2017 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -102,9 +103,8 @@ tst_bench_QCryptographicHash::tst_bench_QCryptographicHash() } else #endif { - qsrand(time(NULL)); for (int i = 0; i < MaxBlockSize; ++i) - blockOfData[i] = qrand(); + blockOfData[i] = QRandomGenerator::global()->generate(); } } -- cgit v1.2.3