Search code examples
batch-filerandomemulationpicker

Random File Picker Picks Same Value On Each Execution (batch)


I'm trying to launch a random file with this software via a script - the only problem is that this script always selects the same random number on every launch. It's always 41 for me... Any suggestions?

@echo on
setlocal EnableDelayedExpansion
cd C:\Users\User\Documents\Downloads\Nintendo
set n=0
for %%f in (*.*) do (
   set /A n+=1
   set "file[!n!]=%%f"
)
set /A "rand=%random% * 100 / 32768+1"
"C:\Users\User\Downloads\fceux-2.2.2-win32\fceux.exe" "!file[%rand%]!"

Solution

  • That works for me:

    @echo off
    setlocal enabledelayedexpansion
    c:
    cd \windows
    
    for %%f in (*.*) do (
       set /A n+=1
       set "file[!n!]=%%f"
    )
    
    rem change random seed value
    for /l %%i in (0,1,%time:~-2%) do set /A tmp=!random!
    
    set /A rand=!random! %% n-1
    echo "!file[%rand%]!"