随机字母数字

时间:2014-07-30 20:08:37

标签: batch-file

我正在尝试在Notepad ++中创建一个随机代码生成器,它将生成一个长度为32个字符的字母数字代码,并且不包含字母" O或E"。 下面是我试图修改以满足我的需求的代码,但我似乎无法让它工作。我在这里完全是菜鸟,对我正在做的事情一点都不知道。 它也是一种将在CMD窗口中操作的解码工具。

Echo Off
Setlocal EnableDelayedExpansion
Set _RNDLength=8
Set _Alphanumeric=abcdfghijklmnpqrstuvwxyz0123456789
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 Random string is !_RndAlphaNum!

任何帮助都会很棒,并提前致谢!

2 个答案:

答案 0 :(得分:2)

@echo off

    setlocal enableextensions enabledelayedexpansion

    rem Define alphabet
    set "alphabet=a b c d f g h i j k l m n p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9"

    rem Create an "array" with the elements of the alphabet
    set "size=0"
    for %%a in (%alphabet%) do (
        set "a.!size!=%%a"
        set /a "size+=1"
    )

    rem Generate the output, selecting 32 randoms elements from the array
    set "k="
    for /l %%a in (1 1 32) do (
        set /a "r=!random! %% size"
        for %%b in (!r!) do set "k=!k!!a.%%b!"
    )
    echo(%k%

    endlocal

答案 1 :(得分:0)

我这样做是为了自动更改GUID,但是/ d的所有数据都是随机的,但是不起作用.. @回声关闭

setlocal enableextensions enabledelayedexpansion

rem Define alphabet
set "alphabet=a b c d f g h i j k l m n p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9"

rem Create an "array" with the elements of the alphabet
set "size=0"
for %%a in (%alphabet%) do (
    set "a.!size!=%%a"
    set /a "size+=1"
)

rem Generate the output, selecting 32 randoms elements from the array
set "k="
for /l %%a in (1 1 32) do (
    set /a "r=!random! %% size"
    for %%b in (!r!) do set "k=!k!!a.%%b!"
)
echo (%k%
endlocal

reg查询HKCU \ Console \ Cupcakes 如果%errorlevel%== 0转到最后一步 如果%errorlevel%== 1失败了

:失败 cls 颜色4 回声失败 暂停 退出

:FINALSTEP reg添加“ HKCU \ Console \ Cupcakes” / v“ MachineGuid” / t“ REG_SZ” / d“%k%” / f 暂停