Get a random sentence from a selection each time in Batch

前端 未结 2 872
感情败类
感情败类 2021-01-28 14:50

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

2条回答
  •  长情又很酷
    2021-01-28 15:48

    @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
    

提交回复
热议问题