hi
I was wondering if you can tell the %random% command to generate a number between 200 and 400
any help would be greatly appreiciated
-=BatMaster=-
use %random% to echo a number between 200 and 400
Moderator: DosItHelp
Re: use %random% to echo a number between 200 and 400
'
[SOLVED] SET /a -- Random Number?
viewtopic.php?f=3&t=1817&hilit=random+number
Just don't get addicted to macros
[SOLVED] SET /a -- Random Number?
viewtopic.php?f=3&t=1817&hilit=random+number
Just don't get addicted to macros
Re: use %random% to echo a number between 200 and 400
Ed Dyreen wrote:'
Just don't get addicted to macros
I'm afraid it's difficult to understand for a beginner
I'll try to explain how such a calculation could look like:
Code: Select all
@echo off &setlocal
set /a n1=200
set /a n2=400
:: difference between n1 and n2
set /a n3=n2-n1
:: check whether n1 was less than n2
if %n3% lss 0 (set /a n3*=-1, n1=n2)
:: %random% contains a number between 0 and 32767
:: the modulo (%%) operation calculates the remainder of division %random%/(n3 + 1)
:: the result is a number between 0 and n3, now add n1 to the remainder
set /a rdm=%random% %% (n3 + 1) + n1
echo %rdm%
pause
Regards
aGerman