At 01:17 05.01.2003 -0800, juan colon wrote:
You didn't nmention any special requirements (uniqueness of letters, limitations on which letters to use) so this handler might do it:how would you do a letter generator in lingo what are the possible outcomes of using the alphabet and getting different combinations for 10 charactersexample: swercogtvn oiknvgytrc erivnthbpq acvpomewlv
on getAsciSalad lang,aslowerCase
-- create a random string
result = ""
base = 64 + 32 * (aslowercase = TRUE)
repeat with index = 1 to lang
result = result & numToChar(random(26)+base)
end repeat
return result
end
f
from the messWin:
put getAsciSalad(10,1)
-- "wsjomybaxu"
As for the number of possible different strings, you would calculate them as power(number_of_chars,length_of_string). For a random string from 26 different characters and a length of 10 this results in 141,167,095,653,376
What do you need this for? If you want to create unique identifiers, probability won't suffice and you might want to consider storing "used" identifiers in a list or field and test against that when creating a new identifier:
on getUniqueID LpriorIds,dlength
-- create a String that is unique to the List LpriorIds
if NOT integerP(dlength) then dLength = 10
ok = FALSE
repeat while not ok
aString = getAsciSalad(dLength,1)
ok = not(LpriorIds.getPos(aString))
end repeat
LpriorIds.append( aString )
return aString
end
from the message window:
-- Welcome to Director --
dL = []
put getUniqueID(dL,9)
-- "dssyaruit"
put dL
-- ["dssyaruit"]
you would need to store the list LpriorIds as a global or property. Since we test for uniqueness the string can be much shorter
HTH
Daniel Plaenitz
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
