Page tree
Skip to end of metadata
Go to start of metadata



Introduced in

Version:1.00

Description

Description:Random real (floating point) value from 0 (inclusive) - x (non-inclusive).

Syntax

Syntax:random x
Parameters:
Return Value:Number

Examples

Examples:
_rNumber = random 1

Additional Information

See also:
Multiplayer:
Problems:

Notes






  • Be careful using random numbers in multiplayer, each client will come up with a different result. See multiplayer tutorials for more general information about locality.
  • The number returned is unlikely to be a whole number.
    To return a whole number use either round, ceil or floor together with random:
x=round(random 5.499) will return 0,1,2,3,4 or 5.  The .499 was added to create a more equal chance to get 5.  Note that 0 is still less likely to occur than 1-5 in this example, which would need to be countered with: round ((random 6) - 0.499)  
x=floor(random 5) will return 0,1,2,3 or 4.
x=ceil(random 5) will return 0, 1,2,3,4 or 5. (0 is very unlikely, but possible, as ceil 0 is 0)