yuzu-early/externals/dynarmic/tests/rand_int.h

22 lines
611 B
C
Raw Normal View History

2020-12-28 16:15:37 +01:00
/* This file is part of the dynarmic project.
* Copyright (c) 2020 MerryMage
* SPDX-License-Identifier: 0BSD
*/
#pragma once
#include <random>
#include <type_traits>
2021-05-30 08:36:49 +02:00
template<typename T>
2020-12-28 16:15:37 +01:00
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);
}