From db2b5e06a36da5048ef07376ff7181dbc3c1c93b Mon Sep 17 00:00:00 2001 From: badaix Date: Wed, 30 Nov 2016 16:35:56 +0100 Subject: [PATCH] generateUUID --- common/utils.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/utils.h b/common/utils.h index 675ce303..955dff42 100644 --- a/common/utils.h +++ b/common/utils.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -265,6 +266,21 @@ static long uptime() } +/// http://stackoverflow.com/questions/2174768/generating-random-uuids-in-linux +static std::string generateUUID() +{ + std::srand(std::time(0)); + std::stringstream ss; + ss << std::setfill('0') << std::hex + << std::setw(4) << (std::rand() % 0xffff) << std::setw(4) << (std::rand() % 0xffff) + << "-" << std::setw(4) << (std::rand() % 0xffff) + << "-" << std::setw(4) << (std::rand() % 0xffff) + << "-" << std::setw(4) << (std::rand() % 0xffff) + << "-" << std::setw(4) << (std::rand() % 0xffff) << std::setw(4) << (std::rand() % 0xffff) << std::setw(4) << (std::rand() % 0xffff); + return ss.str(); +} + + /// https://gist.github.com/OrangeTide/909204 static std::string getMacAddress(int sock) {