Last active
December 9, 2016 00:23
-
-
Save KyleJamesWalker/8b49ba8c51aa61846590b27449952efa to your computer and use it in GitHub Desktop.
Generates a random YouTube like Video ID
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
"""Generate a random YouTube like Video ID, supports deterministic generation | |
if seed is passed. | |
""" | |
import random | |
import string | |
import sys | |
YT_SET = (string.ascii_letters + string.digits + "-_") * 2 | |
def get_video(seed=None): | |
if seed: | |
random.seed(seed) | |
# Get a random string of valid characters (max 2 each) | |
return ''.join(random.sample(YT_SET, 11)) | |
def main(): | |
seed = None | |
if len(sys.argv) == 2: | |
seed = sys.argv[1] | |
print(get_video(seed)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment