Sync public subset from Flux (private)

This commit is contained in:
Gitea CI
2025-10-06 20:14:13 +00:00
parent 272e77c536
commit b2d00af0e1
390 changed files with 152131 additions and 0 deletions

37
include/utils/random.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include "./core/omp_config.h"
#include <random>
namespace utils{
// Shared engine
inline std::mt19937& rng() {
static std::random_device rd;
static std::mt19937 gen(rd());
return gen;
}
// Integral overload
template <
typename T,
typename std::enable_if<std::is_integral<T>::value, int>::type = 0
>
T random(T low, T high) {
std::uniform_int_distribution<T> dist(low, high);
return dist(rng());
}
// Floating-point overload
template <
typename T,
typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0
>
T random(T low, T high) {
std::uniform_real_distribution<T> dist(low, high);
return dist(rng());
}
} // end namespace utils