phpInDev

random_float

float random_float ( float number1, [ float number2 ] )

This script returns a random inclusive floating number (i.e. a number with decimals) between the given floating numbers. If number2 is not specified, then a random number between number1 and 0 is returned.

NOTE: There is much debate over the GM's random functionality (whether it's inclusive/exclusive). It's best to assume that the function is inclusive, so that the bottom and top values are possible from the function (even if highly improbable).

Example 1. Using random_float

{ show_message("A random number is " + string(random_float(2.5, 3.5))); }

That could for example show:

A random number is 2.91

Code for random_float.gml

{
    return min(argument0, argument1) + random(abs(argument0 - argument1));
}