2016-05-13 72 views
0

隨機字母輸出我如何獲得批量隨機字母輸出劑量不需要在每次它只是使一個新的隨機字母洙像這樣我如何獲得批量

@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 
+1

[如何使用批處理腳本隨機的?](http://stackoverflow.com/questions/5777400/how-to-use-random-in-batch-script) – Jehy

+0

OP的可能的複製如果以下答案之一有幫助,請考慮將其標記爲已接受。 [見本問/答](http://meta.stackexchange.com/q/5234/275822)爲什麼這是重要的解釋。 – rojo

回答

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=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
    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 
3

以下是生成隨機字母的快速方法。 %=ExitCodeAscii%包含%ERRORLEVEL%的ASCII值。 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%