title: Windows scheduled task / sql server random time
body: <p>I have the following situation I am working on with the majority of the issue solved. I currently the following folders and files existing on a machine. </p>
  
  <pre><code>C:\foo\foo.sql
  C:\foo\foo.bat
  </code></pre>
  
  <p>"foo.sql" - is a script file that has a very simple line in it:</p>
  
  <pre><code>EXEC uspUpdateCounts
  </code></pre>
  
  <p>"foo.bat" - invokes SQLCMD to call execute foo.sql  and log any output from the stored procedure called to a text file with the current time and date stamp (this will only run once per day):</p>
  
  <pre><code>"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S SvrNme -E -d dbName -i C:\foo\foo.sql -o "C:\foo\fooOutput_%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt"
  </code></pre>
  
  <p>I am currently using a windows scheduled task to kick off foo.bat I would like to know if there is a way I can script the time to happen randomly every day to run between 6AM and 1PM PST. I have messed around with some time components in scripts I have found here and there, but I cannot get it to randomize the minute. I can get the hour but its not very reliable but at this point I am completely lost. If someone can help me with this solution and also explain the solution, that would be great. I am not just looking for the answer but to learn as well. </p>