Last active
July 6, 2016 01:18
-
-
Save r14c/e487ed22b57984c61d14 to your computer and use it in GitHub Desktop.
Coinflip!
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/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Takes an arbitrary number of command line arguments and randomly selects one | |
to return. The amount of entropy involved can be adjusted by setting the | |
environment variable ```RANDBYTES```, which defaults to 4096. | |
""" | |
from __future__ import print_function | |
import os | |
import sys | |
import random | |
RANDBYTES = int(os.environ.get('RANDBYTES', 4096)) | |
def coinflip(*args): | |
random.seed(os.urandom(RANDBYTES)) | |
return random.choice(list(args)) | |
if __name__ == '__main__': | |
try: | |
print(coinflip(*sys.argv[1:])) | |
except IndexError: | |
print("coinflip: usage: coinflip OPTIONS...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment