From cc4588e6fffa4214e2f7f3a08b7b082d7eb2d1da Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Sun, 31 Jan 2021 20:53:27 +0100 Subject: [PATCH] MeasurementArea.cc better randmomId --- .../geometry/MeasurementArea.cc | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/MeasurementComplexItem/geometry/MeasurementArea.cc b/src/MeasurementComplexItem/geometry/MeasurementArea.cc index 4f9a4fa95..e2c2bca9e 100644 --- a/src/MeasurementComplexItem/geometry/MeasurementArea.cc +++ b/src/MeasurementComplexItem/geometry/MeasurementArea.cc @@ -19,7 +19,7 @@ #define MAX_TILES 1000 #endif -QString randomId(); +QString randomId(std::size_t length = 10); using namespace geometry; namespace trans = bg::strategy::transform; @@ -726,13 +726,24 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth, return true; } -QString randomId() { - std::srand(std::time(nullptr)); - std::int64_t r = 0; - - for (int i = 0; i < 10; ++i) { - r ^= std::rand(); +QString randomId(std::size_t length) { + static const QString values( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + static std::uint64_t counter = 0; + static auto firstCall = std::chrono::high_resolution_clock::now(); + + auto delta = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - firstCall) + .count(); + + std::srand((unsigned int)delta ^ counter); + QString str; + for (int i = 0; i < length; ++i) { + int index = std::rand() % values.length(); + QChar c = values.at(index); + str.append(c); } - return QString::number(r); + ++counter; + return str; } -- 2.22.0