1.

Solve : random selection?

Answer»

if i set a range 0-9 how would i make a batch file ramdomly select a number 0-9 and ABCDEF (COLORS)??Quote

if i set a range 0-9 how would i make a batch file ramdomly select a number 0-9 and ABCDEF (colors)

You SEEM to have a serious misconception of what batch files can and cannot do. "make a batch file" and "randomly" are mutually exclusive terms in batch language. You can write a batch file that will allow you the user to test out all the possible color combinations for the cmd window:

CODE: [Select]@echo off
:start
set /p id=Enter the color code:

for %%a in (A B C D E F 0 1 2 3 4 5 6 7 8 9) do (
for %%b in (A B C D E F 0 1 2 3 4 5 6 7 8 9) do (
if /i %id%==%%a%%b goto OK
)
)
Echo Invalid Color Code...Try Again
goto start

:OK
color %id%

How's that online batch course you're taking? it is REALY helping i figered out the for loops a bit yesterday i can filter down serches with them now For the random number between 0 and 9 you can use
Code: [Select]set /a rnd=%random% / (32767 / 10)
echo Random number between 0 and 9 is %rnd%where can i get a list of all the variables like that ( %random% %errorlevel% %OS% ) and so on I found a list of them but it does not say how to use them so if you know of one that would be very helpfull just google it..one found here
http://www.winnetmag.com/Article/ArticleID/23873/23873.htmli did goole it i found some like that but they did not have them all :-/how did you know they don't have them all?
if you have doubts , check it out on microsoft site itself
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=trueThis is what i did to get i random letter and number
Code: [Select]@echo off
:start
set /a rnd=%random% / (32767 / 16)
if %rnd% EQU 10 set rnd=A
if %rnd% EQU 11 set rnd=B
if %rnd% EQU 12 set rnd=C
if %rnd% EQU 13 set rnd=D
if %rnd% EQU 14 set rnd=E
if %rnd% EQU 15 set rnd=F
if %rnd% EQU 16 goto :start
set /a rnd1=%random% / (32767 / 16)
if %rnd1% EQU 10 set rnd1=A
if %rnd1% EQU 11 set rnd1=B
if %rnd1% EQU 12 set rnd1=C
if %rnd1% EQU 13 set rnd1=D
if %rnd1% EQU 14 set rnd1=E
if %rnd1% EQU 15 set rnd1=F
if %rnd1% EQU 16 goto :start
if %rnd% EQU %rnd1% goto :start
set random1=%rnd%%rnd1%
color %random1%
goto :startOr simplified:

Code: [Select]set HEX=0123456789ABCDEF
:again
set /a r1=%random% %% 16
set /a r2=%random% %% 16
call set rndcolor=%%HEX:~%r1%,1%%%%HEX:~%r2%,1%%
color %rndcolor%
goto:againOptionally use the getRandomColor function from:
http://dostips.cmdtips.com/DtCodeCmdLib.php#getRandomColor:

:again
call:getRandomColor rndcolor
color %rndcolor%
goto:again


Hope this info is useful


Discussion

No Comment Found