I am using it to create unique names for one click file renaming and for download list creation, and I thought that it may interest someone else.
To call the function:
Loop, 2 { name := f_BuildNames("x",5) Loop, 3 msgbox, %name%-%A_Index% } ; "x" may be any letter ("r" for rename "d" for download...), 5 = length of string (not greater than 10) ; this code limits the returned string to 10 chars(max).I think it is much more than enough. ; 5 chars will produce 26*26*26*26*26 unique strings
the function:
f_BuildNames(x,n) { IniRead, v_positions, buildnames.ini, ASCII_values, key%x%%n%, 97|97|97|97|97|97|97|97|97|97 ;there is no problem if file|section|key does not exist StringSplit, p, v_positions, | Loop, %n% { i := Mod(1+n- A_Index,n+1) ; in the first run i = n, second i = n - 1 ...last i = 1 v_name := chr(p%i% - 32 * Mod(p%n% - Mod( A_Index + 1, A_Index),2)) . v_name ;this line builds a string (aaa...a to zzz...z) and toggles lower and ;- upper case (AAAAA aaaab AAAAC aaaad...) ;- inner mod() returns "0" if A_Index = 1 and "1" if A_Index > 1 it is needed because "n" of p%n% will be "n + 1" after the first loop iteration ;- outer mod(expression,2) returns "0" if evaluated expression = even number or "1" if uneven, returned value is used to define if "v_name" will be upper or lowercase ;- so chr(expression) will evaluate for example "97 - 32" retuning "A" or "97 - 0" returning "a" ;v_name := chr(p%i%) . v_name ;uncomment this line and comment|delete the previous if you don't want to switch lower/uppercase If (p%i% < 122 && v_stop != 1) { p%i% ++ ;if char is not yet "z" increase p%i% value v_stop = 1 ; stop checking otherwise all p%i% values will be increased } Else If (p%i% > 121 && v_stop != 1) ;ASCII 122 = lowercase "z" p%i% = 97 ;reset to "a" } IniWrite, %p1%|%p2%|%p3%|%p4%|%p5%|%p6%|%p7%|%p8%|%p9%|%p10%, buildnames.ini, ASCII_values,key%x%%n% ; since this script will run "n" loop iterations I decided to not mount the value for "IniWrite" inside the loop Return, v_name }