假定文件名是与批处理文件同位置1.txt@echo offfor /f "tokens=1* delims=:" %%i in ( 'findstr/rvxc:" *" "1.txt"^|findstr/n .')do set "#%%i=%%j"&set/a n+=1set/a "s=%random%%%n+1"call set s=%%#%s%%%echo %s%pause
%random% 用这个随机函数