日期:2014-05-17  浏览次数:20872 次

BAT批处理能否实现16位随机码
在批处理文件中能不能生成16位的随机码,如果能,请给个详尽的编写,如不能,请教调用外部文件生成的16位码的方法,辛苦各位高人了!谢谢!

------解决方案--------------------
给你写了个,应该是你要的效果

BatchFile code

::生成十六位随机码 - Forever_Young
@echo off&setlocal enabledelayedexpansion

set "hexstr=0123456789ABCDEF"
set "ranhex="

for /l %%j in (1,1,8) do (
 set /a "dec=!random!"
 set "hex="
 for /l %%n in (1,1,2) do (
  set /a "d=dec&15,dec>>=2"
  for %%d in (!d!) do set "hex=!hexstr:~%%d,1!!hex!"
 )
 set ranhex=!hex!!ranhex!
)
echo !ranhex!

pause

------解决方案--------------------
BatchFile code
@echo off & setlocal enabledelayedexpansion
set s=0123456789ABCDEF
set "result="

for /l %%a in (1,1,16) do (
    set /a r=!random!%%16
    call set result=!result!%%s:~!r!,1%%
)

echo %result%
pause