下面的两个代码,第一个出错,第二个却成功了,但他们的区别只是第一个(%random%)%%(%n%)+1运算后的值赋予%tn%,而第二个则将运算后的值继续赋予%n%…… 代码如下: @echo off set "string=6 7 8 9 10 11 12 14 15 16 17" for %%i in (%string%) do call set /a "n=%%n%%+1" set /a "tn=(%random%)%%(%n%)+1" for /f "usebackq tokens=%tn% delims= " %%i in ('%string%') do echo %%i pause goto :EOF
代码如下: @echo off set "string=6 7 8 9 10 11 12 14 15 16 17" for %%i in (%string%) do call set /a "n=%%n%%+1" set /a "n=(%random%)%%(%n%)+1" for /f "usebackq tokens=%n% delims= " %%i in ('%string%') do echo %%i pause goto :EOF