I have this:
Code: Select all
FOR /L %%G IN (1,1,6) DO (
SET /A rand%%G=%RANDOM% * (5 - 1 + 1) / 32768 + 1
)
Moderator: DosItHelp
Code: Select all
FOR /L %%G IN (1,1,6) DO (
SET /A rand%%G=%RANDOM% * (5 - 1 + 1) / 32768 + 1
)
If you use any of the logical or modulus operators, you will need to enclose the expression string in quotes.
Code: Select all
setlocal enabledelayedexpansion
FOR /L %%G IN (1,1,6) DO (
SET /A "rand%%G=!RANDOM! * (5 - 1 + 1) / 32768 + 1"
)
Code: Select all
Operator Name Required Special Handling
-------- ------------ --------------------------------------------------
% modulus Must be escaped as %% within a batch file
! not Only if delayed expansion is enabled, then must be
escaped as ^^! without quotes, or ^! within quotes
& and Must be quoted or escaped as ^&
| or Must be quoted or escaped as ^|
^ exclusive or Must be quoted or escaped as ^^
<< left shift Must be quoted or escaped as ^<^<
>> right shift Must be quoted or escaped as ^>^>
) close group Only if appears within a parenthesized block of
code, as often occurs with FOR loops and IF
statements, then must be quoted or escaped as ^)
Code: Select all
FOR /L %%G IN (1,1,6) DO (
SET /A rand%%G=%RANDOM% * (5 - 1 + 1^) / 32768 + 1
^)
Code: Select all
FOR /L %%G IN (1,1,6) DO (
SET /A rand%%G=%RANDOM% * (5 - 1 + 1) / 32768 + 1
^)
Code: Select all
FOR /L %%G IN (1,1,6) DO (
SET /A rand%%G=%RANDOM% * (5 - 1 + 1^) / 32768 + 1
)