I'm making a random number generator with batch files, and sometimes it errors and says "00", and freezes. the seed for the number is the current millisecond. any ideas to help?
I've tried using IF statements to check is the seed/number is above a certain value, as you cane see in the :calc and :calc2 sections of the code, but is still errors after 5 of 6 numbers are generated. heres the code:
@echo off
:seed
set seed=%time%
set result=%seed:~9,10%
echo seed:%result%
goto calc
:calc
echo generating...
set /a "num=%result%*%result%"
if %num% lss 1000 goto seed
set num=%num:~2,3%
cls
goto say
:say
cls
echo your number is %num%
echo press a key for another number
pause >nul
goto calc2
:calc2
cls
echo generating...
set /a "num=%num%*%num%"
if %num% lss 1000 set /a "num=%num%*2"&&goto calc2
set num=%num:~2,3%
goto say
I also want all the outputted numbers to be 2 digits long, but some of them are three digits long.
Aucun commentaire:
Enregistrer un commentaire