2020-04-23 16:25:11 +02:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2020 MerryMage
|
|
|
|
* SPDX-License-Identifier: 0BSD
|
|
|
|
*/
|
2016-07-07 13:01:47 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <random>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2022-07-19 21:47:26 +02:00
|
|
|
namespace detail {
|
|
|
|
inline std::mt19937 g_rand_int_generator = [] {
|
|
|
|
std::random_device rd;
|
|
|
|
std::mt19937 mt{rd()};
|
|
|
|
return mt;
|
|
|
|
}();
|
|
|
|
} // namespace detail
|
|
|
|
|
2021-05-22 15:51:20 +02:00
|
|
|
template<typename T>
|
2016-07-07 13:01:47 +02:00
|
|
|
T RandInt(T min, T max) {
|
2019-05-04 04:44:37 +02:00
|
|
|
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>,
|
2016-07-07 13:01:47 +02:00
|
|
|
"Using char with uniform_int_distribution is undefined behavior.");
|
|
|
|
|
|
|
|
std::uniform_int_distribution<T> rand(min, max);
|
2022-07-19 21:47:26 +02:00
|
|
|
return rand(detail::g_rand_int_generator);
|
2016-07-07 13:01:47 +02:00
|
|
|
}
|