How to use random in BATCH script?

IAdapter picture IAdapter · Apr 25, 2011 · Viewed 205.8k times · Source

How to use random in BATCH script?

Answer

mousio picture mousio · Apr 25, 2011

%RANDOM% gives you a random number between 0 and 32767.

Using an expression like SET /A test=%RANDOM% * 100 / 32768 + 1, you can change the range to anything you like (here the range is [1…100] instead of [0…32767]).