Created
August 19, 2014 01:49
-
-
Save asciipip/7e8e2d43554f971d4b1e to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python | |
import random | |
import string | |
UNAMBIGUOUS_LETTERS = list(set(string.ascii_lowercase) - set('ilou')) | |
def randid_worker(params): | |
"""PARAMS is a collection of (SET, COUNT) pairs. The function returns | |
a collection of COUNT_0 + COUNT_1 + ... COUNT_n items, drawn from the | |
respective SETs.""" | |
result = [] | |
for (s, c) in params: | |
result.extend([ random.choice(s) for i in xrange(c) ]) | |
random.shuffle(result) | |
return result | |
def randid(): | |
"""Creates a random ID space with three modified | |
base32 characters and one number in random order for | |
example vnt5, z2aa, tb9h or 2qxd""" | |
return ''.join(randid_worker([(UNAMBIGUOUS_LETTERS, 3), (string.digits, 1)])) | |
if __name__ == '__main__': | |
# Prints ten examples of the same | |
for n in xrange(10): | |
print randid() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment