batch-file Random In Batch Files Random Alphabets


Unfortunately, batch does not have a built-in method to generate alphabets, but using %random% and for loop, we can 'generate' alphabets.

This is a simple idea of how this works.

set /a result=(%random%*26/32768)+1
for /f "tokens=%result%" %%I in ("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z") do (
    echo %%I
  • The first set /a statement generate a random number N between 1 to 26
  • The for /f statement picks the Nth item from a list of A to Z.
    • Return the result

One can put a total 31 items in 1 for loop, and practically unlimited items using [this method].(Batch - for loop parameter order