Batch file 从文本文件中选择随机行并执行

Batch file 从文本文件中选择随机行并执行,batch-file,random,Batch File,Random,我有一个文本文件中的25个网站的列表,每一个单独的行,我想通过一个批处理文件以随机顺序打开它们 网站.txt ... google.com facebook.com ... 我知道我需要使用for循环,但不确定如何从随机行中提取网址。我想用 for /f "tokens=%rannum%" 但是所有的网站都必须在同一条线上,而且我的测试结果不太好。还需要有一种方法来确保同一个网站不会被打开两次 到目前为止我所拥有的 @echo off set file=openweb.txt set /a

我有一个文本文件中的25个网站的列表,每一个单独的行,我想通过一个批处理文件以随机顺序打开它们

网站.txt

...
google.com
facebook.com
...
我知道我需要使用for循环,但不确定如何从随机行中提取网址。我想用

for /f "tokens=%rannum%"
但是所有的网站都必须在同一条线上,而且我的测试结果不太好。还需要有一种方法来确保同一个网站不会被打开两次

到目前为止我所拥有的

@echo off
set file=openweb.txt
set /a total_lines=1
for /f %%a in ('Type %_File%^|Find "" /v /c') Do Set /a total_lines=%%a
set /a start_count=0
set "found=found.txt"
if exist "%found%" del "%found%"
copy NUL found.txt
if %start_count% NEQ %total_lines% (
:run_again
REM Randomly select a number between 1-26
set /a random_number=%random% %% 26-1
REM Validation Random number was not used already
findstr /m "%random_number%" %found%
if %errorlevel%==0 (
echo already found
goto:run_again
)
REM Open each website. Wait 2sec between each. 
for /f %%a in (websites.txt) do (
start iexplore %%a
@ping 127.0.0.1 -n 2 -w 1000 > nul
)
REM write out Random Number to the .txt
@echo %random_number%>>%found%
set /a start_count+=1
)
欢迎提供有关如何改进此代码的任何信息。谢谢

试试这个:

@echo off
set file=openweb.txt
set /a lines=25

set /a skip=%random%%%lines%-1
more %file% +%skip% > temp.tmp
set /p target=< temp.tmp
del temp.tmp

Echo %target%

我想这会有用的。。。发件人: