Skip to content

Instantly share code, notes, and snippets.

@madssj
Created October 27, 2011 09:25
Show Gist options
  • Save madssj/1319151 to your computer and use it in GitHub Desktop.
Save madssj/1319151 to your computer and use it in GitHub Desktop.
Get a random name from /usr/share/dict/propernames
def get_random_name():
"""
Return a random proper name in a somewhat efficient way.
"""
fp = open("/usr/share/dict/propernames")
fp.seek(0, 2)
size = fp.tell()
fp.seek(0)
fp.seek(int(random.random() * size * 0.95))
fp.readline() # throw away first line
return fp.readline().capitalize().strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment