2.5. Random generator library
The RANDOM module implements pseudo-random number generation using a linear
congruential generator with vectorized state (int4). It provides integer,
float, and vector random values, as well as geometric sampling (unit vectors,
points in spheres and disks).
All functions and symbols are in “random” module, use require to get access to it.
require daslib/random
Example:
require daslib/random
[export]
def main() {
var seed = random_seed(12345)
print("int: {random_int(seed)}\n")
print("float: {random_float(seed)}\n")
print("float: {random_float(seed)}\n")
}
// output:
// int: 7584
// float: 0.5848567
// float: 0.78722495
2.5.1. Constants
- LCG_RAND_MAX = 32767
maximum possible output of random number generator
- LCG_RAND_MAX_BIG = 1073741823
maximum possible output of random_big_int
2.5.2. Seed and basic generators
- random_big_int(seed: int4&): auto
random integer 0..32768*32768-1 (LCG_RAND_MAX_BIG)
- Arguments:
seed : int4&
- random_float(seed: int4&): auto
random float 0..1
- Arguments:
seed : int4&
- random_float4(seed: int4&): auto
random float4, each component is 0..1
- Arguments:
seed : int4&
- random_int(seed: int4&): auto
random integer 0..32767 (LCG_RAND_MAX)
- Arguments:
seed : int4&
- random_int4(seed: int4&): auto
random int4, each component is 0..32767 (LCG_RAND_MAX)
- Arguments:
seed : int4&
- random_seed(seed: int): auto
constructs seed vector out of single integer seed
- Arguments:
seed : int
- random_seed2D(seed: int4&; co: int2; cf: int = 0): auto
constructs seed vector out of 2d screen coordinates and frame counter cf
- Arguments:
seed : int4&
co : int2
cf : int
- random_uint(seed: int4&): auto
random unsigned integer using 3-component LCG, covering full uint range
- Arguments:
seed : int4&
2.5.3. Random iterators
- each_random_uint(rnd_seed: int = 13): iterator<uint>
infinite generator of random uints initialized with rnd_seed
- Arguments:
rnd_seed : int
2.5.4. Specific distributions
- random_in_unit_disk(seed: int4&): auto
Returns a random float3 point uniformly distributed inside the unit disk (length <= 1, z=0).
- Arguments:
seed : int4&
- random_in_unit_sphere(seed: int4&): auto
Returns a random float3 point uniformly distributed inside the unit sphere (length <= 1).
- Arguments:
seed : int4&
- random_unit_vector(seed: int4&): auto
random float3 unit vector (length=1.)
- Arguments:
seed : int4&