Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created August 27, 2021 15:21
Show Gist options
  • Select an option

  • Save marcosan93/42abf2efc9d4325eb05cde7893374db8 to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/42abf2efc9d4325eb05cde7893374db8 to your computer and use it in GitHub Desktop.
def emailGen(name, duplicateFound=False):
"""
Generates a random email address based on the given name.
Adds a number at the end if a duplicate address was found.
"""
# Fake domain name to use
dom = "@fakemail.com"
# Lowercasing and splitting
name = name.lower().split(" ")
# Random character to insert in the name
chars = [".", "_"]
new_name = name[0] + random.choice(chars) + name[1]
# Further distinguishing the email if a duplicate was found
if duplicateFound:
# Random number to insert at the end
num = random.randint(0,100)
# Inserting at the end
new_name = new_name + str(num)
# Returning the email address with the domain name attached
return new_name + dom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment