FOSSredder 0.5.0
Loading...
Searching...
No Matches
StableId.cpp
Go to the documentation of this file.
1
5
6#include "StableId.h"
7
8#include <cstddef>
9#include <random>
10#include <string_view>
11
12namespace core::utils {
13
14namespace {
15
16inline constexpr std::size_t kStableHexLength = 32;
17inline constexpr std::string_view kHexAlphabet = "0123456789abcdef";
18
19}
20
21std::string makeStableId()
22{
23 static thread_local std::mt19937_64 rng(std::random_device{}());
24 std::uniform_int_distribution<int> dist(0, static_cast<int>(kHexAlphabet.size() - 1));
25
26 std::string out;
27 out.reserve(kStableHexLength);
28 for (std::size_t i = 0; i < kStableHexLength; ++i) {
29 out.push_back(kHexAlphabet[static_cast<std::size_t>(dist(rng))]);
30 }
31 return out;
32}
33
34}
Declares private stable identifier helpers for core entity creation.
std::string makeStableId()
Generates a stable hex identifier for persisted entities.
Definition StableId.cpp:21