.. _stdlib_random_core: ============= 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 +++++++++ .. _global-random_core-MAX_INT_RANDOM: .. das:attribute:: MAX_INT_RANDOM = 2147483647 Maximum random int value, equals (2^31 - 1) +++++++++ Functions +++++++++ * :ref:`randomize_seed () ` * :ref:`get_random_seed () : uint4 ` * :ref:`set_random_seed (new_seed: uint4) ` * :ref:`set_random_seed (int_seed: int) ` * :ref:`random_float () : float ` * :ref:`random_float4 () : float4 ` * :ref:`random_int () : int ` * :ref:`random_int4 () : int4 ` * :ref:`random_uint () : uint ` * :ref:`random_uint4 () : uint4 ` * :ref:`random_bool () : bool ` * :ref:`random_range (from: int; to: int) : int ` * :ref:`random_range (from: uint; to: uint) : uint ` * :ref:`random_range (from: float; to: float) : float ` * :ref:`random_range (from: float2; to: float2) : float2 ` * :ref:`random_range (from: float3; to: float3) : float3 ` * :ref:`random_range (from: float4; to: float4) : float4 ` * :ref:`random_unit_vector_2d () : float2 ` * :ref:`random_unit_vector () : float3 ` * :ref:`random_point_inside_unit_sphere () : float3 ` * :ref:`random_point_inside_unit_circle () : float2 ` * :ref:`random_point_on_segment (start_point: float|float2|float3|float4; end_point: float|float2|float3|float4) : auto ` * :ref:`random_element (array_of_elements: array\|array\#|auto(TT)[]|auto(TT)[]#) : TT ` .. _function-random_core_randomize_seed: .. das:function:: randomize_seed() Randomizes the random seed using the current time. .. _function-random_core_get_random_seed: .. das:function:: get_random_seed() : uint4 Returns the current random seed. .. _function-random_core_set_random_seed_uint4: .. das:function:: set_random_seed(new_seed: uint4) Sets the random seed. :Arguments: * **new_seed** : uint4 .. _function-random_core_set_random_seed_int: .. das:function:: set_random_seed(int_seed: int) Sets the random seed. :Arguments: * **int_seed** : int .. _function-random_core_random_float: .. das:function:: random_float() : float Returns a random float value in the range [0..1). .. _function-random_core_random_float4: .. das:function:: random_float4() : float4 Returns a random float4 value in the range [0..1). .. _function-random_core_random_int: .. das:function:: random_int() : int Returns a random int value in the range [0..MAX_INT_RANDOM]. .. _function-random_core_random_int4: .. das:function:: random_int4() : int4 Returns a random int4 value in the range [0..MAX_INT_RANDOM]. .. _function-random_core_random_uint: .. das:function:: random_uint() : uint Returns a random uint value in the range [0..0xFFFFFFFF]. .. _function-random_core_random_uint4: .. das:function:: random_uint4() : uint4 Returns a random uint4 value in the range [0..0xFFFFFFFF]. .. _function-random_core_random_bool: .. das:function:: random_bool() : bool Returns a random boolean value. .. _function-random_core_random_range_int_int: .. das:function:: 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 .. _function-random_core_random_range_uint_uint: .. das:function:: 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 .. _function-random_core_random_range_float_float: .. das:function:: random_range(from: float; to: float) : float Returns a random float value between [from..to). :Arguments: * **from** : float * **to** : float .. _function-random_core_random_range_float2_float2: .. das:function:: random_range(from: float2; to: float2) : float2 Returns a random float2 value between [from..to). :Arguments: * **from** : float2 * **to** : float2 .. _function-random_core_random_range_float3_float3: .. das:function:: random_range(from: float3; to: float3) : float3 Returns a random float3 value between [from..to). :Arguments: * **from** : float3 * **to** : float3 .. _function-random_core_random_range_float4_float4: .. das:function:: random_range(from: float4; to: float4) : float4 Returns a random float4 value between [from..to). :Arguments: * **from** : float4 * **to** : float4 .. _function-random_core_random_unit_vector_2d: .. das:function:: random_unit_vector_2d() : float2 Returns a random unit vector in 2D. .. _function-random_core_random_unit_vector: .. das:function:: random_unit_vector() : float3 Returns a random unit vector in 3D. .. _function-random_core_random_point_inside_unit_sphere: .. das:function:: random_point_inside_unit_sphere() : float3 Returns a random point inside the unit sphere. .. _function-random_core_random_point_inside_unit_circle: .. das:function:: random_point_inside_unit_circle() : float2 Returns a random point inside the unit circle. .. _function-random_core_random_point_on_segment_floatfloat2float3float4_floatfloat2float3float4: .. das:function:: 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 * **end_point** : option .. _function-random_core_random_element_array_ls_autoTT_gr_array_ls_autoTT_gr__hh_autoTTautoTT_hh_: .. das:function:: random_element(array_of_elements: array|array#|auto(TT)[]|auto(TT)[]#) : TT Returns a random element from the given array. :Arguments: * **array_of_elements** : option|array#|auto(TT)[-1]|auto(TT)[-1]#>