Random module
This module provides a simple random number generator based on a Linear Congruential Generator (LCG), along with functions to generate random numbers of different types and ranges. It also provides functions to set and get the random seed.
To use this module, include the following line in your project file:
require engine.math.random_core // or require engine.core
Some useful random functions are also available in the Daslang standard module random.
Constants
- MAX_INT_RANDOM = 2147483647
Maximum random int value, equals (2^31 - 1)
Functions
- get_random_seed(): uint4
Returns the current random seed.
- random_bool(): bool
Returns a random boolean value.
- random_element(array_of_elements: array<auto(TT)>|array<auto(TT)>#|auto(TT)[]|auto(TT)[]#): TT
Returns a random element from the given array.
- Arguments:
array_of_elements : option<array<auto(TT)>| array<auto(TT)>#| auto(TT)[-1]| auto(TT)[-1]#>
- random_float(): float
Returns a random float value in the range [0..1).
- random_float4(): float4
Returns a random float4 value in the range [0..1).
- random_int(): int
Returns a random int value in the range [0..MAX_INT_RANDOM].
- random_int4(): int4
Returns a random int4 value in the range [0..MAX_INT_RANDOM].
- random_point_inside_unit_circle(): float2
Returns a random point inside the unit circle.
- random_point_inside_unit_sphere(): float3
Returns a random point inside the unit sphere.
- random_point_on_segment(start_point: float|float2|float3|float4; end_point: float|float2|float3|float4): auto
Returns a random point on the segment defined by the two points start_point and end_point.
- Arguments:
start_point : option<float| float2| float3| float4>
end_point : option<float| float2| float3| float4>
- random_range(from: uint; to: uint): uint
Returns a random uint value in the range [from..to). If to is less than from then the arguments will be swapped. If to is equal to from then this value will be returned.
- Arguments:
from : uint
to : uint
- random_range(from: int; to: int): int
Returns a random int value in the range [from..to). If to is less than from then the arguments will be swapped. If to is equal to from then this value will be returned.
- Arguments:
from : int
to : int
- random_range(from: float; to: float): float
Returns a random float value between [from..to).
- Arguments:
from : float
to : float
- random_range(from: float2; to: float2): float2
Returns a random float2 value between [from..to).
- Arguments:
from : float2
to : float2
- random_range(from: float4; to: float4): float4
Returns a random float4 value between [from..to).
- Arguments:
from : float4
to : float4
- random_range(from: float3; to: float3): float3
Returns a random float3 value between [from..to).
- Arguments:
from : float3
to : float3
- random_uint(): uint
Returns a random uint value in the range [0..0xFFFFFFFF].
- random_uint4(): uint4
Returns a random uint4 value in the range [0..0xFFFFFFFF].
- random_unit_vector(): float3
Returns a random unit vector in 3D.
- random_unit_vector_2d(): float2
Returns a random unit vector in 2D.
- randomize_seed()
Randomizes the random seed using the current time.
- set_random_seed(int_seed: int)
Sets the random seed.
- Arguments:
int_seed : int
- set_random_seed(new_seed: uint4)
Sets the random seed.
- Arguments:
new_seed : uint4