Skip to content
Snippets Groups Projects
Commit 10f494ee authored by David Marcec's avatar David Marcec
Browse files

Better UUID randomness

parent 448290be
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <random>
#include "boost/optional.hpp" #include "boost/optional.hpp"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/swap.h" #include "common/swap.h"
...@@ -38,8 +39,12 @@ struct UUID { ...@@ -38,8 +39,12 @@ struct UUID {
// TODO(ogniK): Properly generate uuids based on RFC-4122 // TODO(ogniK): Properly generate uuids based on RFC-4122
const UUID& Generate() { const UUID& Generate() {
uuid[0] = (static_cast<u64>(std::rand()) << 32) | std::rand(); std::random_device device;
uuid[1] = (static_cast<u64>(std::rand()) << 32) | std::rand(); std::mt19937 gen(device());
std::uniform_int_distribution<uint64_t> distribution(1,
std::numeric_limits<uint64_t>::max());
uuid[0] = distribution(gen);
uuid[1] = distribution(gen);
return *this; return *this;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment