summaryrefslogtreecommitdiffstats
path: root/src/crsm.cpp
diff options
context:
space:
mode:
authorMarkus Mittendrein <maxmitti@maxmitti.tk>2022-01-15 17:49:24 +0100
committerMarkus Mittendrein <maxmitti@maxmitti.tk>2022-01-15 17:49:24 +0100
commit90ae7d9b7244b3d9a14f03a96e919859580f5a90 (patch)
treebedf4bd96001117b86a783d8514cebc958f7c78f /src/crsm.cpp
parentb660519e1915356214c31bd401b01aa750a961a1 (diff)
downloadmanager-90ae7d9b7244b3d9a14f03a96e919859580f5a90.tar.gz
manager-90ae7d9b7244b3d9a14f03a96e919859580f5a90.zip
Replace uses of q(s)rand with C++11 <random> stuff
Diffstat (limited to 'src/crsm.cpp')
-rw-r--r--src/crsm.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/crsm.cpp b/src/crsm.cpp
index 93dc9d7..b5f0049 100644
--- a/src/crsm.cpp
+++ b/src/crsm.cpp
@@ -19,7 +19,6 @@ CRSM::CRSM(QObject *parent) :
control.setController(this);
parser.addTarget(this);
- qsrand((uint)QDateTime::currentMSecsSinceEpoch());
codec = QTextCodec::codecForName("Windows-1252");
outputBuffer.setFileName(MGMT_BUFFER_FILENAME);
@@ -714,14 +713,15 @@ void CRSM::dccChatRequest(const ClientInfo &client, QString extraArgs)
}
// modified version of http://stackoverflow.com/a/18866593
-QString GetRandomString(int length = 5)
+QString GetRandomString(int length, std::default_random_engine& rng)
{
static const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+ std::uniform_int_distribution<int> dist{0, possibleCharacters.length() - 1};
QString randomString;
for(int i=0; i<length; ++i)
{
- int index = qrand() % possibleCharacters.length();
+ const auto index = dist(rng);
QChar nextChar = possibleCharacters.at(index);
randomString.append(nextChar);
}
@@ -748,7 +748,7 @@ void CRSM::newDCCConnection()
QString identifier;
do
{
- identifier = GetRandomString();
+ identifier = GetRandomString(5, rng);
}
while(dccConnectionIdentifiers.contains(identifier));
@@ -775,12 +775,14 @@ void CRSM::disconnectedDCCConnection()
void CRSM::updateNextAutoScens()
{
if(autolist.length() <= 0) return;
+
+ std::uniform_int_distribution<int> autolistDist{0, autolist.length() - 1};
while(nextAutoScens.length() < Config.Hosting.UserListLength || (nextAutoScens.length() <= 0))
{
ScenarioSettings next("");
if(Config.Hosting.RandomizeAuto)
{
- next = autolist.at(qrand() % autolist.length());
+ next = autolist.at(autolistDist(rng));
}
else
{
@@ -789,7 +791,7 @@ void CRSM::updateNextAutoScens()
}
if(next.randomLeague)
{
- next.league = qrand() % 2;
+ next.league = boolRng();
}
nextAutoScens.append(next);
}
@@ -2379,7 +2381,7 @@ void CRSM::watchdog()
if(watchDogString.isEmpty())
{
watchDogTimer.start(Config.Clonk.Server.Watchdog.Timeout * 1000);
- watchDogString = GetRandomString(20);
+ watchDogString = GetRandomString(20, rng);
control.watchdog(watchDogString);
}
else