501d7ce602
Merge commit '621367dce8abf82e3924679d72f4da0913cc1520' as 'externals/oaknut'
20 lines
602 B
C++
20 lines
602 B
C++
// SPDX-FileCopyrightText: Copyright (c) 2022 merryhime <https://mary.rs>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <random>
|
|
#include <type_traits>
|
|
|
|
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);
|
|
}
|