Created
October 9, 2020 01:59
-
-
Save dendisuhubdy/9c62901d13c91f4c3b07d89a56f85064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
#include <sstream> | |
namespace uuid { | |
static std::random_device rd; | |
static std::mt19937 gen(rd()); | |
static std::uniform_int_distribution<> dis(0, 15); | |
static std::uniform_int_distribution<> dis2(8, 11); | |
std::string generate_uuid_v4() { | |
std::stringstream ss; | |
int i; | |
ss << std::hex; | |
for (i = 0; i < 8; i++) { | |
ss << dis(gen); | |
} | |
ss << "-"; | |
for (i = 0; i < 4; i++) { | |
ss << dis(gen); | |
} | |
ss << "-4"; | |
for (i = 0; i < 3; i++) { | |
ss << dis(gen); | |
} | |
ss << "-"; | |
ss << dis2(gen); | |
for (i = 0; i < 3; i++) { | |
ss << dis(gen); | |
} | |
ss << "-"; | |
for (i = 0; i < 12; i++) { | |
ss << dis(gen); | |
}; | |
return ss.str(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment