RosettaCodeData/Task/Pick-random-element/Batch-File/pick-random-element.bat

17 lines
360 B
Batchfile
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
@echo off
setlocal enabledelayedexpansion
2026-04-30 12:34:36 -04:00
::Initializing the pseudo-array...
2023-07-01 11:58:00 -04:00
set "pseudo=Alpha Beta Gamma Delta Epsilon"
set cnt=0 & for %%P in (!pseudo!) do (
2026-04-30 12:34:36 -04:00
set /a cnt+=1
set "pseudo[!cnt!]=%%P"
2023-07-01 11:58:00 -04:00
)
2026-04-30 12:34:36 -04:00
::Do the random thing...
2023-07-01 11:58:00 -04:00
set /a rndInt=%random% %% cnt +1
2026-04-30 12:34:36 -04:00
::Print the element corresponding to rndint...
2023-07-01 11:58:00 -04:00
echo.!pseudo[%rndInt%]!
pause
exit /b