How do I make sleep random?

Recommended Posts

I can't seem to find out how to randomize sleep between 4 mintues, and 4 1/2 mintues. Any help ?

Share on other sites

• Moderators

I can't seem to find out how to randomize sleep between 4 mintues, and 4 1/2 mintues. Any help ?

`Sleep(Random(240000, 270000, 1))`

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Thanks

Share on other sites

• Moderators

Thanks

Welcome, some simple math would have fixed it for you as well.

```_SleepRandom(4, 4.5)

Func _SleepRandom(\$nMin1, \$nMin2)
Return Sleep(Random((Number(\$nMin1) * 60) * 1000, (Number(\$nMin2) * 60) * 1000, 1))
EndFunc```

Edit:

Oops, I used \$nMin1 for both.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share on other sites

couldn't you also assign a random variable and use that in the sleep command?

like sleep(\$var1) and then have the variable be a random number? Just wondering, might be more useful to make a variable if the statement is being used more than once in the program.

Share on other sites

• Moderators

couldn't you also assign a random variable and use that in the sleep command?

like sleep(\$var1) and then have the variable be a random number? Just wondering, might be more useful to make a variable if the statement is being used more than once in the program.

Your suggestion is no different than what I presented.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share on other sites

Smoke_N's is just more refined then going

```_SleepRandom(4, 4.5)

Func _SleepRandom(\$nMin1, \$nMin2)
\$var1 = Random((Number(\$nMin1) * 60) * 1000, (Number(\$nMin2) * 60) * 1000, 1)
Return Sleep(\$var1)
EndFunc```

Create an account

Register a new account