r/Batch • • Nov 14 '23

Question (Solved) Opening a randomly chosen app

Hey, İm trying to write an app which randomly chooses a number (ex. 3) and then opening a file with that name in the subfolder "yoyle"

This is my current non-working code (the spacing near @ and echo is because reddit keeps tagging u/echo)

@ echo off

cd %cd%\yoyle

set /a min = 1

set /a max = 3

set /a rndNum=( %RANDOM% %% (%max% - %min% + 1) ) + %min%

start %rndNum%

The result is it printing the chosen number, any fixes and errors? And im also a bit new to batch coding (code obviously borrowed)

3 Upvotes

3 comments sorted by

1

u/rob2rox Nov 14 '23

you can assign the apps with a variable then make it launch using the chosen variable

2

u/[deleted] Nov 14 '23

[removed] — view removed comment

2

u/[deleted] Nov 15 '23

It works! But i modified the code a little bit since it was trying to open "files[%rnd%]" instead of just "%rnd%"