【问题标题】:Random alphanumeric随机字母数字
【发布时间】:2014-07-30 20:08:36
【问题描述】:

我正在尝试在 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!

任何帮助都会很棒,并在此先感谢!

【问题讨论】:

    标签: batch-file


    【解决方案1】:
    @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
    

    【讨论】:

      【解决方案2】:

      我这样做,自动更改 guid,一切都很好,但随机的 /d 数据不起作用.. @echo 关闭

      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 IF %errorlevel%==0 转到最后一步 IF %errorlevel%==1 goto 失败

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

      :最后一步 reg add "HKCU\Console\Cupcakes" /v "MachineGuid" /t "REG_SZ" /d "%k%" /f 暂停

      【讨论】:

        猜你喜欢
        • 2012-06-24
        • 2014-07-31
        • 1970-01-01
        • 1970-01-01
        • 2010-09-08
        • 2012-05-30
        • 2017-05-22
        • 2011-01-29
        相关资源
        最近更新 更多