:GetRandomHelper for /f "delims=" %%a in ('set/a %random% % 20 +1') do @set ran_num=%%a If %ran_num% LSS 10 ( set ran_num=0%ran_num% goto :eof ) goto :eofWhy doesn't it work? I want to use it instead of

:GetRandomHelper set %ran_num%=%random% If %ran_num% GTR 20 goto GetRandomHelper If %ran_num% LSS 1 goto GetRandomHelper If %ran_num% LSS 10 ( set ran_num=0%ran_num% goto :eof ) goto :eofMy debugging log shows:

C:\>call :GetRandomHelper C:\> )

('set/a %random% % 20 +1')has no meaning since SET /A needs a variable on the left of the expression, so codeset /A var=%random% %% 20 +1 (YES a double % is needed inside a batch)

for /F "delims=" %%a in ("%var%") do ...but be aware the parsing for /F here is nonsense.

Doubling the % fixed the prob. But now when ran, it shows the same random numbers 1-5 times in a row. =\

('set/a %random% % 20 +1') has no meaning since SET /A needs a variable on the left of the expression, so code

So it would still work without /a?

Thank You!

But now when ran, it shows the same random numbers 1-5 times in a rowI don't understand the above sentence. Anyway to perform computations on batch variables the /A swirch is needed.

Ask Your Question

Weekly Poll

Do you think Monopoly should update its pieces?

Discuss in The Lounge

Poll History