Skip to content
Snippets Groups Projects
Commit e04c4c5e authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

following standard for random uuids

parent bf188122
Branches
Tags
No related merge requests found
...@@ -35,6 +35,12 @@ RandomUUID::RandomUUID() ...@@ -35,6 +35,12 @@ RandomUUID::RandomUUID()
std::random_device rd2; std::random_device rd2;
std::mt19937 gen2( rd2() ); std::mt19937 gen2( rd2() );
b_ = dis(gen2); b_ = dis(gen2);
//unsure how independent these two random numbers really are
//setting version numbers
//https://en.m.wikipedia.org/wiki/Universally_unique_identifier
a_ = ((a_ & 0xFFFFFFFFFFFF0FFF) | 0x0000000000004000);
b_ = ((b_ & 0x3FFFFFFFFFFFFFFF) | 0x8000000000000000);
} }
RandomUUID::RandomUUID( const UIntType a, const UIntType b) RandomUUID::RandomUUID( const UIntType a, const UIntType b)
...@@ -49,7 +55,7 @@ std::string RandomUUID::toString() const ...@@ -49,7 +55,7 @@ std::string RandomUUID::toString() const
<< std::setfill('0') << std::setfill('0')
<< std::setw(8) << (a_ >> 32) << "-" << std::setw(8) << (a_ >> 32) << "-"
<< std::setw(4) << ((a_&0xFFFFFFFF)>>16) << "-" << std::setw(4) << ((a_&0xFFFFFFFF)>>16) << "-"
<< std::setw(4) <<(a_&0xFFFF) << "-" << std::setw(4) << (a_&0xFFFF) << "-"
<< std::setw(4) << (b_ >> 48) << "-" << std::setw(4) << (b_ >> 48) << "-"
<< std::setw(12) << (b_&0xFFFFFFFFFFFF); << std::setw(12) << (b_&0xFFFFFFFFFFFF);
return ss.str(); return ss.str();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment