-
Notifications
You must be signed in to change notification settings - Fork 72
/
RandSleep.ahk
35 lines (28 loc) · 1.05 KB
/
RandSleep.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
SleepRand(min,max){
; Time Array used by for loop
; hr, min, sec, ms
msTimeA := [3600000,60000,1000,1]
; Split fields up
StringSplit, minTime, min, % ":"
StringSplit, maxTime, max, % ":"
; Reset random min/max values
finalMin := 0
finalMax := 0
; Calculate seconds for min and max time
for index, value in msTimeA
{
; finalMin and finalMax are just "total milliseconds"
; Each field is multiplied by the correlating amount of ms in the msTimeA array
; Meaning first loop is hours. So it takes the number of hours times 3600000ms
; which is how many ms are in an hour and adds it to the total.
; It continues until all hrs, min, sec, and ms are all done.
finalMin += (minTime%A_Index% * value)
finalMax += (maxTime%A_Index% * value)
}
; Randomize between min and max
Random, rSleep, % finalMin, % finalMax
; MsgBox % "Sleep timer set for " (rSleep/1000) " seconds."
; Sleep for randomized time
Sleep, % rSleep
return
}