JSI Tip 8559. How can I generate a better random number using only standard commands?

I discussed random numbers in tip 3239 » %RANDOM% generates a random integer in the range of 0 - 32767, and tip 7375 » Random freeware sets %ERRORLEVEL% to a random number between the lowerbound and upperbound parameters.

I have scripted RNmbr.bat to generate a random number that is seeded with the current time.

The syntax for using RNmbr.bat is:


Where VAR is a call directed numeric environment variable that will contain the random number.

RNmbr.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax RNmbr VAR&goto :EOF
call set %1=%time::=%
call set %1=%%%1: 0=%%%
call set %1=%%%1:.=-%%%
call set %1=%%%1:-0=-%%%
call set /a %1=%RANDOM% * %%%1%%%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.