Here is a more compact representation of your algorithm:
from __future__ import division
from collections import Counter
import random
import string
VOWELS = "aeiou"
CONSONANTS = "".join(set(string.lowercase) - set(VOWELS))
def dealHand(n):
numVowels = n // 3
lettersets = [VOWELS] * numVowels + [CONSONANTS] * (n - numVowels)
return Counter(c
for letterset in lettersets
for c in random.choice(letterset)
)
Seems random enough.
And later: " if I wanted letters to appear no more than twice, how could I achieve that?"
Well, you could do this, but I am not recommending this:
def dealHand2(n):
while True:
candidate = dealHand(n)
if all(v <= 2 for v in candidate.values()):
return candidate
This is an infinite loop until it finds a set of letters that satisfies your condition. Running time: uncertain.