Created
October 27, 2011 09:25
-
-
Save madssj/1319151 to your computer and use it in GitHub Desktop.
Get a random name from /usr/share/dict/propernames
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
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