1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Use proper random for IPC

This commit is contained in:
tux3 2015-05-19 20:37:42 +02:00
parent 4306f87df4
commit a841224683
No known key found for this signature in database
GPG Key ID: 7E086DD661263264

View File

@ -12,14 +12,13 @@
See the COPYING file for more details. See the COPYING file for more details.
*/ */
#include "src/ipc.h" #include "src/ipc.h"
#include "src/misc/settings.h" #include "src/misc/settings.h"
#include <QDebug> #include <QDebug>
#include <QCoreApplication> #include <QCoreApplication>
#include <random>
#include <unistd.h> #include <unistd.h>
IPC::IPC() IPC::IPC()
: globalMemory{"qtox-" IPC_PROTOCOL_VERSION} : globalMemory{"qtox-" IPC_PROTOCOL_VERSION}
{ {
@ -35,8 +34,9 @@ IPC::IPC()
// This is a safety measure, in case one of the clients crashes // This is a safety measure, in case one of the clients crashes
// If the owner exits normally, it can set the timestamp to 0 first to immediately give ownership // If the owner exits normally, it can set the timestamp to 0 first to immediately give ownership
qsrand(time(0)); std::default_random_engine randEngine((std::random_device()()));
globalId = ((uint64_t)qrand()) * ((uint64_t)qrand()) * ((uint64_t)qrand()); std::uniform_int_distribution<uint64_t> distribution;
globalId = distribution(randEngine);
qDebug() << "Our global ID is " << globalId; qDebug() << "Our global ID is " << globalId;
if (globalMemory.create(sizeof(IPCMemory))) if (globalMemory.create(sizeof(IPCMemory)))
{ {