add 'random' library

This commit is contained in:
MihailRis 2025-09-16 19:01:47 +03:00
parent 78574f2460
commit eb760e1776
5 changed files with 111 additions and 0 deletions

19
src/util/random.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include <random>
#include <string>
#include <algorithm>
namespace util {
template <class T = std::mt19937, std::size_t N = T::state_size * sizeof(typename T::result_type)>
typename std::enable_if<N, T>::type seeded_random_engine(
std::random_device& source
) {
std::random_device::result_type randomData[(N - 1) / sizeof(source()) + 1];
std::generate(std::begin(randomData), std::end(randomData), std::ref(source));
std::seed_seq seeds(std::begin(randomData), std::end(randomData));
return T(seeds);
}
std::string generate_uuid();
}