Commit a7eda770 authored by Tobias Fella's avatar Tobias Fella
Browse files

Port to Qt6

parent e111f222
......@@ -14,6 +14,7 @@
/* these includes are needed for Qt support */
#include <QApplication>
#include <QPushButton>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -190,12 +191,12 @@ void ExerciseCompare::update()
void ExerciseCompare::createTask()
{
// generate the first ratio
m_firstRatio = Ratio(int ((double(qrand()) / RAND_MAX) * 10 + 1), int ((double(qrand()) / RAND_MAX) * 10 + 1));
m_firstRatio = Ratio(QRandomGenerator::global()->bounded(10) + 1, QRandomGenerator::global()->bounded(10) + 1);
// now the second ratio, but make sure, the second ratio is different from
// the first one
do {
m_secondRatio = Ratio(int ((double(qrand()) / RAND_MAX) * 10 + 1), int ((double(qrand()) / RAND_MAX) * 10 + 1));
m_secondRatio = Ratio(QRandomGenerator::global()->bounded(10) + 1, QRandomGenerator::global()->bounded(10) + 1);
} while (m_firstRatio == m_secondRatio);
return;
......
......@@ -19,6 +19,7 @@
#include <QLocale>
#include <QPushButton>
#include <QFrame>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -196,7 +197,7 @@ void ExerciseConvert::createTask()
{
// the tasks are hardcoded here; there are some algorithms to convert
// rational numbers to fractions, but it is not worth the effort here
switch (int ((double(qrand()) / RAND_MAX) * 19 )) {
switch (QRandomGenerator::global()->bounded(19)) {
case 0 : m_number = QLocale().toString(0.5, 'f', 1);
m_periodStart = 2;
m_periodLength = 0;
......
......@@ -16,6 +16,7 @@
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -317,7 +318,7 @@ void ExerciseFactorize::createTask()
PrimeNumber tmp_primenumber;
// just pick one number out of the possible numbers to factorize
m_taskNumber = possibleTasks[uint((double(qrand()) / RAND_MAX) * numberPossibleTasks)];
m_taskNumber = possibleTasks[QRandomGenerator::global()->bounded(numberPossibleTasks)];
// now get the primefactors of the taskNumber
m_factorsResult.clear();
......
......@@ -18,6 +18,7 @@
#include <QIntValidator>
#include <QPushButton>
#include <QWidget>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -203,13 +204,13 @@ void ExerciseMixedNumbers::createTask()
int denominator = 1;
do {
// numerator should be between 1..15
numerator = int ((double(qrand()) / RAND_MAX) * 15 + 1);
numerator = QRandomGenerator::global()->bounded(15) + 1;
// denominator should be between 1..(numerator-1)
denominator = int ((double(qrand()) / RAND_MAX) * numerator);
denominator = QRandomGenerator::global()->bounded(numerator);
// eventually make ratio negative
if (double(qrand()) / RAND_MAX >= 0.5) {
if (QRandomGenerator::global()->bounded(2) == 1) {
numerator *= -1;
}
tmpRatio.setRatio(numerator, denominator);
......
......@@ -15,6 +15,7 @@
#include <QIntValidator>
#include <QLineEdit>
#include <QPushButton>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -183,7 +184,7 @@ void ExercisePercentage::createTask()
{
// the tasks are hardcoded here; there are some algorithms to convert
// rational numbers to fractions, but it is not worth the effort here
switch (int ((double(qrand()) / RAND_MAX) * 19)) {
switch (QRandomGenerator::global()->bounded(19)) {
case 0 :
//m_number = QLocale().toString(0.5, 'f', 1);
m_numberPercentage = QStringLiteral("75");
......
......@@ -26,6 +26,7 @@
#include <QString>
#include <QTextEdit>
#include <QWidgetAction>
#include <QRandomGenerator>
#ifdef DEBUG
#include <QDebug>
......@@ -402,16 +403,16 @@ void FractionRingWidget::NewTask()
void FractionRingWidget::resetFraction(bool flag = true)
{
int denominator = int ((double(qrand()) / RAND_MAX) * 5) + 2;
int numerator = int ((double(qrand()) / RAND_MAX) * (denominator - 1)) + 1;
int denominator = QRandomGenerator::global()->bounded(5) + 2;
int numerator = QRandomGenerator::global()->bounded(denominator - 1) + 1;
rLeft = Ratio(numerator, denominator, false);
int denominator2 = int ((double(qrand()) / RAND_MAX) * 5) + 2;
int denominator2 = QRandomGenerator::global()->bounded(5) + 2;
while (denominator2 == denominator) {
denominator2 = int ((double(qrand()) / RAND_MAX) * 5) + 2;
denominator2 = QRandomGenerator::global()->bounded(5) + 2;
}
int numerator2 = int ((double(qrand()) / RAND_MAX) * (denominator2 - 1)) + 1;
int numerator2 = QRandomGenerator::global()->bounded(denominator2 - 1) + 1;
rRight = Ratio(numerator2, denominator2, false);
multLeft = 1;
......
......@@ -31,8 +31,6 @@
/* the main program */
int main(int argc, char * argv[])
{
// init random generator
qsrand(time(nullptr));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
......
......@@ -12,13 +12,13 @@
#include <cmath>
#include <ctime>
#include <QRandomGenerator>
#include <QDebug>
/** constructor of class task */
Task::Task()
{
qsrand(time(nullptr));
#ifdef DEBUG
qDebug() << "constructor task";
#endif
......@@ -410,7 +410,7 @@ unsigned short Task::make_operation(short padd_add, short padd_div, short padd_m
op_vector.push_back(SUB);
} else {
do {
operations = short((double(qrand()) / RAND_MAX) * 4);
operations = QRandomGenerator::global()->bounded(4);
switch (operations) {
case ADD:
if (padd_add == YES) {
......@@ -487,7 +487,7 @@ int Task::make_main_dn(unsigned int pmax_md, unsigned short max_product_length)
/* find a main denominator in the given limits by pmax_md and check
* if the main denominator has enough prime factors */
do {
denominator = int (((double(qrand()) / RAND_MAX) * pmax_md) + 1);
denominator = QRandomGenerator::global()->bounded(pmax_md) + 1;
} while ((pmax_md < 1) ||
(prim_factor_nr(denominator) < max_product_length));
......@@ -542,8 +542,7 @@ void Task::make_numerators(int main_denominator, short pnr_ratios)
/* add a new ratio to the task and compute the numerator randomly */
for (short tmpcounter = 0; tmpcounter < pnr_ratios; tmpcounter++) {
(*this).add_ratio(int ((double(qrand()) / RAND_MAX)
* max_numerator) + 1, 1);
(*this).add_ratio(QRandomGenerator::global()->bounded(max_numerator) + 1, 1);
}
return;
}
......@@ -577,7 +576,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
for (ratio_pointer = ratio_vector.begin();
ratio_pointer != ratio_vector.end(); ++ratio_pointer) {
do {
tmp_deno = int ((double(qrand()) / RAND_MAX) * pmax_md) + 1;
tmp_deno = QRandomGenerator::global()->bounded(pmax_md) + 1;
} while (main_denominator % tmp_deno != 0);
(*ratio_pointer).setDenominator(tmp_deno);
}
......@@ -606,8 +605,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
/* the prim_fac_vector is sorted, but we do not want the
* factors in this sorted way as our denominators;
* so we choose one randomly */
next_fac = (unsigned short)((double(qrand()) / RAND_MAX)
* unused_fac);
next_fac = QRandomGenerator::global()->bounded(unused_fac);
tmp_counter = 0;
/* check the prime factors, if they are unused */
......@@ -641,8 +639,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
/* the prim_fac_vector is sorted, but we do not want the
* factors in this sorted way as our denominators;
* so we choose one randomly */
next_fac = (unsigned short)((double(qrand()) / RAND_MAX)
* unused_fac);
next_fac = QRandomGenerator::global()->bounded(unused_fac);
tmp_counter = 0;
/* check the prime factors, if they are unused */
......
Supports Markdown
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