Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X


Random Sleep time

  • Please log in to reply
4 replies to this topic

#1 gripper



  • Active Members
  • 24 posts

Posted 19 April 2011 - 06:06 PM

I have a script that I want to have a random sleep time while it is running.

I typically have code pieces:

I would like to be able instead of having a fixed time have one of two solutions
1. A random time between a MAX and MIN number; or,
2. Set up a choice of 5 times and have it randomly pick each time it executes.

This script is in a loop which runs unattended and interacts with various website databases that I own.

Either solutions would work for me.

#2 UEZ


    Never say never

  • MVPs
  • 5,218 posts

Posted 19 April 2011 - 06:22 PM

Check out the Random() and MsgBox() function in help file.


The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!

#3 Melba23


    I'm old - what's your excuse?

  • Moderators
  • 22,707 posts

Posted 19 April 2011 - 06:25 PM


- 1. Use Random as the argument to Sleep:
Sleep(Random(1000, 10000, 1))

This will sleep for a random time between 1 and 10 seconds.

- 2. Use an array to store the times and then use Random to choose which element to use:
Global $aTimes[5] = [1, 3, 5, 7, 9] Sleep(1000 * $aTimes[Random(0, 4, 1)])

You get sleeps of 1, 3, 5, 7 or 9 seconds.

All clear? :unsure:

StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items
GUITreeViewEx - Check/clear parent and child checkboxes in a TreeView

#4 gripper



  • Active Members
  • 24 posts

Posted 23 April 2011 - 09:33 PM

I used both options and both worked perfectly - Thank you.

#5 Rogue5099



  • Active Members
  • PipPipPipPipPipPip
  • 430 posts

Posted 24 April 2011 - 02:41 AM

Global $aTimes[5] = [1, 3, 5, 7, 9]

Wow learn something new everyday! Didn't know you could assign Arrays like that. I would have done it the hard way:

Global $aTimes[0] = 1 Global $aTimes[1] = 3 Global $aTimes[2] = 5 Global $aTimes[3] = 7 Global $aTimes[4] = 9

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users