1.

Solve : Problem with random number batch file?

Answer»

Im having problems with a batch file i created to generate a random NUMBER between 2 numbers.
This is what i have:

@echo off
:start
cls
echo Picks a Random Number
echo.
SET start=
set /P start=From:
set end=
set /p end=To:
echo.
set /a number=%random% %%%end% + %start% > nul
echo The Random Number is: %number%
echo.
echo Press any Key to Start Again..
pause > nul
goto start


It works fine most of the time but sometimes with some ranges chosen it generates a number above the RANGE. anyone GOT any ideas?For anyone interested this will produce a random number with a chosen upper and lower limit:

@echo off
echo Picks a Random Number..
echo.
set /p from=From:
set /p to=To:
echo.
set /a diff=%to% - %from% + 1
set /a number=%random% %%%diff% + %from%
echo The Random Number is: %number%



Discussion

No Comment Found