Random number

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Random number

#1 Post by darioit » 21 Oct 2014 01:49

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

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: Random number

#2 Post by Yury » 21 Oct 2014 03:04

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

Post Reply