I recently made a function to generate a random string, and i know this has been done before.
This function will enable you to have "options" for example.
SC_RandomString("M10 D3 U L ") " M10 " is the maximum numbers there will be and "N3 U L" is the options. D = Number ( digit ) , U = Upper case and L = Lower case. If you put a number next to it, there will be ( in this example ) a minimum of 3 numbers, and the other 7 digits will be completely random while still following the options ( Number , Upper case, and lower case).
MsgBox, % SC_RandomString(" M10 U4 L ")
this will generate a random string without numbers because i did not put N in the options, so there will be 4 upper case and the rest will be random between upper case and lower case and no numbers
Alright i think that is enough of the examples.
;------------------------------------ SC_RandomString ---------------------------------- ; This will generate a random string according to options ; U = Upper case ; L = Lower case ; D = Digit ( number ) ; M = Maximum numbers ; ; Specify one of these letters and then ( optional ) have a number after it ; That will be the Minimum number of that type of character ; The rest of the characters will be random ( while still fitting the options ) ; ; This will return 1 if the Max ( M10 ) is samller than all the other options that add up ; ; Example ;----------- MsgBox,% SC_RandomString(" M10 U L2 D5") ; This will have a Minimum of 2 lower case and 5 Digits, everything else will be a random between U L and D ;--------------------------------------------------------------------------------------------- SC_RandomString( Options ) { Div := 0, Total := 0 If not RegExMatch( Options, "(M|m)(\d+)", _) Return 1 If RegExMatch( Options, "(U|u)(\d?)", __) Div++, U := 1 If RegExMatch( Options, "(L|l)(\d?)", ___) Div++, L := 1 If RegExMatch( Options, "(D|d)(\d?)", ____) Div++, D := 1 Max := _2, Un := __2, Ln := ___2, Dn := ____2, Un := Un > 0 ? Un : 1, Ln := Ln > 0 ? Ln : 1, Dn := Dn > 0 ? Dn : 1, Total := ( Un + LN + Dn ) , Un := U < 0 ? 0 : Un, Ln := L < 0 ? 0 : Ln, Dn := D < 0 ? 0 : Dn If ( Un + LN + Dn ) > Max Return 2 SC_Loop: Loop, %Total% { Random, Ran, 65, 90 Out .= Un > 0 ? ( Chr(Ran) , Un-- ) : "" If StrLen( Out ) = Max Goto, End Random, Ran, 97, 122 Out .= Ln > 0 ? ( Chr(Ran), Ln-- ) : "" If StrLen( Out ) = Max Goto, End Random, Ran, 0,9 Out .= Dn > 0 ? ( Ran, Dn-- ) : "" If StrLen( Out ) = Max Goto, End } If StrLen( Out ) < Max { Un+= U > 0 ? 1 : 0,Ln+= L > 0 ? 1 : 0,Dn+= D > 0 ? 1 : 0 Goto, SC_Loop } End: Loop, Parse, Out, { gOut .= A_LoopField "," Sort, gOut, Random D`, } Loop, Parse, gOut, `, { If A_LoopField = %Last% Return SC_RandomString( Options ) Last := A_LoopField } StringReplace, Out, gOut, `,,,All Return Out } ;--------------------------------- End of function --------------------------------