Jump to content

Random


Guest Demvaril
 Share

Recommended Posts

Guest Demvaril

Hi , I need a macro that will hit the same key between 2 set times.

For example hit the "x" key at a random time between 45 and 50 secs. At the moment I have a macro that hits the same key at a preset time, like 45000 for 45 seconds. I am not at work at the moment so cannot show the macro i have, but it was a pretty simple one.

Thanks for any help.

been to work and this is the script i am using :ph34r:

$i = 0

Do

Sleep(52000)

Send("s")

Until $i = 1

Would adding

Sleep(Random(2000, 5000))

at the end of the script work? or should i replace "Sleep(52000)" with "Sleep(Random(52000, 55000))

Any help appreciated.

Edited by Demvaril
Link to comment
Share on other sites

Dim $mint, $maxt
$mint = 45  ;Set the min time in seconds. 
$maxt = 50  ;Set the max time in seconds.

If $maxt < $mint Then Exit

While 1
    Sleep($mint * 1000)
    Sleep(Int(Random($maxt - $mint + 1)) * 1000) ;*
    Send('s')
Wend

;* The point to this line is calculate the max time the script should sleep.
;adding 1 to it (since Random() do not include max in its results) truncate
;decimal part of the Random result and sleep that number of seconds.

Edited by ezzetabi
Link to comment
Share on other sites

  • Developers

Dim $mint, $maxt
$mint = 45  ;Set the min time in seconds. 
$maxt = 50  ;Set the max time in seconds.

If $maxt < $mint Then Exit

While 1
    Sleep($mint * 1000)
    Sleep(Int(Random($maxt - $mint + 1)) * 1000);*
    Send('s')
Wend

;* The point to this line is calculate the max time the script should sleep.
;adding 1 to it (since Random() do not include max in its results) truncate
;decimal part of the Random result and sleep that number of seconds.

<{POST_SNAPBACK}>

Think it can also be done with one sleep command:

Sleep(Random($mint,$maxt) * 1000)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Of course, but it seemed more clear for a noob to me.

Btw your code never arrive waiting to $maxt seconds  :(

It should be:

Sleep(Int(Random($mint,$maxt + 1)) * 1000)

:lol:

<{POST_SNAPBACK}>

You are rigth... I am of 1/1000s of a second :ph34r:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...