Sleep: Difference between revisions
Jump to navigation
Jump to search
m (→MS-DOS) |
m (→MS-DOS) |
||
| Line 17: | Line 17: | ||
REM print current date & time | REM print current date & time | ||
ECHO %date% %time% | |||
</pre> | |||
Alternative command: {{exclaim}} The following command {{kbd | key=<nowiki>ECHO %date% %time%</nowiki>}} will not be executed after {{kbd | key=<nowiki>TIMEOUT %timeout%</nowiki>}} was executed. | |||
<pre> | |||
SET /a timeout=%RANDOM% * 60 / 32768 + 5 | |||
TIMEOUT %timeout% | |||
ECHO %date% %time% | ECHO %date% %time% | ||
</pre> | </pre> | ||
Revision as of 14:00, 2 November 2018
Sleep random seconds in programming
MS-DOS
batch file - .bat random timeout - Stack Overflow
- %RANDOM% returns an integer between 0 and 32767.
- 60 is the range of values you want: 0 to 60.
- 32768 is the range of values returned by %RANDOM% (0 to 32767).
- 5 is the minimum value you want. The original range of values you want '0 to 60' became '5 ~ 65'.
- ping local address[1]
REM print current date & time ECHO %date% %time% REM sleep 5 ~ 65 seconds SET /a timeout=%RANDOM% * 60 / 32768 + 5 ping 127.0.0.1 -n %timeout% > nul REM print current date & time ECHO %date% %time%
Alternative command:
The following command ECHO %date% %time% will not be executed after TIMEOUT %timeout% was executed.
SET /a timeout=%RANDOM% * 60 / 32768 + 5 TIMEOUT %timeout% ECHO %date% %time%