From 90ae7d9b7244b3d9a14f03a96e919859580f5a90 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sat, 15 Jan 2022 17:49:24 +0100 Subject: Replace uses of q(s)rand with C++11 stuff --- src/crsm.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/crsm.cpp') 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 dist{0, possibleCharacters.length() - 1}; QString randomString; for(int i=0; i 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 -- cgit v1.2.3-54-g00ecf