Skip to content

Commit

Permalink
Fixed issue with random generator in samples helper
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonRaNet committed Jan 7, 2024
1 parent ee6a840 commit c7662d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions samples/shared/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
#include <QNetworkDiskCache>
#include <QRandomGenerator>

namespace {
int randomInt()
int Helpers::randomInt(int lowest, int highest)
{
return static_cast<int>(QRandomGenerator::global()->generate());
}
return static_cast<int>(QRandomGenerator::global()->bounded(lowest, highest));
}

QGV::GeoRect Helpers::randRect(QGVMap* geoMap, const QGV::GeoRect& targetArea, const QSizeF& size)
Expand All @@ -49,15 +47,15 @@ QGV::GeoPos Helpers::randPos(const QGV::GeoRect& targetArea)
const double lonRange = targetArea.lonRigth() - targetArea.lonLeft();
static const int range = 1000;

return { targetArea.latBottom() + latRange * (randomInt() % range) / range,
targetArea.lonLeft() + lonRange * (randomInt() % range) / range };
return { targetArea.latBottom() + latRange * (randomInt(0, range)) / range,
targetArea.lonLeft() + lonRange * (randomInt(0, range)) / range };
}

QSizeF Helpers::randSize(int baseSize)
{
const int range = -baseSize / 2;
const int range = baseSize / 2;

return QSize(baseSize + (randomInt() % range), baseSize + (randomInt() % range));
return QSize(baseSize + (randomInt(0, range)), baseSize - (randomInt(0, range)));
}

void Helpers::setupCachedNetworkAccessManager(QObject* parent)
Expand Down
1 change: 1 addition & 0 deletions samples/shared/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace Helpers {
void setupCachedNetworkAccessManager(QObject* parent);

int randomInt(int lowest, int highest);
QGV::GeoRect randRect(QGVMap* geoMap, const QGV::GeoRect& targetArea, const QSizeF& size);
QGV::GeoRect randRect(QGVMap* geoMap, const QGV::GeoRect& targetArea, int baseSize);
QGV::GeoPos randPos(const QGV::GeoRect& targetArea);
Expand Down

0 comments on commit c7662d6

Please sign in to comment.