0

I want to create a script that goes to a random url (english, french, and spanish, are just examples of url endings and not actual urls). There are probably better way to set variables, but I need it to be in this particular way because of the way the rest of the code is set up.

REM define list entries
set list[0]=english
set list[1]=french
set list[2]=spanish

REM create a random number, smaller than the list's length
set /a randomNum=(%RANDOM%*3/32768)
start "" http://youtube.com/%list[%randomNum%]%

This goes to youtube.com/randomNum, and not the value of the variables I set.

Any help getting it to go to youtube.com/english etc.?

Compo
  • 36,585
  • 5
  • 27
  • 39
user20194509
  • 13
  • 1
  • 2
  • Three words for you to research: Delayed Variable Expansion. – Compo Nov 22 '22 at 16:13
  • This page may be helpful for you: [EnableDelayedExpansion](https://ss64.com/nt/delayedexpansion.html) – Qwerty Nov 22 '22 at 16:30
  • `call start "" http://youtube.com/%%list[%randomNum%]%%` described in [Advanced usage : `CALL`ing internal commands](https://ss64.com/nt/call.html#advanced). – JosefZ Nov 22 '22 at 20:41
  • Use `start "" http://youtube.com/!list[%randomNum%]!` with Delayed Expansion Enabled and see: [arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Nov 23 '22 at 19:49

0 Answers0