23 using FloatType =
Float;
33 std::random_device rd;
34 _re.seed(_seed = rd());
37 _re.seed(_seed = seed);
52 static std::uniform_real_distribution<T> dist_double;
54 using D = std::decay_t<
decltype(dist_double)>;
55 using P =
typename D::param_type;
56 dist_double.param(
P{min, max});
57 return dist_double(_re);
73 static std::uniform_int_distribution<T> dist_int;
75 using D = std::decay_t<
decltype(dist_int)>;
76 using P =
typename D::param_type;
77 dist_int.param(
P{min, max});
88 static std::normal_distribution<T> dist;
90 using D = std::decay_t<
decltype(dist)>;
91 using P =
typename D::param_type;
92 dist.param(
P{ u, o });
96 static FloatType
FloatNormal(FloatType u = 0_f, FloatType o = 1_f)
104 FloatType scale = 1/3_f,
105 FloatType min = -1, FloatType max = 1)
107#if DL_PLATFORM == DL_PLATFORM_LINUX
110 return std::clamp(
FloatNormal() * scale, min, max);
123 static int Int(
int min,
int max)
130 static unsigned Uint(
unsigned min,
unsigned max)
137 static size_t SizeT(
size_t min,
size_t max)
147 template <
typename C>
150 assert(!container.empty());
152 auto iter = container.begin();
153 advance(iter, index);
162 template <
typename C>
165 assert(!container.empty());
167 auto iter = container.begin();
168 advance(iter, index);
170 container.erase(iter);
176 return {
Int(p0[0], p1[0]),
Int(p0[1], p1[1]) };
180 return {
Uint(p0[0], p1[0]),
Uint(p0[1], p1[1]) };
185 return { std::cos(r), std::sin(r)};
192 return Int(0, 99) < 50;
197 static float Angle(
float min = 0,
float max = 3.1415926f * 2.0f)
199 return Float(min, max);
208 static uint32_t _seed;
209 static std::default_random_engine _re;
static auto & Select(C &container)
从容器随机选择一个
static size_t SizeT(size_t min, size_t max)
返回[min,max]区间的 size_t型整数
static T Float(T min, T max)
返回[min,max)区间的 浮点数随机值
static PointU ExPointU(const PointU &p0, const PointU &p1)
static T Integer(T min, T max)
返回[min,max]区间的 随机整数
static int Int(int min, int max)
返回[min,max]区间的 int型整数
static Point ExPoint(const Point &p0, const Point &p1)
static FloatType FloatNormalX(FloatType scale=1/3_f, FloatType min=-1, FloatType max=1)
返回标准正态分布的缩放值,且限制到指定值
static void SetSeed(uint32_t seed)
设置随机数种子
static std::default_random_engine & GetEngine()
一般不使用,传给标准库接口才使用
static Position ExDirection()
static unsigned Uint(unsigned min, unsigned max)
返回[min,max]区间的 unsigned型整数
static T Normal(T u=0, T o=1)
返回期望为u,标准差为o的正态分布随机值
static bool Percent(int v)
返回百分比命中
static FloatType FloatNormal(FloatType u=0_f, FloatType o=1_f)
static float Angle(float min=0, float max=3.1415926f *2.0f)
返回角度(弧度制)
static auto SelectErase(C &container)
从容器随机选择一个,并且从容器移除
void log(std::string_view str, const std::source_location location=std::source_location::current())
以当前设置输出
constexpr T clamp(const T &x, const T &a, const T &b)
限制数值到 [a, b]