需要一行代码来输出指定字符的随机字符串

发布于 2024-11-04 14:41:06 字数 70 浏览 5 评论 0原文

我正在记事本中工作,需要一行代码来吐出随机的一行字符(我指定的)。我还需要能够更改数字字符。

有人可以帮忙吗?

I am working in notepad, and a need a line of code that will spit out a random line of characters (that I specify). I need to be able change the number characters also.

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小帐篷 2024-11-11 14:41:07

我真的不确定你到底在问什么,但也许你想要一个批处理文件来吐出一行随机字符,这里有一个脚本可以做到这一点。

示例输出:

C:\>rand_chars
XF3KqsBIFzi
C:\>rand_chars
UNx1eQ8MebihmizfIjHT4gc7O85uIOxBk5u8xZj8pnBBOf0jSygII4kNx7IUJA8nMchRKl1f6sQgJjB

代码:

@echo off & setlocal EnableDelayedExpansion

REM Change these values to whatever you want, or change the code to take them
REM as command-line arguments.  You must set CHARS_LEN to the string length
REM of the string in the CHARS variable.
REM 
REM This script generates a string of these characters at least
REM MIN_CHARS_IN_LINE chars long and at most MAX_CHARS_IN_LINE chars long.

SET CHARS=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
SET /A CHARS_LEN=26 + 26 + 10
SET /A MIN_CHARS_IN_LINE=5
SET /A MAX_CHARS_IN_LINE=79

REM Pick a random line length and output a random character until we reach that
REM length.

call:rand %MIN_CHARS_IN_LINE% %MAX_CHARS_IN_LINE%
SET /A LINE_LENGTH=%RAND_NUM%

SET LINE=
for /L %%a in (1 1 %LINE_LENGTH%) do (
    call:rand 1 %CHARS_LEN%
    SET /A CHAR_INDEX=!RAND_NUM! - 1
    CALL SET EXTRACTED_CHAR=%%CHARS:~!CHAR_INDEX!,1%%
    SET LINE=!LINE!!EXTRACTED_CHAR!
)
echo !LINE!

goto:EOF

REM The script ends at the above goto:EOF.  The following are functions.

REM rand()
REM Input: %1 is min, %2 is max.
REM Output: RAND_NUM is set to a random number from min through max.
:rand
SET /A RAND_NUM=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
goto:EOF

I'm really not sure what exactly you're asking, but maybe you want a batch file that spits out a line of random characters, and here's a script that will do that.

Example output:

C:\>rand_chars
XF3KqsBIFzi
C:\>rand_chars
UNx1eQ8MebihmizfIjHT4gc7O85uIOxBk5u8xZj8pnBBOf0jSygII4kNx7IUJA8nMchRKl1f6sQgJjB

Code:

@echo off & setlocal EnableDelayedExpansion

REM Change these values to whatever you want, or change the code to take them
REM as command-line arguments.  You must set CHARS_LEN to the string length
REM of the string in the CHARS variable.
REM 
REM This script generates a string of these characters at least
REM MIN_CHARS_IN_LINE chars long and at most MAX_CHARS_IN_LINE chars long.

SET CHARS=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
SET /A CHARS_LEN=26 + 26 + 10
SET /A MIN_CHARS_IN_LINE=5
SET /A MAX_CHARS_IN_LINE=79

REM Pick a random line length and output a random character until we reach that
REM length.

call:rand %MIN_CHARS_IN_LINE% %MAX_CHARS_IN_LINE%
SET /A LINE_LENGTH=%RAND_NUM%

SET LINE=
for /L %%a in (1 1 %LINE_LENGTH%) do (
    call:rand 1 %CHARS_LEN%
    SET /A CHAR_INDEX=!RAND_NUM! - 1
    CALL SET EXTRACTED_CHAR=%%CHARS:~!CHAR_INDEX!,1%%
    SET LINE=!LINE!!EXTRACTED_CHAR!
)
echo !LINE!

goto:EOF

REM The script ends at the above goto:EOF.  The following are functions.

REM rand()
REM Input: %1 is min, %2 is max.
REM Output: RAND_NUM is set to a random number from min through max.
:rand
SET /A RAND_NUM=%RANDOM% * (%2 - %1 + 1) / 32768 + %1
goto:EOF
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文