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

KRandom -> QRandomGenerator

parent ecc37933
project(lskat)
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
set (QT_MIN_VERSION "5.9.0")
set (QT_MIN_VERSION "5.10.0")
set (KF5_MIN_VERSION "5.46.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG)
......
......@@ -33,11 +33,11 @@
#define SHUFFLE_AMOUNT 1000
// Constructor for the view
Deck::Deck(long seed, QObject *parent)
Deck::Deck(quint32 seed, QObject *parent)
: QObject(parent)
{
// Set the random seed
mRandom.setSeed(seed);
mRandom.seed(seed);
// TODO: Hardcoded
// mRandom.setSeed(global_debug);
shuffle();
......@@ -58,7 +58,7 @@ int Deck::cardNumber()
// Draw a random trump from all cards.
Suite Deck::randomTrump()
{
int card = mRandom.getLong(NUMBER_OF_CARDS);
int card = mRandom.bounded(NUMBER_OF_CARDS);
Suite suite = getSuite(card);
CardType type = getCardType(card);
......@@ -82,8 +82,8 @@ void Deck::shuffle()
// Shuffle cards
for (int i = 0; i < SHUFFLE_AMOUNT; i++)
{
int c1 = mRandom.getLong(NUMBER_OF_CARDS);
int c2 = mRandom.getLong(NUMBER_OF_CARDS);
int c1 = mRandom.bounded(NUMBER_OF_CARDS);
int c2 = mRandom.bounded(NUMBER_OF_CARDS);
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
mCards.swapItemsAt(c1, c2);
#else
......
......@@ -25,9 +25,7 @@
#include <QObject>
#include <QList>
#include <QHash>
// KDE includes
#include <KRandomSequence>
#include <QRandomGenerator>
#include "lskat_debug.h"
......@@ -58,7 +56,7 @@ public:
* @param seed The random seed
* @param parent The parent object
*/
Deck(long seed, QObject *parent);
Deck(quint32 seed, QObject *parent);
/**
* Destructor
......@@ -153,7 +151,7 @@ private:
// Array of card numbers
QList<int> mCards;
// Random generator
KRandomSequence mRandom;
QRandomGenerator mRandom;
};
#endif
......@@ -22,12 +22,12 @@
#include <QDir>
#include <QFileInfo>
#include <QRandomGenerator>
#include <QStandardPaths>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KRandom>
#include "lskat_debug.h"
// KConfig entries
......@@ -145,7 +145,7 @@ QString randomDeckName()
// Collect matching items
QStringList list = deckinfoStatic->themeNameMap.keys();
// Draw random one
int d = KRandom::random() % list.count();
int d = QRandomGenerator::system()->bounded(list.count());
return list.at(d);
}
......
......@@ -25,6 +25,7 @@
#include <QDir>
#include <QKeySequence>
#include <QPointer>
#include <QRandomGenerator>
#include <QStatusBar>
#include <QStandardPaths>
......@@ -35,7 +36,6 @@
#include <KSharedConfig>
#include <KStandardGameAction>
#include <KLocalizedString>
#include <KRandom>
#include <KSelectAction>
// Application specific includes
#include "lskat_debug.h"
......@@ -126,7 +126,7 @@ Mainwindow::Mainwindow(QWidget *parent)
((KSelectAction *)ACTION(QLatin1String("theme")))->setCurrentItem(mThemeIndexNo);
// Get the card deck
long seed = KRandom::random();
const quint32 seed = QRandomGenerator::global()->generate();
if (global_debug > 0) qCDebug(LSKAT_LOG) << "Random seed" << seed;
mDeck = new Deck(seed, this);
......
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