Sleep: Difference between revisions

Jump to navigation Jump to search
18 bytes added ,  6 February 2023
Line 4: Line 4:
=== Approach 1: %RANDOM% + ping local ===
=== Approach 1: %RANDOM% + ping local ===
Purpose
Purpose
* Sleep random seconds between 5 ~ 65 seconds
* Sleep random seconds between 5 ~ 60 seconds


BAT file:
BAT file:
Line 11: Line 11:
ECHO %date% %time%
ECHO %date% %time%


REM sleep 5 ~ 65 seconds
REM sleep 5 ~ 60 seconds
SET /a timeout=%RANDOM% * 60 / 32768 + 5
SET /a timeout=%RANDOM% * 55 / 32767 + 5
ping 127.0.0.1 -n %timeout% > nul
ping 127.0.0.1 -n %timeout% > nul


Line 21: Line 21:
Instruction<ref>[https://stackoverflow.com/questions/8258087/bat-random-timeout batch file - .bat random timeout - Stack Overflow]</ref>
Instruction<ref>[https://stackoverflow.com/questions/8258087/bat-random-timeout batch file - .bat random timeout - Stack Overflow]</ref>
* {{kbd | key=<nowiki>%RANDOM%</nowiki>}} returns an integer between 0 and 32767<ref>[https://ss64.com/nt/syntax-random.html Random Numbers - Windows CMD - SS64.com]</ref>.
* {{kbd | key=<nowiki>%RANDOM%</nowiki>}} returns an integer between 0 and 32767<ref>[https://ss64.com/nt/syntax-random.html Random Numbers - Windows CMD - SS64.com]</ref>.
* 60 is the range of values you want: 0 to 60.
* 55 is the range of values you want: 5 to 60.
* 32768 is the range of values returned by {{kbd | key=<nowiki>%RANDOM%</nowiki>}} (0 to 32767).
* 32767 is the range of values returned by {{kbd | key=<nowiki>%RANDOM%</nowiki>}} (0 to 32767).
* 5 is the minimum value you want. The original range of values you want '0 to 60' became '5 ~ 65'.
* 5 is the minimum value you want. The original range of values is '0 to 60'. After plus 5 the range became '5 ~ 65'.
* ping local address: {{kbd | key=<nowiki>/n <Count></nowiki>}} "Specifies the number of echo Request messages sent. The default is 4."<ref>[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ping time]</ref><ref>[https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script windows xp - How to wait in a batch script? - Stack Overflow]</ref>
* ping local address: {{kbd | key=<nowiki>/n <Count></nowiki>}} "Specifies the number of echo Request messages sent. The default is 4."<ref>[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ping time]</ref><ref>[https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script windows xp - How to wait in a batch script? - Stack Overflow]</ref>


Anonymous user

Navigation menu