Last active
January 5, 2017 09:57
-
-
Save samisalkosuo/f2a7a3043753f835c8468462d396cd04 to your computer and use it in GitHub Desktop.
Simple function to generate random usernames.
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 sys | |
def generate_username(formatStr,capitalize=True): | |
"""Generate random user name. formatStr is like CVC-CVC which generates username with consonant-vowel-consonant-consonant-vowel-consonant.abs | |
C=consonant | |
V=vowel | |
N=number | |
+=space | |
""" | |
import random | |
import re | |
vowels="eyuioa" | |
consonants="mnbvcxzlkjhgfdsptrwq" | |
numbers="0123456789" | |
def randomVowel(): | |
return random.choice(vowels) | |
def randomConsonant(): | |
return random.choice(consonants) | |
def randomNumber(): | |
return random.choice(numbers) | |
regex = re.compile('[^a-zA-Z+]') | |
formatStr=regex.sub('', formatStr) | |
username=[] | |
for c in formatStr.upper(): | |
if c=="C": | |
username.append(randomConsonant()) | |
if c=="V": | |
username.append(randomVowel()) | |
if c=="+": | |
username.append(" ") | |
if c=="N": | |
username.append(randomNumber()) | |
username="".join(username) | |
if capitalize==True: | |
username= username.capitalize() | |
return username | |
for i in range(int(sys.argv[2])): | |
print(generate_username(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment