Like I said, the formula is somewhat simplistic. It doesn't produce a number greater than 32767, which is the limitation of %RANDOM%. That might well be enough for you, but in case it is not, you could extend the range to 2-1 using two %RANDOM% calls like this:SET /A skip=(%RANDOM%*32768+%RANDOM%)%%lines因此,这里再次是相同的脚本,经过修改以解决上述问题:So, here's the same script again, amended to address the above mentioned issues:@ECHO OFFIF "%~1"=="" GOTO :EOFIF NOT EXIST %1 GOTO :EOFFOR /F "" %%I IN ('FIND /C /V "" ^<%1') DO SET /A lines=%%IIF %lines%==0 GOTO :EOFSET /A skip=(%RANDOM%*32768+%RANDOM%)%%lines<%1 ( FOR /L %%I IN (1,1,%skip%) DO ( SET /P line= ) SET line= SET /P line=)ECHO(%line%另一个注意事项是,如果您愿意,可以添加说明脚本过早终止的原因的消息.基本上,无论您要将消息添加到何处,都只需替换单个One other note is that, if you like, you can add messages explaining the reason for the premature termination of the script. Basically, wherever you want to add the message, you'll just need to replace the singleGOTO :EOF使用(ECHO your message & GOTO :EOF)例如:IF NOT EXIST %1 (ECHO Error! File not found & GOTO :EOF) 这篇关于使用批处理的随机文本行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 06:23
查看更多