Skip to content

Instantly share code, notes, and snippets.

@jchysk
Created April 7, 2015 19:34
Show Gist options
  • Save jchysk/6f82c6490f5f2ee3edcf to your computer and use it in GitHub Desktop.
Save jchysk/6f82c6490f5f2ee3edcf to your computer and use it in GitHub Desktop.
Winner Picker using Blockchain
"""
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