Commit cc4588e6 authored by Valentin Platzgummer's avatar Valentin Platzgummer

MeasurementArea.cc better randmomId

parent a4d09405
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define MAX_TILES 1000 #define MAX_TILES 1000
#endif #endif
QString randomId(); QString randomId(std::size_t length = 10);
using namespace geometry; using namespace geometry;
namespace trans = bg::strategy::transform; namespace trans = bg::strategy::transform;
...@@ -726,13 +726,24 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth, ...@@ -726,13 +726,24 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth,
return true; return true;
} }
QString randomId() { QString randomId(std::size_t length) {
std::srand(std::time(nullptr)); static const QString values(
std::int64_t r = 0; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
static std::uint64_t counter = 0;
for (int i = 0; i < 10; ++i) { static auto firstCall = std::chrono::high_resolution_clock::now();
r ^= std::rand();
auto delta = std::chrono::duration_cast<std::chrono::nanoseconds>(
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;
} }
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