generateUUID

This commit is contained in:
badaix 2016-11-30 16:35:56 +01:00
parent ad568f1076
commit db2b5e06a3

View file

@ -30,6 +30,7 @@
#include <vector>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <memory>
#include <cerrno>
#include <iterator>
@ -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)
{