Générer un nombre aléatoire de 0 à 9 dans un fichier de commandes Windows

Je suis en train d'écrire un fichier de commandes Windows qui permettra de générer un nombre aléatoire de 0 à 9, puis de charger une autre carte de la liste dans notre serveur de jeu basé sur le nombre aléatoire.

J'ai essayé de modifier un fichier similaire qui a été sur ce forum pour générer des caractères aléatoires, mais quand je réduire le maxchars variables de 1 de longueur.

Parfois, j'ai des @echo is off comme réponse et parfois obtenir un numéro.

Voici ce que j'ai:

@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=0123456789
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

Une fois que je peux obtenir ce de manière fiable le choix des personnages, j'ai juste besoin d'ajouter un processus de sélection à la fin qui va appeler le serveur avec une autre ligne de commande pour chaque carte liste.

  • Je pense que vous avez raté le "@echo off" qui fera écho et de sortie de la commande affichera
InformationsquelleAutor Kai Boulton | 2012-07-26