Commit e2b51853 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

KRandom::random() % -> QRandomGenerator::global()->bounded()

parent 7d493438
......@@ -7,7 +7,7 @@ set(RELEASE_SERVICE_VERSION_MICRO "70")
set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
project(parley VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION "5.2.0")
set(QT_MIN_VERSION "5.10.0")
set(KF5_MIN_VERSION "5.22.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
......
......@@ -14,10 +14,10 @@
#include "entryfilter.h"
#include <QDebug>
#include <QRandomGenerator>
#include <KMessageBox>
#include <KLocalizedString>
#include <KRandom>
#include <keduvocdocument.h>
#include <keduvocwordtype.h>
......@@ -622,5 +622,5 @@ void EntryFilter::updateCurrentSelection()
void EntryFilter::randomizedInsert(QList<TestEntry*>& list, TestEntry* entry)
{
list.insert(KRandom::random() % (list.size() + 1), entry);
list.insert(QRandomGenerator::global()->bounded(list.size() + 1), entry);
}
......@@ -16,9 +16,9 @@
#include "lessonmodel.h"
#include "parleydocument.h"
#include <KRandom>
#include <KLocalizedString>
#include <QFont>
#include <QRandomGenerator>
/** @file
* Implementation of LessonModel.
......@@ -109,7 +109,7 @@ void LessonModel::splitLesson(const QModelIndex& containerIndex, int entriesPerL
// next entry to be assigned to one of the new lessons
int nextEntry = 0;
if (order == Random) {
nextEntry = KRandom::random() % parentLesson->entryCount();
nextEntry = QRandomGenerator::global()->bounded(parentLesson->entryCount());
child->appendEntry(parentLesson->entry(nextEntry));
}
}
......
......@@ -15,7 +15,8 @@
#include "multiplechoicebackendmode.h"
#include <KLocalizedString>
#include <KRandom>
#include <QRandomGenerator>
#include "multiplechoicedata.h"
......@@ -48,10 +49,10 @@ void MultipleChoiceBackendMode::prepareChoices(TestEntry* current)
QStringList choices = m_sessionManager->multipleChoiceAnswers(m_numberOfChoices - 1);
foreach(const QString & choice, choices) {
int position = KRandom::random() % (m_choices.count() + 1);
int position = QRandomGenerator::global()->bounded(m_choices.count() + 1);
m_choices.insert(position, choice);
}
int correctAnswer = KRandom::random() % (m_choices.count() + 1);
int correctAnswer = QRandomGenerator::global()->bounded(m_choices.count() + 1);
m_choices.insert(correctAnswer, m_current->entry()->translation(m_current->languageTo())->text());
setCorrectAnswer(correctAnswer);
}
......@@ -117,7 +118,7 @@ void MultipleChoiceBackendMode::hintAction()
int hint = -1;
do {
hint = KRandom::random() % m_choices.count();
hint = QRandomGenerator::global()->bounded(m_choices.count());
} while (hint == m_correctAnswer || m_hints.contains(hint));
m_hints.append(hint);
m_frontend->setHint(QVariant(hint));
......
......@@ -18,13 +18,13 @@
// Qt
#include <QDateTime>
#include <QRandomGenerator>
// kdelibs
#include <KLocalizedString>
#include <kconfig.h>
#include <QDebug>
#include <KMessageBox>
#include <KRandom>
// kdeedulibs
#include <keduvoclesson.h>
......@@ -136,12 +136,12 @@ TestEntry* SessionManagerBase::nextTrainingEntry()
int lastEntry = m_currentEntry;
if (m_currentEntries.count() > 0) {
// Choose one of the current entries randomly.
m_currentEntry = KRandom::random() % m_currentEntries.count();
m_currentEntry = QRandomGenerator::global()->bounded(m_currentEntries.count());
// Do not allow to ask the same entry twice in a row.
if (m_currentEntries.count() > 1) {
while (m_currentEntry == lastEntry) {
m_currentEntry = KRandom::random() % m_currentEntries.count();
m_currentEntry = QRandomGenerator::global()->bounded(m_currentEntries.count());
}
}
......@@ -253,7 +253,7 @@ QStringList SessionManagerBase::multipleChoiceAnswers(int numberChoices)
TestEntry *currentEntry = m_currentEntries.at(m_currentEntry);
QStringList predefinedChoices = currentEntry->entry()->translation(currentEntry->languageTo())->getMultipleChoice();
while (!predefinedChoices.isEmpty() && count > 0) {
choices.append(predefinedChoices.takeAt(KRandom::random() % predefinedChoices.count()));
choices.append(predefinedChoices.takeAt(QRandomGenerator::global()->bounded(predefinedChoices.count())));
count--;
}
......@@ -281,7 +281,7 @@ QStringList SessionManagerBase::multipleChoiceAnswers(int numberChoices)
int nr;
// if there are enough non-empty fields, fill the options only with those
do {
nr = KRandom::random() % allEntries.count();
nr = QRandomGenerator::global()->bounded(allEntries.count());
} while (!isValidMultipleChoiceAnswer(allEntries.value(nr)));
// append if new entry found
bool newex = true;
......
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