Delayed expansion is also required on referencing the value of variable seed
defined and assigned with a random value within a block defined with (
... )
.
@echo off
setlocal EnableDelayedExpansion
set /p "startIndex=Start index: "
set /p "endIndex=End index: "
for /l %%a in (%startIndex% 1 %endIndex%) do (
set "seed=!random!"
echo !seed!
)
set /p "endfile=Wait for it ..."
Further option /a
is not necessary to assign a random number to variable seed
as no arithmetic expression to evaluate. But be careful with spaces around equal sign. All spaces are ignored by set on using option /a
, but are not anymore ignored by command set on a simple assignment without option /a
.
And also take care about where first double quote is written on line with command set as this makes a big difference.
For details about spaces around equal sign and first double quote position see answer on
Why is no string output with 'echo %var%' after using 'set var = text' on command line?