本帖最后由 77七 于 2023-7-16 12:10 编辑
回复 3# 447219071
修改一下,兼容末尾大量空行,随机性可能也高一点- @echo off
- cd /d "文本所在路径\"
- for /f "useback delims=" %%a in ("a.txt") do set /a n+=1
-
- set /a m=%random% %% n
-
- if %m%==0 (set skip=) else set skip=skip=%m%
- for /f "%skip% delims=" %%a in ('findstr . "a.txt"') do set "str=%%a" & goto end
-
- :end
- echo "%str%"
- pause
复制代码
|