0

Is there a way of making it so instead of saying the same echo that you set every time, you can give a list of echos and it chooses a random one to say each time it reaches that echo command?

Andreas
  • 5,393
  • 9
  • 44
  • 53

2 Answers2

1

Yep. Here's a proof of concept.

@echo off
setlocal enabledelayedexpansion

set string[0]=This is the first random line.
set string[1]=This is the second random line.
set string[2]=This is the third random line.

set /a idx=%random% * 3 / 32768

echo !string[%idx%]!

Here's more info on generating random numbers in Windows batch scripting.

Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
0
@echo OFF
SETLOCAL
SET message0=message zero
SET message1=message one
SET message2=message two
SET message3=message three
SET message4=message four

:: running 10 times

FOR /l %%i IN (1,1,10) DO CALL :showme
GOTO :eof

:showme
SET /a select=%RANDOM% %% 5
CALL SET message=%%message%select%%%
ECHO %message%
GOTO :eof
Magoo
  • 77,302
  • 8
  • 62
  • 84