这是两个随机数的函数,但是uniform_int_distribution<>在random库中定义时要求类型一定是整型,但是_Ty = int不被看做是整型,所以编译出错。uniform_real_distribution<>同理。请问有没有办法解决这个问题?
template <typename _Ty = int>
inline const _Ty random(const _Ty MIN = (numeric_limits<_Ty>::min)(), const _Ty MAX = (numeric_limits<_Ty>::max)())
{
static uniform_int_distribution<_Ty> random_pool(MIN, MAX);
return random_pool(seed);
}
template <typename _Ty = double>
inline const _Ty frandom(const _Ty MIN = (numeric_limits<_Ty>::min)(), const _Ty MAX = (numeric_limits<_Ty>::max)())
{
static uniform_real_distribution<_Ty> frandom_pool(MIN, MAX);
return frandom_pool(seed);
}
[Error] static assertion failed: result_type must be a floating point type
[Error] static assertion failed: template argument must be an integral type