Search code examples
windowsbatch-filerandomcommand-linecolors

Randomizing text color and background color in batch file


I am attempting to make a batch file that will randomize the color code when the script is run. How would i do this?


Solution

  • To change the color, you need the color command. The arguments are:

    color <background><text>
    

    So generating a random color works like this:

    set /a rand1=%random% %% 16
    set /a rand2=%random% %% 16
    set HEX=0123456789ABCDEF
    call set hexcolors=%%HEX:~%rand1%,1%%%%HEX:~%rand2%,1%%
    color %hexcolors%