mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 03:51:50 +00:00
add 'random' library
This commit is contained in:
parent
78574f2460
commit
eb760e1776
5 changed files with 111 additions and 0 deletions
19
src/util/random.hpp
Normal file
19
src/util/random.hpp
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue