typedef std::array< char unsigned, (128u / CHAR_BIT) + !!(128u % CHAR_BIT) > uuid_t;
I think UUIDs would be a good fit for the C++ standard library, but as a vocabulary class type, not just some alias for an array.
Keep in mind that there are different versions of UUIDs, and not every 128-bit pattern is a valid UUID. Version 4 in particular is the one populated with random numbers. If we did have 128-bit integers, this is how we could generate a random UUID:
std::uint128_t random_uuid_v4() {
return std::experimental::randint<std::uint128_t>(0, -1)
& 0xffff'ffff'ffff'003f'ff0f'ffff'ffff'ffff // clear version and variant
| 0x0000'0000'0000'0080'0040'0000'0000'0000; // set to version 4 and IETF variant
}
Notice how certain bits are constant.