From: Ivailo Monev Date: Thu, 29 Sep 2022 23:04:12 +0000 (+0300) Subject: kdeplasma-addons: make use of KRandom::randomMax() X-Git-Tag: 4.22.0~115 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d0d629510f0284f447773b7c291025b28bb55ca4;p=kde%2Fkde-extraapps.git kdeplasma-addons: make use of KRandom::randomMax() Signed-off-by: Ivailo Monev --- diff --git a/kdeplasma-addons/applets/life/life.cpp b/kdeplasma-addons/applets/life/life.cpp index 215013a2..5952879d 100644 --- a/kdeplasma-addons/applets/life/life.cpp +++ b/kdeplasma-addons/applets/life/life.cpp @@ -28,6 +28,7 @@ #include #include #include +#include Life::Life(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args), @@ -250,7 +251,7 @@ void Life::initGame() void Life::resetGame() { for (int i = 0; i < (m_cellsArrayHeight * m_cellsArrayWidth); i++){ - m_cells[i] = (rand() % 100) < m_popDensityNumber ? 1 : 0; + m_cells[i] = (KRandom::randomMax(100) < m_popDensityNumber ? 1 : 0); } if (m_reflectHorizontal){ diff --git a/kdeplasma-addons/applets/paste/pastemacroexpander.cpp b/kdeplasma-addons/applets/paste/pastemacroexpander.cpp index 747cd611..e2250d57 100644 --- a/kdeplasma-addons/applets/paste/pastemacroexpander.cpp +++ b/kdeplasma-addons/applets/paste/pastemacroexpander.cpp @@ -184,7 +184,7 @@ QString PasteMacroExpander::password(const QString& args) rand = KRandom::random(); } while (rand >= top); - result += chars[rand % setSize]; + result += chars[KRandom::randomMax(setSize)]; } //kDebug() << result; return result; diff --git a/kdeplasma-addons/dataengines/potd/flickrprovider.cpp b/kdeplasma-addons/dataengines/potd/flickrprovider.cpp index f16200ac..06fdcaca 100644 --- a/kdeplasma-addons/dataengines/potd/flickrprovider.cpp +++ b/kdeplasma-addons/dataengines/potd/flickrprovider.cpp @@ -37,7 +37,6 @@ class FlickrProvider::Private Private( FlickrProvider *parent ) : mParent( parent ) { - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); } void pageRequestFinished( KJob* ); diff --git a/kdeplasma-addons/wallpapers/virus/alife.cpp b/kdeplasma-addons/wallpapers/virus/alife.cpp index 1f0d0eb3..b4c76032 100644 --- a/kdeplasma-addons/wallpapers/virus/alife.cpp +++ b/kdeplasma-addons/wallpapers/virus/alife.cpp @@ -8,8 +8,9 @@ */ #include "alife.h" -#include +#include #include +#include #define VIRUS_GENOME_SIZE 38 #define MAX_AGE 8 @@ -90,8 +91,8 @@ void Alife::initVirus(){ //create the needed viruses so that we have in total "amount" viruses void Alife::createViruses(int amount){ for(int i = m_livingCells.size(); i < amount; i++) { - int x = rand() % m_width; - int y = rand() % m_height; + int x = KRandom::randomMax(m_width); + int y = KRandom::randomMax(m_height); struct cell *temp = &m_cells[x][y]; //cell already alive @@ -105,10 +106,10 @@ void Alife::createViruses(int amount){ //initial code for(int i = 0; i < 7; i++) { - temp->code[i] = rand()%12; + temp->code[i] = KRandom::randomMax(12); } - temp->code[rand()%7] = 7; //cheating, jumpstart evolution + temp->code[KRandom::randomMax(7)] = 7; //cheating, jumpstart evolution /*temp->code[0] = 4; temp->code[1] = 12; @@ -155,7 +156,7 @@ void Alife::resetCell(struct cell *temp) //REMINDER: Update if a new op is added uchar Alife::randomCode() { - return rand() % 20; + return KRandom::randomMax(20); } //Executes the code of a certain living cell @@ -188,7 +189,7 @@ void Alife::executeCell(int id) stop = true; break; case 1://random value - reg = rand() % 4; + reg = KRandom::randomMax(4); break; case 2: //change direction facing = reg & 3; @@ -381,7 +382,7 @@ bool Alife::reproduce(struct cell* cell, int direction, QRgb color) //give a unfair advantage to darker places int prob = (((qRed(color) + qGreen(color) + qBlue(color))/ 255.)+1);// 0 - 765 - if(rand() % prob != 0){ + if(KRandom::randomMax(prob) != 0){ return false; } @@ -395,26 +396,26 @@ bool Alife::reproduce(struct cell* cell, int direction, QRgb color) memcpy(newCell->code,cell->code,VIRUS_GENOME_SIZE); - int mutate = rand() % 3; + int mutate = KRandom::randomMax(3); if(mutate) { //normal mutation - int mutations = rand() % 5; + int mutations = KRandom::randomMax(5); for(int i = 0; i < mutations; i++) { - int index = rand() % VIRUS_GENOME_SIZE; + int index = KRandom::randomMax(VIRUS_GENOME_SIZE); newCell->code[index] = randomCode(); } - int duplication = rand() % 3; + int duplication = KRandom::randomMax(3); for(int i = 0; i < duplication; i++) { - int start = rand() % VIRUS_GENOME_SIZE; - int end = start + rand() % ( VIRUS_GENOME_SIZE - start); + int start = KRandom::randomMax(VIRUS_GENOME_SIZE); + int end = start + KRandom::randomMax( VIRUS_GENOME_SIZE - start); memcpy(&newCell->code[end],&cell->code[start],VIRUS_GENOME_SIZE - end); } - int deletion = rand() % 3; + int deletion = KRandom::randomMax(3); for(int i = 0; i < deletion; i++) { - int start = rand() % VIRUS_GENOME_SIZE; - int end = start + rand() % ( VIRUS_GENOME_SIZE - start); + int start = KRandom::randomMax(VIRUS_GENOME_SIZE); + int end = start + KRandom::randomMax( VIRUS_GENOME_SIZE - start); memcpy(&newCell->code[start],&cell->code[end],VIRUS_GENOME_SIZE - end); memset(&newCell->code[end], 0, VIRUS_GENOME_SIZE - end); }