mirror of
https://git.suyu.dev/suyu/dynarmic
synced 2024-11-21 14:29:03 -07:00
tests/rand_int: Expose PRNG
This commit is contained in:
parent
8e6467bf45
commit
ecacb6cdc6
1 changed files with 9 additions and 3 deletions
|
@ -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 a new issue