Solved Wondering about the syntax with %random% in batch

July 19, 2012 at 07:19:39
Specs: Windows XP
I was wondering about the syntax with %random% in batch today as I have never seen it set up this way before.

someone on another post used

%random% %% 10 to generate a random number between 1-10.

I guess I am a newbie with this kind of thing, as I thought the only way to do so was to use a set of if statements for example

set /a ran2=%random%
if /i %ran2% GTR 10 goto :ans2
if /i %ran2% LSS 1 goto :ans2
set lotnum=%ran2%

I was curious as to why this works %random% %% 10 ?

Thanks for your time.

:: mike

See More: Wondering about the syntax with %random% in batch

Report •

July 19, 2012 at 07:47:28
✔ Best Answer
It technically generates a random number between 0-9; you would need to add 1 to make it 1-10.
As for what's happening, "%" (or "%%" in batch files) is the modulo operator.

How To Ask Questions The Smart Way

Report •

July 19, 2012 at 08:50:55
Sweet, thank you for the link. I never was that excellent at math. However, I believe I understand how it works now. Thank you for taking the time, If I was paying attention, I might have noticed that the set /a command references using the %% for this.

:: mike

Report •
Related Solutions

Ask Question