7. 随机生成器库
随机库实现了基本的随机例程。
所有函数和符号都在 random 模块中,使用 require 可以访问该模块。
require random
7.1. 常量
- LCG_RAND_MAX = 32767
随机数生成器的最大可能输出
- LCG_RAND_MAX_BIG = 1073741823
random_big_int 可能输出的最大值
7.2. 种子生成器和基本生成器
- random_seed(seed: int const)
random_seed returns auto
argument |
argument type |
---|---|
seed |
int const |
用单个整数种子构建种子向量
- random_seed2D(seed: int4&; co: int2 const; cf: int const)
random_seed2D returns auto
argument |
argument type |
---|---|
seed |
int4& |
co |
int2 const |
cf |
int const |
用 2d 屏幕坐标和帧计数器 cf 构造种子向量
- random_int(seed: int4&)
random_int returns auto
argument |
argument type |
---|---|
seed |
int4& |
random integer 0..32767 (LCG_RAND_MAX)
- random_big_int(seed: int4&)
random_big_int returns auto
argument |
argument type |
---|---|
seed |
int4& |
random integer 0..32768*32768-1 (LCG_RAND_MAX_BIG)
- random_uint(seed: int4&)
random_uint returns auto
argument |
argument type |
---|---|
seed |
int4& |
random integer 0..32768*32768-1 (LCG_RAND_MAX_BIG)
- random_int4(seed: int4&)
random_int4 returns auto
argument |
argument type |
---|---|
seed |
int4& |
random int4, each component is 0..32767 (LCG_RAND_MAX)
- random_float(seed: int4&)
random_float returns auto
argument |
argument type |
---|---|
seed |
int4& |
random float 0..1
- random_float4(seed: int4&)
random_float4 returns auto
argument |
argument type |
---|---|
seed |
int4& |
random float4, each component is 0..1
7.3. Random iterators
- each_random_uint(rnd_seed: int const)
each_random_uint returns iterator<uint>
argument |
argument type |
---|---|
rnd_seed |
int const |
endless iterator of random uints
7.4. 具体分布
- random_unit_vector(seed: int4&)
random_unit_vector returns auto
argument |
argument type |
---|---|
seed |
int4& |
random float3 unit vector (length=1.)
- random_in_unit_sphere(seed: int4&)
random_in_unit_sphere returns auto
argument |
argument type |
---|---|
seed |
int4& |
random float3 unit vector (length=1) which happens to be inside a sphere R=1
- random_in_unit_disk(seed: int4&)
random_in_unit_disk returns auto
argument |
argument type |
---|---|
seed |
int4& |
random float3 unit vector (length=1) which happens to be inside a disk R=1, Z=0