There is a discussion here that you could adapt for your purposes.
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET /A _Len=_Len+_tmp
Set /a _count+=1
Set /A _RND=_RND%%%_Len%
If !_count! lss %_RNDLength% goto _loop
Echo Random string is !_RndAlphaNum!
TheOutcaste expains the above:
I've modified it so you can easily specify the length, and add or
remove characters without having to change any other part of the code.
For example, you might not want to use both 0 and O (zero and
Uppercase O), or 1 and l (one and lowercase L).
You can use punctuation except for these characters:
! % ^ & < >
You can use
%, but must enter them in the
variable twice as ^^ or
%%. However, if you want to use the result
_RndAlphaNum) later in the batch file (other than Echoing to the
screen), they might require special handling.
You can even use a space, as long as it's not the last character in
the string. If it ends up as the last character in the generated
string though, it will not be used, so you would only have 7