如何批量生成随机字母输出,每次只需要更新一个新的随机字母就不需要更新
@echo off
title random letter gen
echo welcome
echo press any key to get a random letter
!!!!!!!!!!!!i want the %letter% to give a random letter!!!!!!!!!!
echo %letter%
echo press a key to get a new letter
pause
goto a
:a
echo %letter%
pause
goto a
答案 0 :(得分:5)
这是生成随机字母的快捷方式。 %=ExitCodeAscii%
包含ASCII值%ERRORLEVEL%
。 More information
rem // generate a random number between 65 and 90
set /a "ascii = %random% * 26 / 32768 + 65"
rem // set errorlevel to that number
cmd /c exit /b %ascii%
rem // get letter corresponding to that exit code
echo %=ExitCodeAscii%
答案 1 :(得分:2)
Eggsedan,
我在Superuser.com上找到了这段代码。它被设计为密码生成器,但您可以编辑为仅允许它生成单个字符。
https://superuser.com/questions/349474/how-do-you-make-a-letter-password-generator-in-batch
希望这能满足您的需求。
@Echo Off
color 0a
set /P lengthnumberuser="What length do you want your password to be? "
pause
cls
Setlocal EnableDelayedExpansion
Set _RNDLength=%lengthnumberuser%
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _Str=%_Alphanumeric%987654321
:_LenLoop
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET _tmp=%_Str:~9,1%
SET /A _Len=_Len+_tmp
Set _count=0
SET _RndAlphaNum=
:_loop
Set /a _count+=1
SET _RND=%Random%
Set /A _RND=_RND%%%_Len%
SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
If !_count! lss %_RNDLength% goto _loop
Echo Password is: is !_RndAlphaNum!
pause
答案 2 :(得分:1)
您也可以使用 The Exit code ASCII output 来输出小写和数字。
这是一个使用数字小写和大写字符的随机字符串生成器:
@ECHO OFF& SETLOCAL ENABLEDELAYEDEXPANSION
:RandomStrings
::: numbers: char 48 + (0-9)
::: lowercase: char 97 + (0-25)
::: uppercase: char 65 + (0-25)
SET "RANDSTUFF="
SET "CharCount=8"
FOR /L %%A in (1,1,%CharCount%) DO (
SET /A "Chance=%RANDOM% %% 3"
CALL :RandomStrings.!Chance!
)
ECHO.!RANDSTUFF!
EXIT /B
:RandomStrings.0
SET /A "nAscii=%RANDOM%*9/32768+48"
CMD /c EXIT /b %nAscii%
SET RANDSTUFF=!RANDSTUFF!%=ExitCodeASCII%
EXIT /B
:RandomStrings.1
SET /A "lAscii=%RANDOM%*26/32768+97"
CMD /c EXIT /b %lAscii%
SET RANDSTUFF=%RANDSTUFF%%=ExitCodeASCII%
EXIT /B
:RandomStrings.2
SET /A "uAscii=%RANDOM%*26/32768+65"
CMD /c EXIT /b %uAscii%
SET RANDSTUFF=%RANDSTUFF%%=ExitCodeASCII%
EXIT /B