By using this site you agree to the use of cookies.

Learn more

Share via:

AutoIt Random Function

The random function is used to generate random numbers.

Created: 2017-03-24 17:06

The AutoIt Random function is used to generate a random number in a given range.

Can be used in conjunction with sleep to pause script execution for a random amount of time.

Parameters

Min [optional]The starting point, default is 0.
Max [optional]The end point, default is 0.
Flag [optional]The value of 1 returns an integer, while the default is a floating point number.

AutoIt Random Number Examples

The below example shows how to use random together with the sleep function.

$st = random(1000, 5000, 1) ; Sleep Time

sleep($st) ; sleeps for a random amount of milliseconds between 1000 and 5000

MsgBox(0, "AutoIt Random Number Example:", $st)

The next example shows the difference if you are using the integer flag.

MsgBox(0, "AutoIt Random Number Example:", random(1000, 5000)) ; Outputs something like: 2524.55020649660

MsgBox(0, "AutoIt Random Number Example:", random(1000, 5000, 1)) ; Outputs something like: 4567