how can i make a script that will generate random letters and numbers in a number i decide? example generate X#X#X#X#X# for a password (just an example, i know that there are password generators :))
any ideas?
on randomString(aLength)
set randomChars to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set aString to ""
repeat aLength times
set aString to aString & some item of randomChars
end repeat
return aString
end randomString
-- Example
randomString(8)
thank you. So lets se if i learnt something today
aLength is a variable, set to the number of times the aString variable (which is set to one item of the randomChars list) will appear.
Then the return command, makes the random chars appear. is this correct?
Yep, that’s about it! I love the “some item” command, it’s a simple way to select something randomly from a list without having to generate random numbers.