Code:
:_mixture
For %%J In (%number%) Do (
echo %%J
set /a _P=!random!%%55
set _str=!str:~%_P%,1!
set /a _pw=%%J
set /a _pw=%_pw:~0,1%
echo %_pw%%_str%
set _str=!str:~%_P%,1!
this line won't work the way you expect. It will
not use the value of _P set in the previous line. It will use the value of _P that was set in line 7.
To work, you would need this:
set _str=!_str:~!_P!,1!
But that doesn't work, same reason you can't use all percent signs. And
set _str=%_str:~!_P!,1% doesn't work either.
But luckily,
Call set _str=%%_string:~!_P!,1%% will work (I redefined the string to use _string).
It also has a typo; you have
!str instead of
!_str. Same typo in line 8
You also have to remember that you redefined
_str in the RandomLetter section. When you get to the For loop,
_str is a single character. So unless your random number (_P) is 0, you will not get any output.
You'll need to use a different variable for the extracted letter, so you don't modify the original string. Though I'm guessing that may be what you intended by using
_str and
str;
_str for the single extracted letter, and
str for the full string. If you change the string definition on line 5 to be str=AaBb etc, then line 8 and 37 should work.
All of the lines that are in the For loop must use ! instead of %
So give this a try (some of the changes in red):
Code:
::@echo off
@echo on
:_RandomLetter
set _string=AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz.-_
setLocal EnableDelayedExpansion
set /a _P=random%%55
set _str=!_string:~%_P%,1!
set number=0
If %number% LSS 1234 Call :_RandomNumber
Goto _End
:_RandomNumber
:_setmax
set max=%random%
if %max% LSS 8000 GOTO _setmax
:_setmaxrand
set maxrand=%random%
if %maxrand% LSS 10000 GOTO _setmaxrand
set /a min=random%%7999
set /a range=max-min
set /a minrand=random%%9999
set /a rangerand=maxrand-minrand
set /a rand=random%%3
set /a number=(((random - minrand) * range) / ((rangerand + min) ^^ rand))
if %number% LSS 1234 Call :_RandomNumber
GOTO :EOF
:_End
:_mixture
For %%J In (%number%) Do (
echo %%J
set /a _P=!random!%%55
Call set _str=%%_string:~!_P!,1%%
set /a _pw=%%J
set _pw=!_pw:~0,1!
echo !_pw!!_str!
)
EndLocal
pause
Though there really is no reason to use a For loop for this. %%J will equal %number%. It will only execute one time. These three lines will do the same as the For loop will.
Code:
set /a _P=!random!%%55
set _str=!_string:~%_P%,1!
set _pw=%number:~0,1%
I wrote the following a while back in another thread. They wanted something to generate a series of random passwords with a specified length. This uses just alphanumeric characters, plus % and ^.
Other punctuation should work as long as it's not a special character.
If you want a quote, it should be the first character in the string. An exclamation point won't work though. I doubt if &, |, >, or < would work either.
Code:
@Echo Off
Setlocal EnableDelayedExpansion
Set _HowMany=25
Set _RNDLength=8
Set _Alphanumeric="A%%^^BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
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 _Test1=0
:_test
Set /A _test1+=1
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!
If %_Test1% lss %_HowMany% Goto _test
Jerry