kdirshare: use KRandom::randomMax() for less round-trips

feels like a new KRandom::randomRange() method is needed

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-25 19:08:42 +02:00
parent a408a397a5
commit 77453ce6e9

View file

@ -26,6 +26,7 @@
#include <kconfiggroup.h>
#include <knotification.h>
#include <kdirnotify.h>
#include <krandom.h>
#include <kpluginfactory.h>
#include <kdebug.h>
@ -35,8 +36,9 @@ static quint16 getPort(const quint16 portmin, const quint16 portmax)
return portmax;
}
quint16 portnumber = 0;
while (portnumber < portmin || portnumber > portmax) {
portnumber = quint16(qrand());
while (portnumber < portmin) {
portnumber = quint16(KRandom::randomMax(portmax));
Q_ASSERT(portnumber <= portmax);
}
return portnumber;
}