lundi 19 mars 2018

How do I make random not output duplicate answers in batch?

What can I do to make this code NOT output duplicates? Currently, it has a high chance of outputting a duplicate and I would like it to print randomly but not duplicate outputs.

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)

:fruits
set i=0
for %%a in (apple banana grape lime) do (
   set /A i+=1
   set fruit[!i!]=%%a
)

:food
for /l %%x in (1, 1, 2) do (
call :rand
call :colorEcho 70 !fruit!
echo/
)
pause

exit

:rand
set /a rand=%random%%%4+1
set fruit=!fruit[%rand%]!
GOTO :EOF

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
GOTO :EOF




Aucun commentaire:

Enregistrer un commentaire