我正在嘗試編寫一個Windows批處理文件,該文件將生成一個從0到9的隨機數,然後在我們的遊戲服務器中加載一個不同的地圖列表隨機數。在Windows批處理文件中生成0-9中的隨機數
我試圖修改一個類似的文件,在這個論壇上生成隨機字符,但是當我將maxchars變量的長度減少到1。
我有時會得到@echo is off
作爲迴應,有時會得到一個數字。
這是我有:
@echo off & setlocal EnableDelayedExpansion
REM Random.bat
REM
REM Change these values to whatever you want, or change the code to take them
REM as command-line arguments. You must set CHARS_LEN to the string length
REM of the string in the CHARS variable.
REM
REM This script generates a string of these characters at least
REM MIN_CHARS_IN_LINE chars long and at most MAX_CHARS_IN_LINE chars long.
SET CHARS=
SET /A CHARS_LEN=10 + 10 + 10
SET /A MIN_CHARS_IN_LINE=1
SET /A MAX_CHARS_IN_LINE=2
REM Pick a random line length and output a random character until we reach that
REM length.
call:rand %MIN_CHARS_IN_LINE% %MAX_CHARS_IN_LINE%
SET /A LINE_LENGTH=%RAND_NUM%
SET LINE=
for /L %%a in (1 1 %LINE_LENGTH%) do (
call:rand 1 %CHARS_LEN%
SET /A CHAR_INDEX=!RAND_NUM! - 1
CALL SET EXTRACTED_CHAR=%%CHARS:~!CHAR_INDEX!,1%%
SET LINE=!LINE!!EXTRACTED_CHAR!
)
echo !LINE!
goto:EOF
REM The script ends at the above goto:EOF. The following are functions.
REM rand()
REM Input: %1 is min, %2 is max.
REM Output: RAND_NUM is set to a random number from min through max.
:rand
SET /A RAND_NUM=%RANDOM% * (%2 - %1 + 1)/32768 + %1
goto:EOF
:eof
一旦我能得到這個可靠地選擇角色我只需要一個選擇過程增加,這將調用服務器爲每個地圖列表中的不同命令行的末尾。
我想你錯過了「回聲消失」這將關閉回聲和命令輸出將顯示 – 2013-11-11 04:44:55