Created
April 7, 2015 19:34
-
-
Save jchysk/6f82c6490f5f2ee3edcf to your computer and use it in GitHub Desktop.
Winner Picker using Blockchain
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
""" | |
Pick a random winner | |
""" | |
if __name__ == '__main__': | |
import sys | |
entries = sys.argv[1] | |
import requests | |
# Grab the latest hash | |
latest_hash = requests.get("https://blockchain.info/q/latesthash") | |
# Convert from hex to decimal | |
latest_hash = int(latest_hash.text, 16) | |
# Modulo the number of entries and add 1 to find the winning row | |
winner = latest_hash % int(entries) + 1 | |
print "The winner is " + str(winner) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment