Solved Number generating batch file?

December 5, 2012 at 15:24:17
Specs: Windows 7

I need a batch file that will generate a specific "random" number.
I dont know how to code this, obviously so Ill make up my own coding language to explain.

:start
x = choose_random(0,00)
y = choose_random(3,5,7,8,10,12)
echo %x%%y%%x%%y%%x%%y%%x%%y%%x%%y%
pause:
goto start

an example output could be: 0080070507005


See More: Number generating batch file?

Report •


#1
December 5, 2012 at 17:23:51

@echo off & setlocal enabledelayedexpansion
set n= 3 5 7 81012
:loop
set /a r1=%random%"%%"6*2
set z=!n:~%r1%,2!
set z=%z: =%
set /a c=%random% "%%" 2
if %c% equ 1 set c=00
echo %c%%z%
:: does it look right?
pause
goto :loop

Report •

#2
December 5, 2012 at 18:01:29

Almost... so close. Instead of it generating like a supposed 007 then having to click enter to generate a new one, Id like it to echo 5 sets. so when I changed your code to: "echo %c%%z%%c%%z%%c%%z%%c%%z%%c%%z%" near the end to make 5 sets, it just displays 007007007007007.
I need it too be more like 05007080305

Report •

#3
December 5, 2012 at 20:06:15
✔ Best Answer

@echo off & setlocal enabledelayedexpansion
set n= 3 5 7 81012
set out=
:loop
set /a r1=%random%"%%"6*2
set z=!n:~%r1%,2!
set z=%z: =%
set /a c=%random% "%%" 2
if %c% equ 1 set c=00
set /a I+=1
if !I! equ 6 (
echo !out!
set out=
set I=0
) else (
set out=!out!%c%%z%*
)
pause
goto :loop
::===== end
the asterisk is just for debugging (since it is hard to tell how many items were actually delivered). Remove it when things look right.

Report •

Related Solutions

#4
December 6, 2012 at 18:14:28

PERFECT! Works like a charm.

Report •


Ask Question