Built-in functions: math_rand()
The function math_rand() calculates a random number lying within a predetermined range.
Declaration
Form 1:
float math_rand( float aValue1, float aValue2 )
Form 2:
int32 math_rand( int32 aValue1, int32 aValue2 )
Parameters
aValue1
The lower end of the range to generate the random number.
aValue2
The upper end of the range to generate the random number.
Discussion
The function math_rand() returns a random value lying within the range aValue1 ... aValue2 including the both end values. In its first form the function is intended to calculate with floating-point values. The second form is optimized to be used within a 32-bit integer expression. For example:
var float random1 = math_rand( 0.0, 1.0 ); // random1 = 0.0 .. 1.0 var int32 random2 = math_rand( 0, 255 ); // random2 = 0 .. 255
The quality of the returned values depends on the random generator implementation available in the underlying target system. Usually, the typical target system will provide pseudo random numbers only. Please note the existing limitation in the usage of the int32 version of math_rand(). This function can return incorrect values in case of the range aValue1 ... aValue2 is exceeding the value 32767.