diff options
-rw-r--r-- | src/libs/installer/fileutils.cpp | 4 | ||||
-rw-r--r-- | src/libs/installer/metadatajob.cpp | 3 | ||||
-rw-r--r-- | src/libs/installer/testrepository.cpp | 3 | ||||
-rw-r--r-- | src/sdk/main.cpp | 2 | ||||
-rw-r--r-- | tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp | 3 | ||||
-rw-r--r-- | tests/auto/installer/replaceoperation/tst_replaceoperation.cpp | 3 |
6 files changed, 10 insertions, 8 deletions
diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp index 61891832e..76e5e3cd8 100644 --- a/src/libs/installer/fileutils.cpp +++ b/src/libs/installer/fileutils.cpp @@ -39,6 +39,7 @@ #include <QtCore/QUrl> #include <QtCore/QCoreApplication> #include <QImageReader> +#include <QRandomGenerator> #include <errno.h> @@ -460,9 +461,8 @@ QString QInstaller::generateTemporaryFileName(const QString &templ) static const QString characters = QLatin1String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); QString suffix; - qsrand(qrand() * QDateTime::currentDateTime().toTime_t()); for (int i = 0; i < 5; ++i) - suffix += characters[qrand() % characters.length()]; + suffix += characters[QRandomGenerator::global()->generate() % characters.length()]; const QString tmp = QLatin1String("%1.tmp.%2.%3"); int count = 1; diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp index bd5fc7f74..a8405a0e8 100644 --- a/src/libs/installer/metadatajob.cpp +++ b/src/libs/installer/metadatajob.cpp @@ -39,6 +39,7 @@ #include <QTemporaryDir> #include <QtMath> +#include <QRandomGenerator> const QStringList metaElements = {QLatin1String("Script"), QLatin1String("Licenses"), QLatin1String("UserInterfaces"), QLatin1String("Translations")}; @@ -174,7 +175,7 @@ void MetadataJob::doStart() url += m_core->value(scUrlQueryString) + QLatin1Char('&'); // also append a random string to avoid proxy caches - FileTaskItem item(url.append(QString::number(qrand() * qrand()))); + FileTaskItem item(url.append(QString::number(QRandomGenerator::global()->generate()))); item.insert(TaskRole::UserRole, QVariant::fromValue(repo)); item.insert(TaskRole::Authenticator, QVariant::fromValue(authenticator)); items.append(item); diff --git a/src/libs/installer/testrepository.cpp b/src/libs/installer/testrepository.cpp index 3bbf304e7..10c4360e6 100644 --- a/src/libs/installer/testrepository.cpp +++ b/src/libs/installer/testrepository.cpp @@ -33,6 +33,7 @@ #include "serverauthenticationdialog.h" #include <QFile> +#include <QRandomGenerator> namespace QInstaller { @@ -88,7 +89,7 @@ void TestRepository::doStart() auth.setPassword(m_repository.password()); FileTaskItem item(m_repository.url().toString() + QLatin1String("/Updates.xml?") + - QString::number(qrand() * qrand())); + QString::number(QRandomGenerator::global()->generate())); item.insert(TaskRole::Authenticator, QVariant::fromValue(auth)); m_timer.start(10000); diff --git a/src/sdk/main.cpp b/src/sdk/main.cpp index 27b58465e..ecff6e7d2 100644 --- a/src/sdk/main.cpp +++ b/src/sdk/main.cpp @@ -74,8 +74,6 @@ int main(int argc, char *argv[]) setrlimit(RLIMIT_NOFILE, &rl); #endif - qsrand(QDateTime::currentDateTime().toTime_t()); - // We need to start either a command line application or a GUI application. Since we // fail doing so at least on Linux while parsing the argument using a core application // object and later starting the GUI application, we now parse the arguments first. diff --git a/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp b/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp index bbe391a0a..4d14a2753 100644 --- a/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp +++ b/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp @@ -37,6 +37,7 @@ #include <QTextStream> #include <QSettings> #include <QtGlobal> +#include <QRandomGenerator> #include "qsettingswrapper.h" @@ -73,7 +74,7 @@ private slots: const QString possible = "abcdefghijklmnopqrstuvwxyz0123456789"; qsrand(QTime::currentTime().msec()); for (int i = 0; i < 5; i++) { - int index = qrand() % possible.length(); + int index = QRandomGenerator::global()->generate() % possible.length(); QChar nextChar = possible.at(index); randomString.append(nextChar); diff --git a/tests/auto/installer/replaceoperation/tst_replaceoperation.cpp b/tests/auto/installer/replaceoperation/tst_replaceoperation.cpp index 88dc2011b..33bd2b6c1 100644 --- a/tests/auto/installer/replaceoperation/tst_replaceoperation.cpp +++ b/tests/auto/installer/replaceoperation/tst_replaceoperation.cpp @@ -34,6 +34,7 @@ #include <QDir> #include <QFile> #include <QTest> +#include <QRandomGenerator> using namespace KDUpdater; using namespace QInstaller; @@ -46,7 +47,7 @@ private slots: void initTestCase() { m_testDirectory = QInstaller::generateTemporaryFileName(); - m_testFilePath = m_testDirectory + "/test." + QString::number(qrand() % 1000); + m_testFilePath = m_testDirectory + "/test." + QString::number(QRandomGenerator::global()->generate() % 1000); } void testWrongArguments() |