文本要是固定3位可以这样- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (a.txt) do (
- set /a n+=1
- set /a ar[!n!]=1%%a-1000
- )
- set /a r=!random!%%n+1
- echo !ar[%r%]!
- pause
复制代码 如果文本不存在为0的行可以这样- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=* delims=0" %%a in (a.txt) do (
- set /a n+=1
- set ar[!n!]=%%a
- )
- set /a r=!random!%%n+1
- echo !ar[%r%]!
- pause
复制代码 不然可以这样,最通用了- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (a.txt) do (
- set /a n+=1
- set ar[!n!]=0
- for /f "tokens=* delims=0" %%b in ("%%a") do set ar[!n!]=%%b
- )
- set /a r=!random!%%n+1
- echo !ar[%r%]!
- pause
复制代码
|