Solved For /f delims in set random error

December 4, 2011 at 11:53:53
Specs: Windows Vista
: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 :eof

Why 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 :eof

My debugging log shows:

C:\>call :GetRandomHelper 

C:\>	)


See More: For /f delims in set random error

Report •

#1
December 4, 2011 at 12:20:49
✔ Best Answer
('set/a %random% % 20 +1') has no meaning since SET /A needs a variable on the left of the expression, so code

set /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.


Report •

#2
December 4, 2011 at 12:22:05
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?

Report •

#3
December 4, 2011 at 12:29:21
Thank You!

Report •

Related Solutions

#4
December 4, 2011 at 12:44:04
But now when ran, it shows the same random numbers 1-5 times in a row

I don't understand the above sentence. Anyway to perform computations on batch variables the /A swirch is needed.


Report •

Ask Question