随机字母数字 [英] Random alphanumeric

查看:106
本文介绍了随机字母数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Notepad ++中创建一个随机代码生成器,该生成器将生成长度为32个字符且不包含字母"O或E"的字母数字代码. 下面是我尝试修改以满足我的需要的代码,但似乎无法正常工作.我在这里完全是菜鸟,对我在做什么几乎一无所知. 另外,它是一种将在CMD窗口中操作的解码工具.

I am trying to make a random code generator in Notepad++ that will generate a alphanumeric code that is 32 characters long and does not include the letters "O or E". Below is a code I tried to modify to fit my needs but I cannot seem to get it to work. I am a total noob here and really have little idea of what I am doing. Also the it is a sort of decoding tool that will be operated in a CMD window.

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!

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

Any help would be great and thanks in advance!

推荐答案

@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

这篇关于随机字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆