I need to randomly select an element from an array. The array may have 1-8 elements. This article appears to be out of date - it is telling me I can do it this way, but when I try (or even just copy-paste its code) it fails, instead giving me the variable's name surrounded by %s.
SET _Array[1]=Option1
SET _Array[2]=Option2
SET _Array[3]=Option3
SET _Array[4]=Option4
SET /A _throwaway=%RANDOM%
SET /A _Index=%RANDOM% * 4 / 32768
ECHO %%_Array[%_Index%]%%
Assuming that %RANDOM% * 4 / 32768
gave 1, the above should output:
Option 1
but instead it outputs:
%_Array[1]%
I've tried several permutations, doubling the %s in different places, using a CALL, even
FOR /L %%G IN (%_Index%,8,8) DO (ECHO %_Array[%%G])
No dice.