Commit 84faff4c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to QRandomGenerator

parent f22eb4c7
project (picmi)
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")
......
......@@ -21,6 +21,7 @@
#include <qglobal.h>
#include <QTime>
#include <QVector>
#include <QRandomGenerator>
static int box_count(const QList<Board::State> &data) {
int count = 0;
......@@ -50,17 +51,16 @@ void BoardMap::genRandom() {
/* To maintain a uniformly random selection of k elements:
* element i enters the selection with probability k/i. */
qsrand(QTime::currentTime().msec());
QVector<int> indices(m_box_count);
auto *generator = QRandomGenerator::global();
for (int i = 0; i < m_size; i++) {
if (i < m_box_count) {
indices[i] = i;
continue;
}
if (qrand() % i <= m_box_count) {
indices[qrand() % indices.size()] = i;
if (generator->bounded(i) <= m_box_count) {
indices[generator->bounded(indices.size())] = i;
}
}
......
......@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************* */
#include <QRandomGenerator>
#include <config.h>
#include "picmi.h"
......@@ -186,7 +186,7 @@ QPoint Picmi::hint()
return QPoint(0, 0);
}
const int idx = qrand() % incorrect_cells.size();
const int idx = QRandomGenerator::global()->bounded(incorrect_cells.size());
const QPoint cell(incorrect_cells.at(idx));
Board::State state = m_map->get(cell.x(), cell.y());
if (state == Board::Nothing) {
......
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