41using uuid_t = std::array<std::uint8_t, 16>;
49 static std::mt19937_64& get_rng() {
50 thread_local static std::mt19937_64 rng__{std::random_device{}()};
68 std::uniform_int_distribution<std::uint8_t> dist{0, 255};
69 for (
auto&
byte : uuid) {
70 byte = dist(details::randgen::get_rng());
75 uuid[6] = (uuid[6] & 0x0F) | 0x40;
79 uuid[8] = (uuid[8] & 0x3F) | 0x80;
83inline std::ostream& operator<<(std::ostream& os,
const uuid_t& uuid) {
84 auto flags = os.flags();
85 os << std::hex << std::setfill(
'0');
86 for (
int i = 0; i < 16; ++i) {
87 if (i == 4 || i == 6 || i == 8 || i == 10) os <<
'-';
88 os << std::setw(2) << static_cast<unsigned>(uuid[i]);
105 std::ostringstream os;
107 std::string result = os.str();
Thread-local randomness.
Definition tec_guid.hpp:48
Common definitions and utilities for the tec namespace.
std::string generate()
Generate new GUID as hex string (in lowercase).
Definition tec_guid.hpp:115
std::array< std::uint8_t, 16 > uuid_t
16-byte GUID
Definition tec_guid.hpp:41
std::string to_string(const uuid_t &uuid)
Convert GUID to hex string (in lowercase).
Definition tec_guid.hpp:103
uuid_t generate_v4()
Generates 16-byte uuid_t version 4.
Definition tec_guid.hpp:61