0

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
Excallypurr
  • 319
  • 1
  • 16
  • Surely it would make more sense for your `set /a rand=%random%%%4+1` line to use `%i%` instead of `4`. – Compo Mar 19 '18 at 14:54
  • Not for my purposes. In this example it seems like that, yes. But in my uses I need it hard coded. I just only came up with 4 examples for this post. – Excallypurr Mar 19 '18 at 20:22
  • If you use `%i%` you won't need to adjust anything later, it will always use the number of items between the `for` parentheses under the `:fruits` label. – Compo Mar 19 '18 at 20:26

0 Answers0