Page 1 of 1

Random number

Posted: 21 Oct 2014 01:49
by darioit
Hello,
I use this variable %random% to get random number, but the result must be always 5 byte

Code: Select all

@echo off
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%
echo %random%


result:
14915
15875
3294 (results must be 03294)
17197
25615
28844
3323 (results must be 03323)
457 (results must be 00457)
21912
21 (resuls must be 00021)

How can I fill zero in result?
Thanks you in advance

Re: Random number

Posted: 21 Oct 2014 03:04
by Yury

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /l %%i in (1 1 100) do (
 set var=0000!random!
 echo !var:~-5!
 )

endlocal
pause>nul
exit /b