MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / CreateRandomUUID

Function CreateRandomUUID

src/loggers/groot2_publisher.cpp:36–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34namespace
35{
36std::array<char, 16> CreateRandomUUID()
37{
38 std::random_device rd;
39 std::mt19937 gen(rd());
40 std::uniform_int_distribution<uint32_t> dist;
41 std::array<char, 16> out{};
42 char* bytes = out.data();
43 for(int i = 0; i < 16; i += 4)
44 {
45 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
46 *reinterpret_cast<uint32_t*>(bytes + i) = dist(gen);
47 }
48 // variant must be 10xxxxxx
49 bytes[8] &= static_cast<char>(0xBF);
50 bytes[8] |= static_cast<char>(0x80);
51
52 // version must be 0100xxxx
53 bytes[6] &= 0x4F;
54 bytes[6] |= 0x40;
55
56 return out;
57}
58} // namespace
59
60struct Groot2Publisher::PImpl

Callers 1

serverLoopMethod · 0.85

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected