LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
p4tr1ck
- Posts: 36
- Joined: Mon Jun 14, 2010 4:58 pm
Post
by p4tr1ck » Tue Aug 17, 2010 8:15 pm
I am making a speakable password generator for school. I can't seem to get this right. Instead of a mixture of vowels and consonants, it simply creates vowels and spaces.
Code: Select all
on mouseUp
local lResult
local i
local lVowels
local lConts
local sType
put 1 into i;
put "" into lResult
put "aeiou" into lVowels
put "bcdfghjklmnprstwyz" into lConts
put 0 into sType
repeat 40 times
local lRandomCharNum
local lRandomChar
if sType is 1 then
put randomInRange(1,5) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
if sType is 0 then
put randomInRange(1,18) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
put lResult && lRandomChar into lResult
if sType is 1 then put 0 into sType;
else put 1 into sType;
put lResult into field "output"
if i is the thumbPos of scrollbar "pLength" then exit repeat;
add 1 to i
end repeat
end mouseUp
Thanks for your help.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Aug 17, 2010 9:32 pm
patrick
I changed some of your code. The main problem was that you used lVowels twice instead of lConts and lVowels. In Rev if you append with double ampersand (&&) you effectively insert a space.
I commented the other changes I made, have a look.
Code: Select all
on mouseUp
local lResult
local i
local lVowels
local lConts
local sType
put 1 into i;
put "" into lResult
put "aeiou" into lVowels
put "bcdfghjklmnprstwyz" into lConts
put 0 into sType
put the thumbPos of scrollbar "pLength" into tLengthPassword -- changed this
repeat tLengthPassword -- changed this
local lRandomCharNum
local lRandomChar
if sType is 1 then
put randomInRange(1,5) into lRandomCharNum
put char lRandomCharNum of lVowels into lRandomChar
end if
if sType is 0 then
put randomInRange(1,18) into lRandomCharNum
put char lRandomCharNum of lConts into lRandomChar -- changed this, was lVowels
end if
put lRandomChar after lResult -- changed this
if sType is 1 then put 0 into sType;
else put 1 into sType;
-- put lResult into field "output" -- blocked this, it moved out ot the repeat loop
-- if i is the thumbPos of scrollbar "pLength" then exit repeat; -- blocked this
-- add 1 to i --blocked this
end repeat
put lResult into field "output"
end mouseUp
function randomInRange lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
it works in my limited testing.
For a random vowel or consonant in your list you could just as well say: put any char of lVowels after lResult, for consonants likewise. Look up "any"
regards
Bernd
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Aug 17, 2010 10:29 pm
patrick,
just to make the code a bit shorter here is a version that does what you want
Code: Select all
on mouseUp
put the thumbPosition of scrollbar "pLength" into tPasswordLength
put "bcdfghjklmnprstwyz" into lConts
put "aeiou" into lVowels
put "" into tResult
repeat tPasswordLength
if tResult = "" or last char of tResult is in lVowels then
put any char of lConts after tResult
else
put any char of lVowels after tResult
end if
end repeat
put tResult into field "output"
end mouseUp
regards
Bernd
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sat Aug 21, 2010 12:39 pm
Hi,
Here's a function that allows for double consonants while the password is still speakable.
Code: Select all
function speakablePassword theLength
put "bcdfghjklmnprstwyz" into myConsonants
put "aeiou" into myVowels
put "" into myPass
repeat theLength
if char -1 of myPass is in myConsonants then
if char -2 of myPass is in myConsonants or \
length(myPass) = 9 then
put any char of myVowels after myPass
else
if any item of "true,false" then
put any char of myVowels after myPass
else
put any char of myConsonants after myPass
end if
end if
else
put any char of myConsonants after myPass
end if
end repeat
return myPass
end speakablePassword
Enjoy,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sat Sep 04, 2010 9:06 am
Here's a stack, which generates even slightly better speakable passwords.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode