Sign in to follow this  
Followers 0

Random Sleep time

5 posts in this topic

Posted · Report post

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

I typically have code pieces:

"sleep(1500)"

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.

Share this post


Link to post
Share on other sites



Posted · Report post

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

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted · Report post

gripper,

- 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:

M23

Share this post


Link to post
Share on other sites

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

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

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

  • Recently Browsing   0 members

    No registered users viewing this page.