Rand
Math Function
The Rand function returns a random value n between 0 and X (0 <= n < X) where X is the result of the expression.
To generate random numbers between the expression and a number other than zero, use the expression as the range between the maximum and minimum values. Then add the minimum to the random number. For example, the statement Attr1 = 2+Rand(3) generates a random number from two up to, but not including, five. An alternate method is to use a uniform distribution. Note that the Rand function works very similar to a uniform distribution.
Syntax
Rand(<expression>)
Rand(10) min
Order Rand(10) EntA TO Loc1
If Rand(100) > 45 Then
{
Route 1
}
Parameters
(<expression>)
The upper limit of the random value to return. This value is never returned.
Example
In the following example, a random number between 0 and 9 is displayed every time an Entity enters the Truck Location.
Display Rand(10)
Remarks
This function returns a real number, although the real value may be converted to an integer. To have the Rand function generate random integer values between zero and some upper bound, use the formula...
Integer_Value = Rand(X+1)
...where X is the greatest integer to be returned by the function. For example, to generate a random integer value between zero and six, use the formula...
Integer_Value = Rand(7)
The Rand(7) part of this formula actually generates a real value between 0 and 6.999, but is truncated to a whole number between 0 and 6 when assigned to an integer value. Therefore, when generating integer values, ensure the Rand function result is assigned to an integer value, or is used in an expression where it is truncated to an integer.