Commit dfd2fb4e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to QRandomGenerator

parent c9996ee7
......@@ -28,14 +28,13 @@
#include <QTime>
#include <QRegularExpression>
#include <QCryptographicHash>
#include <QRandomGenerator>
#include <KIO/StoredTransferJob>
#include <KIO/Job>
MediaFrame::MediaFrame(QObject *parent) : QObject(parent)
{
qsrand(QTime::currentTime().msec());
const auto imageMimeTypeNames = QImageReader::supportedMimeTypes();
QMimeDatabase mimeDb;
for (const auto& imageMimeTypeName : imageMimeTypeNames) {
......@@ -79,7 +78,7 @@ int MediaFrame::random(int min, int max)
}
//qDebug() << "random" << min << "<->" << max << "=" << ((qrand()%(max-min+1))+min);
return ((qrand() % (max - min + 1) ) + min);
return (QRandomGenerator::global()->bounded((max - min + 1) ) + min);
}
QString MediaFrame::getCacheDirectory()
......
......@@ -28,6 +28,7 @@
#include <QMimeType>
#include <QMimeDatabase>
#include <QStandardPaths>
#include <QRandomGenerator>
#include <KRun>
#include <KConfig>
......@@ -156,14 +157,14 @@ static QString determineNewDesktopFilePath(const QString &baseName)
QString appendix;
QString desktopFilePath = locateLocal(baseName) + QLatin1String(".desktop");
auto *generator = QRandomGenerator::global();
while (QFile::exists(desktopFilePath)) {
if (appendix.isEmpty()) {
qsrand(QTime::currentTime().msec());
appendix += QLatin1Char('-');
}
// Limit to [0-9] and [a-z] range.
char newChar = qrand() % 36;
char newChar = generator->bounded(36);
newChar += newChar < 10 ? 48 : 97-10;
appendix += QLatin1Char(newChar);
......
......@@ -23,7 +23,7 @@
#include <QUrlQuery>
#include <QDebug>
#include <QRandomGenerator>
#include <KPluginFactory>
#include <KIO/Job>
......@@ -47,8 +47,6 @@ QUrl buildUrl(const QDate &date)
FlickrProvider::FlickrProvider(QObject *parent, const QVariantList &args)
: PotdProvider(parent, args)
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
mActualDate = date();
const QUrl url = buildUrl(mActualDate);
......@@ -142,7 +140,7 @@ void FlickrProvider::pageRequestFinished(KJob *_job)
}
if (m_photoList.begin() != m_photoList.end()) {
QUrl url( m_photoList.at(qrand() % m_photoList.size()) );
QUrl url( m_photoList.at(QRandomGenerator::global()->bounded(m_photoList.size())) );
KIO::StoredTransferJob *imageJob = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo);
connect(imageJob, &KIO::StoredTransferJob::finished, this, &FlickrProvider::imageRequestFinished);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment