random variables
Posted: 19 Jan 2011 20:47
i can do the %random% command, and i can set color manually, but how do you set the # of didgts in the %random% command, and how can you set random color?
Code: Select all
@echo off &setlocal
:: all possible HEX digits for background and foreground color
set "digits=0123456789ABCDEF"
:loop
:: calculate two random numbers between 0 and 15 using modulo operation
set /a n1 = %random% %% 16 , n2 = %random% %% 16
:: background and foreground color should never be the same, otherwise calculate new numbers
if %n1%==%n2% goto loop
:: change the colors by picking up two single digits depending on the random numbers
setlocal enabledelayedexpansion
color !digits:~%n1%,1!!digits:~%n2%,1!
endlocal
pause