Using a .bat file, I know how to echo out a random number with %Random%. How do I set a certain random range of the %Random% e.g. 50-100? Oh, and I've got a point system which states at the start: SET /A MAINSCORE=0 How do I set that Random Range number to add / subtract from the MainScore? Thanks.
The %RANDOM% returns a number between 0 and 32767. To narrow these range use modulo operator, and addition or substraction to offset the result. Example:
@set /a bottomlimit = 50
@set /a upperlimit = 100
@set /a result = %bottomlimit% + %RANDOM% %% (%upperlimit% - %bottomlimit% + 1)
@echo %result%
@echo off
set min=5
set max=10
set /a range=max-min +1
set /a rnd=%random% %%%range% +%min%
echo %rnd%
pause
personally i really like my way of doing it
this will go through any # between 5 and 10
and best of all, its clean. thank you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With