Create a list of random strings

December 29, 2011 at 19:03:09
Specs: Windows XP
I'm looking for a batch file to create a list of random alphanumeric strings, to be piped to a text file with each string on a seperate line and also with fixed text in front of each string.

I've come across the following 2 batch files, would it be possible to combine them?

A) creates list of random single characters:

@Echo Off
:: Generates semi-random alphanumeric character, upper/lower case A-z and 0-9
Setlocal EnableDelayedExpansion
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _count=0
:_loop
Set /a _count+=1
SET _RND=%Random%
:: Use (Number of characters-1) as the mod operand. So for just 26 letters use 25 instead of 61
Set /A _RND=_RND%%61
SET _rndalphanum=!_Alphanumeric:~%_RND%,1!
Echo Random character is !_rndalphanum!
If !_count! leq 21 goto _loop

B) creates a single random string of multiple characters:

@Echo Off
Setlocal EnableDelayedExpansion
Set _RNDLength=8
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _Str=%_Alphanumeric%987654321
:_LenLoop
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET _tmp=%_Str:~9,1%
SET /A _Len=_Len+_tmp
Set _count=0
SET _RndAlphaNum=
:_loop
Set /a _count+=1
SET _RND=%Random%
Set /A _RND=_RND%%%_Len%
SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
If !_count! lss %_RNDLength% goto _loop
Echo Random string is !_RndAlphaNum!

I'm looking to create a list something like this:

Random string is OVrzJb
Random string is Y4Ensb
Random string is bRqvFw
Random string is eHyWbH
Random string is l0jjpw
Random string is oqLqBl
Random string is rDTRY6

thanks


See More: Create a list of random strings

Report •

#1
December 30, 2011 at 10:46:18
ah well, I bodged something together...I used the second batch above which I named test.bat and called it from another bat file:

@Echo Off
Setlocal EnableDelayedExpansion
Set _count=0
:_loop
Set /a _count+=1
call test.bat>> output.txt
If !_count! leq 10 goto _loop

I now get the desired output, e.g.

IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=ThPMUY
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=hMAuY6
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=K3CU7v
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=0pkLYZ
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=0NBH1x
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=RP8Lko
IMG.EXE /FILE=C:\SAVED\ABC.IMG /PWD=EyFEMg

but I can't run the above output as a bat file, as img.exe creates files with the same name... LOL...so some more figuring out.


Report •
Related Solutions


Ask Question