Created
May 25, 2014 22:51
-
-
Save leegould/7ec855879f46d70ffddb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
minLen = 3 | |
maxLen = 8 | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
consonantExclude = ['q'] | |
consonants = [a for a in string.ascii_lowercase if a not in vowels and a not in consonantExclude] | |
charpairs = ['qu', 'th', 'ch'] | |
patternWeighting = [(vowels, 0.3), (consonants, 0.6), (charpairs, 0.1)] | |
letterType = consonants | |
def randomWeighted(items): | |
n = random.uniform(0,1) | |
for item, weight in items: | |
if n < weight: | |
break; | |
n = n - weight | |
return item | |
def randomEntry(arr): | |
return arr[random.randrange(0, len(arr))] | |
def randomChar(): | |
return randomEntry(randomWeighted(patternWeighting)) | |
def randomName(): | |
str = '' | |
for i in xrange(random.randrange(minLen, maxLen)): | |
str += randomChar() | |
return str | |
print randomName() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment