24 using FloatType =
Float;
34 std::random_device rd;
35 _re.seed(_seed = rd());
38 _re.seed(_seed = seed);
53 static std::uniform_real_distribution<T> dist_double;
55 using D = std::decay_t<
decltype(dist_double)>;
56 using P =
typename D::param_type;
57 dist_double.param(
P{min, max});
58 return dist_double(_re);
74 static std::uniform_int_distribution<T> dist_int;
76 using D = std::decay_t<
decltype(dist_int)>;
77 using P =
typename D::param_type;
78 dist_int.param(
P{min, max});
89 static std::normal_distribution<T> dist;
91 using D = std::decay_t<
decltype(dist)>;
92 using P =
typename D::param_type;
93 dist.param(
P{ u, o });
97 static FloatType
FloatNormal(FloatType u = 0_f, FloatType o = 1_f)
105 FloatType scale = 1/3_f,
106 FloatType min = -1, FloatType max = 1)
108#if DL_PLATFORM == DL_PLATFORM_LINUX
111 return std::clamp(
FloatNormal() * scale, min, max);
124 static int Int(
int min,
int max)
131 static unsigned Uint(
unsigned min,
unsigned max)
138 static size_t SizeT(
size_t min,
size_t max)
143 static std::array<std::byte, N>
Array()
145 std::array<std::byte, N> ret;
148 for (
size_t i = 0; i <
X; ++i)
150 ((uint64_t*)ret.data())[i] =
Integer<uint64_t>(0, (std::numeric_limits<uint64_t>::max)());
152 uint8_t* p = (uint8_t*)ret.data() +
X * 8;
153 for (
size_t j = 0; j <
Y; ++j)
155 p[j] = (uint8_t)
Int(0, 7);
165 for (
size_t i = 0; i <
X; ++i)
167 ((uint64_t*)ret.data())[i] =
Integer<uint64_t>(0, (std::numeric_limits<uint64_t>::max)());
169 uint8_t* p = (uint8_t*)ret.data() +
X * 8;
170 for (
size_t j = 0; j <
Y; ++j)
172 p[j] = (uint8_t)
Int(0, 7);
182 template <
typename C>
185 assert(!container.empty());
187 auto iter = container.begin();
188 advance(iter, index);
197 template <
typename C>
200 assert(!container.empty());
202 auto iter = container.begin();
203 advance(iter, index);
205 container.erase(iter);
211 return {
Int(p0[0], p1[0]),
Int(p0[1], p1[1]) };
215 return {
Uint(p0[0], p1[0]),
Uint(p0[1], p1[1]) };
220 return { std::cos(r), std::sin(r)};
227 return Int(0, 99) < v;
232 static float Angle(
float min = 0,
float max = 3.1415926f * 2.0f)
234 return Float(min, max);
236 static float Float(
const std::array<float, 2>& mm)
238 return Float(mm[0], mm[1]);
242 return Float(mm[0], mm[1]);
250 static uint32_t _seed;
251 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 float Float(const dl::Array< float, 2 > &mm)
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 Buffer BufferX(size_t len)
static std::default_random_engine & GetEngine()
一般不使用,传给标准库接口才使用
static float Float(const std::array< float, 2 > &mm)
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 std::array< std::byte, N > Array()
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, DL_SOURCE_LOCATION)
以当前设置输出
constexpr T clamp(const T &x, const T &a, const T &b)
限制数值到 [a, b]