qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit());
#endif
- qsrand(std::random_device()());
-
CmdOptions options;
options.silent = false;
options.trustSSL = false;
#include <QStandardPaths>
#include <QCollator>
#include <QSysInfo>
+#include <qrandom.h>
#ifdef Q_OS_UNIX
bool Utility::writeRandomFile(const QString &fname, int size)
{
int maxSize = 10 * 10 * 1024;
- qsrand(QDateTime::currentMSecsSinceEpoch());
if (size == -1)
- size = qrand() % maxSize;
+ size = rand() % maxSize;
QString randString;
for (int i = 0; i < size; i++) {
- int r = qrand() % 128;
+ int r = rand() % 128;
randString.append(QChar(r));
}
return in.toHtmlEscaped();
}
+int Utility::rand()
+{
+ return QRandomGenerator::global()->bounded(0, RAND_MAX);
+}
+
void Utility::sleep(int sec)
{
QThread::sleep(sec);
* @{
*/
namespace Utility {
+ OCSYNC_EXPORT int rand();
OCSYNC_EXPORT void sleep(int sec);
OCSYNC_EXPORT void usleep(int usec);
OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);
// Invalid? (Unset at the very first launch)
if(segment < 0 || segment > 99) {
// Save valid segment value, normally has to be done only once.
- segment = qrand() % 99;
+ segment = Utility::rand() % 99;
settings.setValue(QLatin1String(updateSegmentC), segment);
}
int overhead = 1 + 1 + 2 + 8; // slash dot dot-tilde ffffffff"
int spaceForFileName = qMin(254, tmpFileName.length() + overhead) - overhead;
if (tmpPath.length() > 0) {
- return tmpPath + '/' + '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
+ return tmpPath + '/' + '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(Utility::rand() % 0xFFFFFFFF), 16));
} else {
- return '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
+ return '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(Utility::rand() % 0xFFFFFFFF), 16));
}
}
void PropagateUploadFileNG::startNewUpload()
{
ASSERT(propagator()->_activeJobList.count(this) == 1);
- _transferId = uint(qrand() ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16) ^ qHash(_fileToUpload._file));
+ _transferId = uint(Utility::rand() ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16) ^ qHash(_fileToUpload._file));
_sent = 0;
_currentChunk = 0;
{
_chunkCount = int(std::ceil(_fileToUpload._size / double(chunkSize())));
_startChunk = 0;
- _transferId = uint(qrand()) ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16);
+ _transferId = uint(Utility::rand()) ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16);
const SyncJournalDb::UploadInfo progressInfo = propagator()->_journal->getUploadInfo(_item->_file);
inline QByteArray generateEtag() {
- return QByteArray::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(), 16) + QByteArray::number(qrand(), 16);
+ return QByteArray::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(), 16) + QByteArray::number(OCC::Utility::rand(), 16);
}
inline QByteArray generateFileId() {
- return QByteArray::number(qrand(), 16);
+ return QByteArray::number(OCC::Utility::rand(), 16);
}
class PathComponents : public QStringList {
#endif
public:
- TestFolderWatcher() {
- qsrand(QTime::currentTime().msec());
+ TestFolderWatcher()
+ {
QDir rootDir(_root.path());
_rootPath = rootDir.canonicalPath();
qDebug() << "creating test directory tree in " << _rootPath;
QString _root;
private slots:
- void initTestCase() {
- qsrand(QTime::currentTime().msec());
-
- _root = QDir::tempPath() + "/" + "test_" + QString::number(qrand());
+ void initTestCase()
+ {
+ _root = QDir::tempPath() + "/" + "test_" + QString::number(OCC::Utility::rand());
qDebug() << "creating test directory tree in " << _root;
QDir rootDir(_root);
rootDir.mkpath(_root + "/a1/b2/c1");
rootDir.mkpath(_root + "/a1/b3/c3");
rootDir.mkpath(_root + "/a2/b3/c3");
-
}
// Test the recursive path listing function findFoldersBelow
void testLaunchOnStartup()
{
- qsrand(QDateTime::currentDateTime().toTime_t());
- QString postfix = QString::number(qrand());
+ QString postfix = QString::number(OCC::Utility::rand());
const QString appName = QString::fromLatin1("testLaunchOnStartup.%1").arg(postfix);
const QString guiName = "LaunchOnStartup GUI Name";