标题: [已结]求获取随机位数的字符
[打印本页]
作者: ka56
时间: 2008-12-3 19:52
标题: [已结]求获取随机位数的字符
@echo off&setlocal ENABLEDELAYEDEXPANSION
set a=abcdefghijklmnopqrstuvwxyz
set /a a_=(%random%+26)%%26
set /a b_=(%random%+26)%%26
set /a c_=(%random%+26)%%26
set /a d_=(%random%+26)%%26
set /a f_=(%random%+26)%%26
set /a g_=(%random%+26)%%26
set h=!a:~%a_%,1!!a:~%b_%,1!!a:~%c_%,1!!a:~%d_%,1!!a:~%f_%,1!!a:~%g_%,1!
set j=!a:~%a_%,1!!a:~%b_%,1!!a:~%c_%,1!!a:~%d_%,1!!a:~%f_%,1!
set i=!a:~%a_%,1!!a:~%b_%,1!!a:~%c_%,1!!a:~%d_%,1!
set k=!a:~%a_%,1!!a:~%b_%,1!!a:~%c_%,1!
想随机获取%h% %j% %i% %k%这4个中的一个,如果能把位数变成随机的更好~~
[
Last edited by ka56 on 2008-12-3 at 23:05 ]
作者: ka56
时间: 2008-12-3 20:40
搜索得到答案:
set var1=%h% %j% %i% %k%
set/a var2=%random%%%4+1
for /f "tokens=%var2% delims= " %%x in ("%var1%") do (
echo %%x)
pause
不知道有没更精简的不~ : )
作者: 26933062
时间: 2008-12-3 21:16
是这个意识吗?
@echo off&Setlocal EnableDelayedExpansion
set "str=abcdefghijklmnopqrstuvwxyz"
set /a n=!random!%%26
echo !str:~%n%,1!
pause
作者: ka56
时间: 2008-12-3 22:04
要随机位数+随机字符的字符串
运行一次,得到一行,如:
yry
gdtukk
rsjkjo
fyoihi
dfswestyui
应该也得限制长度吧,不然估计会死机...

作者: moniuming
时间: 2008-12-3 22:16
标题: 这样?
@echo off&Setlocal Enabledelayedexpansion
set "str=abcdefghijklmnopqrstuvwxyz"
for /l %%a in (1 1 20) do (
set /a "var1=!random!%%10+5","n=0"&set "var="
call :lb
)
echo.&pause&goto :eof
:lb
if "%n%"=="%var1%" (echo %var%&goto :eof)
set /a n+=1,var2=%random%%%26
set "var=%var%!str:~%var2%,1!"
goto :lb
作者: ka56
时间: 2008-12-3 23:05
Quote: |
Originally posted by moniuming at 2008-12-3 22:16:
|
|
是的,一行就够了,有点深度,我研究下,多谢指教!!