dimanche 12 septembre 2021

How do I make the output random? batch

Focusing on the for loops, I'm basically trying to run through each set of characters defined in alpha, beta, and gamma variables. I want to print out random ones from each variable upon for loop iteration. How could I do this?

@echo off
setlocal

rem starts program introduction
:start
echo "This program prints random token characters."
echo.
pause
cls
goto alpha

rem uses for /f loop to print token characters
rem with the space delimeter
:alpha
setlocal
set alpha=abvs5656 456465 4564564 456456546
set beta=5 6 f g
set gamma="zy x w 458923 %$1 % # $@"
rem using two tokens like here (%%a and %%b) will output the correct
rem numbers. The takeaway is to have the same number of iteration
rem tokens, %%a, %%b, %%c, etc. for the number designated
rem in the tokens field in the for loop.
for /f "tokens=1,2,4 delims= " %%a in ("%alpha%") do set first=%%a %%b %%c
echo %first%
for /f "tokens=* delims= " %%a in ("%beta%") do set second=%%a
echo %second%
pause
endlocal

endlocal



Aucun commentaire:

Enregistrer un commentaire