1#ifndef NEFORCE_CORE_NUMERIC_RANDOM_HPP__
2#define NEFORCE_CORE_NUMERIC_RANDOM_HPP__
13NEFORCE_BEGIN_NAMESPACE__
63 static constexpr seed_type a = 1103515245;
70 seed_ = a * seed_ + c;
77 result =
static_cast<uint64_t>(generate_32bit()) << 32;
78 result |= generate_32bit();
106 template <
typename T>
117 const uint64_t value = generate_64bit();
119 return static_cast<T
>(product >> 32);
129 template <
typename T>
142 template <
typename T>
161 const uint64_t value = generate_64bit();
176 template <
typename T>
180 using IntT =
decay_t<
decltype(gen)>;
191 template <
typename T>
205 template <
typename T>
224 static constexpr size_t n = 624;
225 static constexpr size_t m = 397;
226 static constexpr seed_type a = 0x9908b0df;
229 static constexpr seed_type b = 0x9d2c5680;
231 static constexpr seed_type c = 0xefc60000;
237 void twist() noexcept;
239 seed_type generate_32bit() noexcept;
271 template <
typename T>
282 const uint64_t value = generate_64bit();
284 return static_cast<T
>(product >> 32);
294 template <
typename T>
307 template <
typename T>
326 const uint64_t value = generate_64bit();
341 template <
typename T>
345 using IntT =
decay_t<
decltype(gen)>;
356 template <
typename T>
370 template <
typename T>
386 static void get_random_bytes(
byte_t* buffer,
size_t length);
390 get_random_bytes(
reinterpret_cast<byte_t*
>(&value),
sizeof(value));
396 get_random_bytes(
reinterpret_cast<byte_t*
>(&value),
sizeof(value));
411 template <
typename T>
422 const uint64_t value = generate_64bit();
424 return static_cast<T
>(product >> 32);
434 template <
typename T>
447 template <
typename T>
450 return static_cast<T
>(secret::generate(
bool_constant<
sizeof(T) <= 4>()));
466 const uint64_t value = generate_64bit();
481 template <
typename T>
484 auto gen =
static_cast<T
>(secret::generate(
bool_constant<
sizeof(T) <= 4>()));
485 using IntT =
decay_t<
decltype(gen)>;
496 template <
typename T>
511 template <
typename T>
526NEFORCE_END_NAMESPACE__
static NEFORCE_NODISCARD constexpr T max() noexcept
获取类型的最大值
uint64_t next_uint64(uint64_t max) noexcept
生成 [0, max) 范围内的随机 64 位整数
T next_int() noexcept
生成完整范围的随机整数
T next_float(T min, T max) noexcept
生成 [min, max) 范围内的随机浮点数
T next_float(T max) noexcept
生成 [0, max) 范围内的随机浮点数
T next_float() noexcept
生成 [0, 1) 范围内的随机浮点数
uint64_t next_uint64() noexcept
生成完整范围的随机 64 位整数
random_lcd() noexcept
默认构造函数 默认使用当前时间戳值作为种子。
T next_int(T max) noexcept
生成 [0, max) 范围内的随机整数
T next_int(T min, T max) noexcept
生成 [min, max) 范围内的随机整数
T next_int(T max) noexcept
生成 [0, max) 范围内的随机整数
T next_int(T min, T max) noexcept
生成[min, max)范围内的随机整数
T next_float(T min, T max) noexcept
生成 [min, max) 范围内的随机浮点数
uint64_t next_uint64() noexcept
生成完整范围的随机 64 位整数
T next_float() noexcept
生成 [0, 1) 范围内的随机浮点数
uint64_t next_uint64(uint64_t max) noexcept
生成 [0, max) 范围内的随机 64 位整数
void set_seed(seed_type seed) noexcept
设置随机数种子
random_mt() noexcept
默认构造函数 默认使用当前时间戳值作为种子。
T next_int() noexcept
生成完整范围的随机整数
T next_float(T max) noexcept
生成 [0, max) 范围内的随机浮点数
static T next_int(T min, T max)
生成 [min, max) 范围内的随机整数
static uint64_t next_uint64(uint64_t max)
生成 [0, max) 范围内的随机 64 位整数
static bool system_supported()
检查系统是否支持真随机数生成
static T next_float(T max)
生成 [0, max) 范围内的随机浮点数
static T next_int()
生成完整范围的随机整数
static T next_float(T min, T max)
生成 [min, max) 范围内的随机浮点数
static T next_int(T max)
生成 [0, max) 范围内的随机整数
static T next_float()
生成 [0, 1) 范围内的随机浮点数
static uint64_t next_uint64()
生成完整范围的随机 64 位整数
NEFORCE_INLINE17 constexpr bool is_floating_point_v
is_floating_point的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_integral_v
is_integral的便捷变量模板
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位无符号整数类型
unsigned long long uint64_t
64位无符号整数类型
constexpr void generate(Iterator first, Iterator last, Generator gen)
用生成器的值填充范围
typename decay< T >::type decay_t
decay的便捷别名
bool_constant< true > true_type
表示true的类型
bool_constant< false > false_type
表示false的类型
integral_constant< bool, Value > bool_constant
布尔常量包装器