📎 AI Summary:
The original poster seeks to add a random delay between 5 and 30 minutes in a batch script before executing a second command. Respondent Neemobeer suggests using PowerShell for easier range control, providing example code to generate a random wait time within that range and pause execution accordingly. The overall sentiment indicates that switching to PowerShell simplifies implementing precise random delays compared to batch scripts.

onlinegill

New Member
Joined
Mar 28, 2020
Messages
1
Thread Author #1
Hello,
I have a batch script and i would like to put random delay / wait time in minutes to run second command.
example :
run first command here
random wait between 5 to 30 minutes
run second command here


Thank You
 

Solution
There is a sudo random number generated in a command line shell you can call timeout /t %random% however there is no way to control the value range which is a 32 bit int. You'd have to do some math to control the value to get a range of 5-30 minutes.

If you re-wrote the batch file into a Powershell script it's much easier to control that timing.

<command one>
$wait_time = Get-Random -Minimum 300 -Maximum 1800
Start-Sleep -Seconds $wait_time
<command two>

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
There is a sudo random number generated in a command line shell you can call timeout /t %random% however there is no way to control the value range which is a 32 bit int. You'd have to do some math to control the value to get a range of 5-30 minutes.

If you re-wrote the batch file into a Powershell script it's much easier to control that timing.

<command one>
$wait_time = Get-Random -Minimum 300 -Maximum 1800
Start-Sleep -Seconds $wait_time
<command two>
 

Solution