 <p><em><a href="http://ss64.com/nt/set.html" rel="nofollow">The <code>CALL SET</code> syntax</a> allows a <a href="http://ss64.com/nt/syntax-substring.html" rel="nofollow">variable substring</a> to be evaluated, the <a href="http://ss64.com/nt/call.html" rel="nofollow">CALL page</a> has more detail on this technique, in most cases a better approach is to use <a href="http://ss64.com/nt/delayedexpansion.html" rel="nofollow"><code>Setlocal EnableDelayedExpansion</code></a></em>. </p> <p>Command line (note that all <code>%</code> percent signs are <a href="http://ss64.com/nt/syntax-esc.html" rel="nofollow">escaped</a> as <code>^%</code> and that <code>&gt;</code> and <code>&amp;</code> characters are escaped within a pair of <code>"</code> double quotes:</p> <pre><code>set "zeroThroughNine=call set /a number=^%Random^% ^% 10&gt;nul &amp; call echo number=^%number^%" %zeroThroughNine% for /L %G in (1, 1, 10) do @%zeroThroughNine% </code></pre> <p>Batch script, <strong><code>CALL</code> method</strong> (note that all <code>%</code> percent signs are escaped as <code>%%</code>):</p> <pre><code>@echo OFF SETLOCAL set "_zeroThroughNine=call set /a _number=%%Random%% %%%% 10 &amp; call echo number=%%_number%%" echo check variables set _ echo output %_zeroThroughNine% for /L %%G in (1,1,10) do %_zeroThroughNine% echo check variables after evaluating set _ ENDLOCAL </code></pre> <p>Batch script, <strong><code>EnableDelayedExpansion</code> only for output</strong>:</p> <pre><code>@echo OFF SETLOCAL EnableExtensions DisableDelayedExpansion set "_zeroThroughNine=set /a _number=!Random! %% 10 &amp; echo Number=!_number!" SETLOCAL EnableDelayedExpansion echo check variables set _ echo output %_zeroThroughNine% for /L %%G in (1,1,10) do %_zeroThroughNine% echo check variables after evaluating set _ ENDLOCAL ENDLOCAL </code></pre> <p>Batch script, <strong><code>EnableDelayedExpansion</code> script wide</strong> (note that <code>!</code> exclamation sign is escaped as <code>^!</code>):</p> <pre><code>@echo OFF SETLOCAL EnableExtensions EnableDelayedExpansion set "_zeroThroughNine=set /a _number=^!Random^! %% 10 &amp; echo NUMBER=^!_number^!" echo check variables set _ echo output %_zeroThroughNine% for /L %%G in (1,1,10) do %_zeroThroughNine% echo check variables after evaluating set _ ENDLOCAL </code></pre>