dl
dl::Random类 参考

随机数 更多...

#include <dl_random.h>

静态 Public 成员函数

static void SetSeed (uint32_t seed)
 设置随机数种子
 
template<typename T>
static T Float (T min, T max)
 返回[min,max)区间的 浮点数随机值
 
template<typename T>
static T Integer (T min, T max)
 返回[min,max]区间的 随机整数
 
template<typename T>
static T Normal (T u=0, T o=1)
 返回期望为u,标准差为o的正态分布随机值
 
static FloatType FloatNormal (FloatType u=0_f, FloatType o=1_f)
 
static FloatType FloatNormalX (FloatType scale=1/3_f, FloatType min=-1, FloatType max=1)
 返回标准正态分布的缩放值,且限制到指定值
 
static bool Bool ()
 
static int Int (int min, int max)
 返回[min,max]区间的 int型整数
 
static unsigned Uint (unsigned min, unsigned max)
 返回[min,max]区间的 unsigned型整数
 
static size_t SizeT (size_t min, size_t max)
 返回[min,max]区间的 size_t型整数
 
template<size_t N>
static std::array< std::byte, NArray ()
 
static Buffer BufferX (size_t len)
 
template<typename C>
static auto & Select (C &container)
 从容器随机选择一个
 
template<typename C>
static auto SelectErase (C &container)
 从容器随机选择一个,并且从容器移除
 
static Point ExPoint (const Point &p0, const Point &p1)
 
static PointU ExPointU (const PointU &p0, const PointU &p1)
 
static Position ExDirection ()
 
static bool Percent (int v)
 返回百分比命中
 
static float Angle (float min=0, float max=3.1415926f *2.0f)
 返回角度(弧度制)
 
static float Float (const std::array< float, 2 > &mm)
 
static float Float (const dl::Array< float, 2 > &mm)
 
static std::default_random_engine & GetEngine ()
 一般不使用,传给标准库接口才使用
 

详细描述

随机数

在文件 dl_random.h22 行定义.

成员函数说明

◆ Angle()

static float dl::Random::Angle ( float min = 0,
float max = 3.1415926f * 2.0f )
inlinestatic

返回角度(弧度制)

在文件 dl_random.h232 行定义.

◆ Array()

template<size_t N>
static std::array< std::byte, N > dl::Random::Array ( )
inlinestatic

在文件 dl_random.h143 行定义.

◆ Bool()

static bool dl::Random::Bool ( )
inlinestatic

在文件 dl_random.h116 行定义.

◆ BufferX()

static Buffer dl::Random::BufferX ( size_t len)
inlinestatic

在文件 dl_random.h160 行定义.

◆ ExDirection()

static Position dl::Random::ExDirection ( )
inlinestatic

在文件 dl_random.h217 行定义.

◆ ExPoint()

static Point dl::Random::ExPoint ( const Point & p0,
const Point & p1 )
inlinestatic

在文件 dl_random.h209 行定义.

◆ ExPointU()

static PointU dl::Random::ExPointU ( const PointU & p0,
const PointU & p1 )
inlinestatic

在文件 dl_random.h213 行定义.

◆ Float() [1/3]

static float dl::Random::Float ( const dl::Array< float, 2 > & mm)
inlinestatic

在文件 dl_random.h240 行定义.

◆ Float() [2/3]

static float dl::Random::Float ( const std::array< float, 2 > & mm)
inlinestatic

在文件 dl_random.h236 行定义.

◆ Float() [3/3]

template<typename T>
static T dl::Random::Float ( T min,
T max )
inlinestatic

返回[min,max)区间的 浮点数随机值

注解
如果min等于max,则返回min。如果min大于max则交换位置后比较,但会发出一条警告。

在文件 dl_random.h45 行定义.

◆ FloatNormal()

static FloatType dl::Random::FloatNormal ( FloatType u = 0_f,
FloatType o = 1_f )
inlinestatic

在文件 dl_random.h97 行定义.

◆ FloatNormalX()

static FloatType dl::Random::FloatNormalX ( FloatType scale = 1/3_f,
FloatType min = -1,
FloatType max = 1 )
inlinestatic

返回标准正态分布的缩放值,且限制到指定值

在文件 dl_random.h104 行定义.

◆ GetEngine()

static std::default_random_engine & dl::Random::GetEngine ( )
inlinestatic

一般不使用,传给标准库接口才使用

在文件 dl_random.h245 行定义.

◆ Int()

static int dl::Random::Int ( int min,
int max )
inlinestatic

返回[min,max]区间的 int型整数

在文件 dl_random.h124 行定义.

◆ Integer()

template<typename T>
static T dl::Random::Integer ( T min,
T max )
inlinestatic

返回[min,max]区间的 随机整数

注解
如果min等于max,则返回min。如果min大于max则交换位置后比较,但会发出一条警告。

在文件 dl_random.h66 行定义.

◆ Normal()

template<typename T>
static T dl::Random::Normal ( T u = 0,
T o = 1 )
inlinestatic

返回期望为u,标准差为o的正态分布随机值

注解
标准正态分布 1)34% 2)13.5% 3)2.5%

在文件 dl_random.h87 行定义.

◆ Percent()

static bool dl::Random::Percent ( int v)
inlinestatic

返回百分比命中

在文件 dl_random.h225 行定义.

◆ Select()

template<typename C>
static auto & dl::Random::Select ( C & container)
inlinestatic

从容器随机选择一个

参数
[in]container容器(不能为空)
返回值
返回引用

在文件 dl_random.h183 行定义.

◆ SelectErase()

template<typename C>
static auto dl::Random::SelectErase ( C & container)
inlinestatic

从容器随机选择一个,并且从容器移除

参数
[in]container容器(不能为空)
返回值
返回引用

在文件 dl_random.h198 行定义.

◆ SetSeed()

static void dl::Random::SetSeed ( uint32_t seed)
inlinestatic

设置随机数种子

注解
0会随机生成一个种子

在文件 dl_random.h30 行定义.

◆ SizeT()

static size_t dl::Random::SizeT ( size_t min,
size_t max )
inlinestatic

返回[min,max]区间的 size_t型整数

在文件 dl_random.h138 行定义.

◆ Uint()

static unsigned dl::Random::Uint ( unsigned min,
unsigned max )
inlinestatic

返回[min,max]区间的 unsigned型整数

在文件 dl_random.h131 行定义.


该类的文档由以下文件生成: