返回列表 发帖
前排支持   
[url=][/url]

TOP

其实重复 for + 'set #' 累计耗时是比较多的。
@echo off
set t=%time%
setlocal enabledelayedexpansion
for /l %%a in (1,1,100) do (call :get_sRandom)
echo %t% %time%
pause
rem ---生成随机字符串
:get_sRandom
    set "sRandom="
    set "sTime=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%"
    set "p=ABCDEFGHIJ"
    for /l %%a in (0 1 9) do set "#!random!!random!!random!=!p:~%%a,1!"
    for /f "tokens=1,2 delims==" %%a in ('set #') do (set "%%a="&set "sRandom=!sRandom!%%b")
    set "sRandom=!sTime!!sRandom!"
    echo !sRandom!
    goto :eofCOPY
另外写了一个随机提取的方法,对比下时间:
@echo off
set t=%time%
setlocal enabledelayedexpansion
for /l %%a in (1,1,100) do (call :get_sRandom)
echo %t% %time%
pause
rem ---生成随机字符串
:get_sRandom
    set "sRandom="
    set "sTime=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%"
    set "p=ABCDEFGHIJ"
    for /l %%a in (9,-1,1) do (
        set /a R=!random! %% %%a
        for %%b in (!R!) do set GetSR=!p:~%%b,1!
        for %%c in (!GetSR!) do set p=!p:%%c=!
        set sRandom=!sRandom!!GetSR!
    )
    set "sRandom=!sTime!!sRandom!"
    echo !sRandom!
    goto :eofCOPY
[url=][/url]

TOP

返回列表