Skip to content

Instantly share code, notes, and snippets.

@sbp
Created August 26, 2012 10:00
Show Gist options
  • Save sbp/3476758 to your computer and use it in GitHub Desktop.
Save sbp/3476758 to your computer and use it in GitHub Desktop.
Use random.org to select an item
# Derived from http://pastebin.com/10egeE1a
# Original Copyright 2012, Paul
# License: Eiffel Forum License 2
import re, urllib
def randomorg(max):
svcurl = "http://www.random.org/integers/?num=1&min=1&max=%d&col=1&base=10&format=plain&rnd=new" % max
u = urllib.urlopen(svcurl)
content = u.read()
u.close()
return int(content)
def selector(istr):
terms = re.findall('\[[^\]]*\]|\"[^\"]*\"|\S+', istr)
tlen = len(terms)
if tlen < 2:
print "Please provide at least 2 terms."
try: result = randomorg(tlen)
except IOError:
print "Service error."
print "I choose: " + terms[result - 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment