Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
October 26, 2003
Marty List brings us Random.zip to return %ERRORLEVEL% as a random number between a lowerbound and upperbound parameter.
When you type random /?, you receive:
Returns an exit code (Errorlevel) of a random number based onlowerbound and upperbound numbers which must be passed as arguments.Syntax: random LowerBound UpperBoundExample: random 1 10Non-numeric arguments will be evaluated as 0.An argument of /? or -? displays this syntax and always returns 0.
To set an environment variable to a random number between 1 and 997:
for /f "Tokens=1" %%r in ('random 1 997') do if /i "%%r" NEQ "The" set /a rnum=%%r
You May Also Like