0

有没有办法做到这一点,而不是每次都说你设置的相同回声,你可以给出一个回声列表,并在每次到达该回声命令时选择一个随机的回声?

4

2 回答 2

1

是的。这是一个概念证明。

@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%]!

这是有关在 Windows 批处理脚本中生成随机数的更多信息。

于 2013-03-20T18:31:31.623 回答
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
于 2013-03-20T18:32:42.527 回答