This is the code snippet (credit to Aacini for the snippet):
@echo off
setlocal EnableDelayedExpansion
rem total number of random numbers:
set /A "RND_TOTAL=8"
rem range for random numbers (minimum, maximum, interval):
set /A "RND_MIN=1, RND_MAX=10, RND_INTER=1"
rem Create an input vector with all numbers in given range
set "n=0"
for /L %%i in (%RND_MIN%,%RND_INTER%,%RND_MAX%) do (
set /A n+=1
set "in[!n!]=%%i"
)
echo Input:
set in[
echo/
rem Extract RND_TOTAL elements from input vector in random order
for /L %%i in (1,1,%RND_TOTAL%) do (
set /A "randIndex=(!random!*n)/32768+1"
set /A "out[%%i]=in[!randIndex!], in[!randIndex!]=in[!n!], n-=1"
)
echo Output:
set out[
How do I get this working with strings? So that instead of
out[1]=2
out[2]=8
out[3]=9
out[4]=5
etc...
I can get
out[1]=dog
out[2]=cat
out[3]=possum
out[4]=flea
Where those strings were picked from an array and randomized.
Aucun commentaire:
Enregistrer un commentaire