Sign in to follow this  
Followers 0
Chobyhy

Help With creating Random Sleeptime

5 posts in this topic

I need a way to create random sleep time. Random between two chosen number

like the random function. I've tried sleep(random(1,10)) or something like that but it didnt work

Share this post


Link to post
Share on other sites



Remember that Sleep uses Milliseconds... The default Sleep if you use any number I believe is 10, so whether you use 1 to 10, it's the same as using 10....


[center]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.[/center]

Share this post


Link to post
Share on other sites

i used those number as example. Numbers i used was 1000 to 10000

Share this post


Link to post
Share on other sites

Test your own theory that it's not working...

ConsoleWrite(@LF)
While 1
    $iTimer = TimerInit()
    $iRand = Random(1000, 10000, 1)
    ToolTip('Random Time = ' & $iRand, 0, 0)
    Sleep($iRand)
    ConsoleWrite('The Pause was: ' & TimerDiff($iTimer) / 1000 & @LF)
WEnd
Run it in SciTe... and it will show you the approximate output.

[center]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.[/center]

Share this post


Link to post
Share on other sites

I need a way to create random sleep time. Random between two chosen number

like the random function. I've tried sleep(random(1,10)) or something like that but it didnt work

....
SleepRan(1000)   ;sleep for 1 second, with a 20% variance.
....

....
Func SleepRan($n)
$v = .2 ;variance. currently set to 20%
Sleep(Random($n*(1-$v),$n*(1+$v),1))
EndFunc

Try that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0