1#ifndef MSTL_CORE_NUMERIC_RANDOM_HPP__
2#define MSTL_CORE_NUMERIC_RANDOM_HPP__
32 static constexpr seed_type a = 1103515245;
62 seed_ = a * seed_ + c;
64 return static_cast<int>(
static_cast<double>(seed_) / m *
max);
90 seed_ = a * seed_ + c;
92 return static_cast<double>(seed_) / m;
128 static constexpr size_t n = 624;
129 static constexpr size_t m = 397;
130 static constexpr seed_type a = 0x9908b0df;
133 static constexpr seed_type b = 0x9d2c5680;
135 static constexpr seed_type c = 0xefc60000;
268 static void get_random_bytes(
byte_t* buffer,
size_t length);
static MSTL_NODISCARD constexpr T max() noexcept
获取类型的最大值
double next_double(const double min, const double max)
生成[min, max)范围内的随机双精度浮点数
random_lcd(random_lcd &&)=default
移动构造函数
double next_double(const double max)
生成[0.0, max)范围内的随机双精度浮点数
int next_int()
生成[0, INT32_MAX)范围内的随机整数
random_lcd(const random_lcd &)=default
拷贝构造函数
double next_double()
生成[0.0, 1.0)范围内的随机双精度浮点数
int next_int(const int max)
生成[0, max)范围内的随机整数
random_lcd()
默认构造函数 默认使用当前时间戳值作为种子。
random_lcd(const seed_type seed)
带种子构造函数
int next_int(const int min, const int max)
生成[min, max)范围内的随机整数
double next_double(const double min, const double max)
生成[min, max)范围内的随机双精度浮点数
int next_int(const int min, const int max)
生成[min, max)范围内的随机整数
void set_seed(seed_type seed)
设置随机数种子
int next_int()
生成[0, numeric_traits<int32_t>::max())范围内的随机整数
int next_int(int max)
生成[0, max)范围内的随机整数
random_mt(const random_mt &other)=default
拷贝构造函数
double next_double(const double max)
生成[0.0, max)范围内的随机双精度浮点数
random_mt(const seed_type seed)
带种子构造函数
double next_double()
生成[0.0, 1.0)范围内的随机双精度浮点数
random_mt()
默认构造函数 默认使用当前时间戳值作为种子。
random_mt(random_mt &&other) noexcept=default
移动构造函数
static int32_t next_int(int32_t min, int32_t max)
生成[min, max)范围内的随机整数
static double next_double()
生成[0.0, 1.0)范围内的随机双精度浮点数
static int32_t next_int(const int32_t max)
生成[0, max)范围内的随机整数
static bool is_supported()
检查系统是否支持真随机数生成
constexpr const T & max(const T &a, const T &b, Compare comp) noexcept(noexcept(comp(a, b)))
返回两个值中的较大者
constexpr const T & min(const T &a, const T &b, Compare comp) noexcept(noexcept(comp(b, a)))
返回两个值中的较小者
unsigned char byte_t
字节类型,定义为无符号字符
unsigned int uint32_t
32位无符号整数类型
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL