For question

  • Thread starter Thread starter Gustavio
  • Start date Start date
G

Gustavio

Hello,

Why this command give me se same Random number for each iteration ? How can
I have a different one each iteration ?

For /L %%i IN (1,1,10) do @echo %RANDOM%

Thanks
Gustavio
 
Hi Gustavio,

The %RANDOM% variable is only expanded once, when the FOR command first
executes. You need to enable delayed variable expansion, and use !RANDOM!
so it will be expanded each time.

@Echo Off
SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
For /L %%i In (1,1,10) Do @Echo !RANDOM!


For more info, see SET /? and SETLOCAL /?
 
Thanks a lot

Marty List said:
Hi Gustavio,

The %RANDOM% variable is only expanded once, when the FOR command first
executes. You need to enable delayed variable expansion, and use !RANDOM!
so it will be expanded each time.

@Echo Off
SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
For /L %%i In (1,1,10) Do @Echo !RANDOM!


For more info, see SET /? and SETLOCAL /?
 
Back
Top