def random_word(length,dictionary = False):
if dictionary:<EOL><INDENT>try:<EOL><INDENT>with open('<STR_LIT>') as fp:<EOL><INDENT>words = [word.lower()[:-<NUM_LIT:1>] for word in fp.readlines() if re.match('<STR_LIT>'.format('<STR_LIT:{>'+str(length)+'<STR_LIT:}>'),word)]<EOL><DEDENT>return random.choice(words)<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>vowels = list('<STR_LIT>')<EOL>consonants = list('<STR_LIT>')<EOL>pairs = [(random.choice(consonants),random.choice(vowels)) for _ in range(length//<NUM_LIT:2>+<NUM_LIT:1>)] <EOL>return '<STR_LIT>'.join([l for p in pairs for l in p])[:length]<EOL>
Creates random lowercase words from dictionary or by alternating vowels and consonants

The second method chooses from 85**length words.
The dictionary method chooses from 3000--12000 words for 3<=length<=12
(though this of course depends on the available dictionary)

:param length: word length
:param dictionary: Try reading from dictionary, else fall back to artificial words