Cadzow Knowledgebase

Normal view

Scripting: Random Number

The command processor (CMD.EXE) will dynamically resolve the environment variable %RANDOM% to a random integer between 0 and 32767.

To return a number to the variable R between 0 and an upper limit n inclusive, use the modulo syntax (%% in a script, % from the command line):

set /A R=%Random% %% n+1

To return a number between m and n, use:

set /A R=%Random% %% (n-m+1) + m

For example, to return a random number between 10 and 20 inclusive:

set /A R=%Random% %% 11 + 10

Copyright © 1996-2021 Cadzow TECH Pty. Ltd. All rights reserved.
Information and prices contained in this website may change without notice. Terms of use.

Question/comment about this page? Please email