#!/usr/bin/python
# This code is released in the public domain

import random

# standard consonants
std_consonants = ('b','c','d','f','g','h','j',
                  'k','l','m','n','p','q','r',
                  's','t','v','w','x','z')
# consonants appearing in beginning of syllables
start_consonants = std_consonants + ('th','sh','tr','pr',
                                     'cr','dr',)

end_consonants = std_consonants + ('th','sh','ng','nt','rd',
                                   'll',)
              
# standard vowels
vowels     = ('a','e','i','o','u','y')
# add double vowels and diftongs
vowels += ('ee','oo','ay','ey','oy','ai','ei','oi','ie')
# add 'numerized' vowels (diftongs not included)
vowels += ('0','3','4','00','33')

# numbers, 0 to 9
numbers    = ('0','1','2','3','4',
              '5','6','7','8','9')

# Function to create a syllable up to a maximum length
def make_syllable(max_length):
    syl = ''

    # If there is only room for one character, use a number
    if max_length == 1: 
        syl += random.choice(numbers)
    else:
        while True:	
            # syllable starts with a consonant and a vowel
            syl = "%s%s" % (random.choice(start_consonants),
                            random.choice(vowels))
            # maybe there is a consonant at the end
            if random.choice((True,False)):
                syl += random.choice(end_consonants)
            # maybe the syllable is capitalized
            if random.choice((True,False)):
                syl = syl[0].upper() + syl[1:]
            
            # break if syllable does not exceed max_length 
            if len(syl) <= max_length: break
    return syl

# Function to generate a password of syllables
def generate_password(plength=8):
    generated_password = ''

    # add syllable until length is achieved
    while not len(generated_password) == plength:
        generated_password += make_syllable(plength-len(generated_password))
   
    return generated_password
	
# if called directly
if __name__ == '__main__':
    for i in range(4):
        print(generate_password())

