Random String Generator .BAT

Call this batch file with the following parameters to view the help on this
command, then learn the parameters and apply the appropriate switches:

call rand.bat help


@echo off
rem ============================================
rem Open Source, make this better if you can.
rem Original Code by Jakash3
rem .
rem THIS BATCH FILE IS MEANT TO BE CALLED WITH
rem PARAMETERS FROM ANOTHER BATCH FILE OR CMD.EXE
rem ============================================
rem
rem =================
rem Declare Arguments
rem =================
set len=%1
set case=%2
set data=%3
set randomvar=%4
if %len%==help goto help
rem ==========================
rem This variable counts loops
set start=0
rem ==========================
:console
if %start%==%endloop% goto finish
goto return1
:return1
if %len%==? (
set rlen=%random%
goto Random_Len
)
if not %len%==? set endloop=%len%
goto return2
:return2
if %case%==? (
set rcase=%random%
goto Random_Casing
)
if %case%==lower set casing=lower
if %case%==upper set casing=upper
goto return3
:return3
if %data%==? (
set rdata=%random%
goto Random_Data
)
goto return4
rem =============================
rem Main Loop
rem =============================
:return4
set index=%random%/2
set /a char=%random%/1260
set /a int=%random%/3073
set /a start=%start%+1
if %char% LEQ 0 goto return4
if not %data%==? (
if %data%==char goto %char%
if %data%==int goto Add_Integer
)
if %index% LEQ 16383 (
goto Add_Integer
)
if %index% GTR 16383 (
goto %char%
)
rem =============================
:finish
set %randomvar%=%output%
goto End_Command
rem ################################################
rem Functions
rem ################################################
rem .
rem .
rem =======================================
rem Random Boolean: Upper_Case/Lower_Case
rem =======================================
:Random_Casing
if %rcase% GEQ 16383 (
set casing=lower
)
if %rcase% LSS 16383 (
set casing=upper
)
goto return3
rem =======================================
rem Random Boolean: Integer/String
rem =======================================
:Random_Data
if %rdata% GEQ 16383 (
set data=string
)
if %rdata% LSS 16383 (
set data=integer
)
goto return4
rem =======================================
rem Random Length of Output
rem =======================================
:Random_Len
set endloop=%random%
goto return2
rem ======================================
rem Integer
rem ======================================
:Add_Integer
if not defined output set output=%int%
if defined output set output=%output%%int%
goto console
rem ======================================
rem Convert Integers to Strings Section
rem ======================================
:1
if %casing%==lower (
if not defined output set output=a
if defined output set output=%output%a
)
if %casing%==upper (
if not defined output set output=A
if defined output set output=%output%A
)
goto console
:2
if %casing%==lower (
if not defined output set output=b
if defined output set output=%output%b
)
if %casing%==upper (
if not defined output set output=B
if defined output set output=%output%B
)
goto console
:3
if %casing%==lower (
if not defined output set output=c
if defined output set output=%output%c
)
if %casing%==upper (
if not defined output set output=C
if defined output set output=%output%c
)
goto console
:4
if %casing%==lower (
if not defined output set output=d
if defined output set output=%output%d
)
if %casing%==upper (
if not defined output set output=D
if defined output set output=%output%D
)
goto console
:5
if %casing%==lower (
if not defined output set output=e
if defined output set output=%output%e
)
if %casing%==upper (
if not defined output set output=E
if defined output set output=%output%E
)
goto console
:6
if %casing%==lower (
if not defined output set output=f
if defined output set output=%output%f
)
if %casing%==upper (
if not defined output set output=F
if defined output set output=%output%F
)
goto console
:7
if %casing%==lower (
if not defined output set output=g
if defined output set output=%output%g
)
if %casing%==upper (
if not defined output set output=G
if defined output set output=%output%G
)
goto console
:8
if %casing%==lower (
if not defined output set output=h
if defined output set output=%output%h
)
if %casing%==upper (
if not defined output set output=H
if defined output set output=%output%H
)
goto console
:9
if %casing%==lower (
if not defined output set output=i
if defined output set output=%output%i
)
if %casing%==upper (
if not defined output set output=I
if defined output set output=%output%I
)
goto console
:10
if %casing%==lower (
if not defined output set output=j
if defined output set output=%output%j
)
if %casing%==upper (
if not defined output set output=J
if defined output set output=%output%J
)
goto console
:11
if %casing%==lower (
if not defined output set output=k
if defined output set output=%output%k
)
if %casing%==upper (
if not defined output set output=K
if defined output set output=%output%K
)
goto console
:12
if %casing%==lower (
if not defined output set output=l
if defined output set output=%output%l
)
if %casing%==upper (
if not defined output set output=L
if defined output set output=%output%L
)
goto console
:13
if %casing%==lower (
if not defined output set output=m
if defined output set output=%output%m
)
if %casing%==upper (
if not defined output set output=M
if defined output set output=%output%M
)
goto console
:14
if %casing%==lower (
if not defined output set output=n
if defined output set output=%output%n
)
if %casing%==upper (
if not defined output set output=N
if defined output set output=%output%N
)
goto console
:15
if %casing%==lower (
if not defined output set output=o
if defined output set output=%output%o
)
if %casing%==upper (
if not defined output set output=O
if defined output set output=%output%O
)
goto console
:16
if %casing%==lower (
if not defined output set output=p
if defined output set output=%output%p
)
if %casing%==upper (
if not defined output set output=P
if defined output set output=%output%P
)
goto console
:17
if %casing%==lower (
if not defined output set output=q
if defined output set output=%output%q
)
if %casing%==upper (
if not defined output set output=Q
if defined output set output=%output%Q
)
goto console
:18
if %casing%==lower (
if not defined output set output=r
if defined output set output=%output%r
)
if %casing%==upper (
if not defined output set output=R
if defined output set output=%output%R
)
goto console
:19
if %casing%==lower (
if not defined output set output=s
if defined output set output=%output%s
)
if %casing%==upper (
if not defined output set output=S
if defined output set output=%output%S
)
goto console
:20
if %casing%==lower (
if not defined output set output=t
if defined output set output=%output%t
)
if %casing%==upper (
if not defined output set output=T
if defined output set output=%output%T
)
goto console
:21
if %casing%==lower (
if not defined output set output=u
if defined output set output=%output%u
)
if %casing%==upper (
if not defined output set output=U
if defined output set output=%output%U
)
goto console
:22
if %casing%==lower (
if not defined output set output=v
if defined output set output=%output%v
)
if %casing%==upper (
if not defined output set output=V
if defined output set output=%output%V
)
goto console
:23
if %casing%==lower (
if not defined output set output=w
if defined output set output=%output%w
)
if %casing%==upper (
if not defined output set output=W
if defined output set output=%output%W
)
goto console
:24
if %casing%==lower (
if not defined output set output=x
if defined output set output=%output%x
)
if %casing%==upper (
if not defined output set output=X
if defined output set output=%output%X
)
goto console
:25
if %casing%==lower (
if not defined output set output=y
if defined output set output=%output%y
)
if %casing%==upper (
if not defined output set output=Y
if defined output set output=%output%Y
)
goto console
:26
if %casing%==lower (
if not defined output set output=z
if defined output set output=%output%z
)
if %casing%==upper (
if not defined output set output=Z
if defined output set output=%output%Z
)
goto console
:help
echo.
echo RAND Key Generator by Jakash3
echo =============================
echo.
echo Usage: rand [Length] [upper/lower/?] [char/int/?] [X]
echo.
echo Description: Creates a variable containing random data.
echo.
echo Parameters:
echo.
echo Length The number characters in the data.
echo upper Upper casing for string characters.
echo lower Lower casing for string characters.
echo char Generated data type to be letters.
echo int Generated data type to be numbers.
echo x Store output data to specified variable.
echo ? Random Switch
echo.
echo http://www.youtube.com/user/jakash3
echo.
goto End_Command
:End_Command
set output=

One thought on “Random String Generator .BAT

  1. Not same functionality but a lot less code.

    @echo off
    SetLocal EnableDelayedExpansion
    set len=%1
    set alphanum=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456798
    :getChar
    set /a index=%random%*60/32767
    set out=%out%!alphanum:~%index%,1!
    set /a len-=1
    if %len% GTR 0 GOTO getChar
    echo %out%

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s