MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / generateRandomUUID

Method generateRandomUUID

src/common/types/uuid.cpp:116–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116uuid UUID::generateRandomUUID(RandomEngine* engine) {
117 uint8_t bytes[16];
118 for (int i = 0; i < 16; i += 4) {
119 *reinterpret_cast<uint32_t*>(bytes + i) = engine->nextRandomInteger();
120 }
121 // variant must be 10xxxxxx
122 bytes[8] &= 0xBF;
123 bytes[8] |= 0x80;
124 // version must be 0100xxxx
125 bytes[6] &= 0x4F;
126 bytes[6] |= 0x40;
127
128 int128_t result = 0;
129 result.high = 0;
130 result.high |= ((int64_t)bytes[0] << 56);
131 result.high |= ((int64_t)bytes[1] << 48);
132 result.high |= ((int64_t)bytes[2] << 40);
133 result.high |= ((int64_t)bytes[3] << 32);
134 result.high |= ((int64_t)bytes[4] << 24);
135 result.high |= ((int64_t)bytes[5] << 16);
136 result.high |= ((int64_t)bytes[6] << 8);
137 result.high |= bytes[7];
138 result.low = 0;
139 result.low |= ((uint64_t)bytes[8] << 56);
140 result.low |= ((uint64_t)bytes[9] << 48);
141 result.low |= ((uint64_t)bytes[10] << 40);
142 result.low |= ((uint64_t)bytes[11] << 32);
143 result.low |= ((uint64_t)bytes[12] << 24);
144 result.low |= ((uint64_t)bytes[13] << 16);
145 result.low |= ((uint64_t)bytes[14] << 8);
146 result.low |= bytes[15];
147 return uuid{result};
148}
149
150const regex::RE2& UUID::regexPattern() {
151 static regex::RE2 retval("(?i)[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}");

Callers

nothing calls this directly

Calls 1

nextRandomIntegerMethod · 0.80

Tested by

no test coverage detected