mirror of
https://github.com/Vita3K/dynarmic.git
synced 2024-11-23 05:29:48 +00:00
tests/rand_int: Expose PRNG
This commit is contained in:
parent
8e6467bf45
commit
ecacb6cdc6
@ -8,14 +8,20 @@
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
namespace detail {
|
||||
inline std::mt19937 g_rand_int_generator = [] {
|
||||
std::random_device rd;
|
||||
std::mt19937 mt{rd()};
|
||||
return mt;
|
||||
}();
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
T RandInt(T min, T max) {
|
||||
static_assert(std::is_integral_v<T>, "T must be an integral type.");
|
||||
static_assert(!std::is_same_v<T, signed char> && !std::is_same_v<T, unsigned char>,
|
||||
"Using char with uniform_int_distribution is undefined behavior.");
|
||||
|
||||
static std::random_device rd;
|
||||
static std::mt19937 mt(rd());
|
||||
std::uniform_int_distribution<T> rand(min, max);
|
||||
return rand(mt);
|
||||
return rand(detail::g_rand_int_generator);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user