Skip to content

Instantly share code, notes, and snippets.

@super3
Created April 4, 2013 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save super3/5311135 to your computer and use it in GitHub Desktop.
Save super3/5311135 to your computer and use it in GitHub Desktop.
def generate_email(f_name, l_name):
"""Returns a random email."""
common_email_providers = ["hotmail", "msn", "aol", "yahoo", "gmail"]
dictionary = file_to_list('data/dictionary.txt')
dictionary = small_dict(dictionary, 6)
user = ""
for i in range(3):
rand = random.randrange(1, 6)
if rand == 1:
user += f_name
elif rand == 2:
user += l_name
elif rand == 3:
user += random.choice(dictionary)
elif rand == 4:
user += random.choice(string.ascii_lowercase)
else:
user += str(random.randrange(1, 9999))
email = user + "@" + random.choice(common_email_providers) + ".com"
# if too long or starts with number generate again
if len(email) > 30:
return generate_email(f_name, l_name)
elif email[0].isdigit():
return generate_email(f_name, l_name)
else:
return email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment