Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2012 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3807542 to your computer and use it in GitHub Desktop.
Save anonymous/3807542 to your computer and use it in GitHub Desktop.
3 Line dice roller
#!/usr/bin/python
import sys, random, re
m = re.match(r"(\d*)d(\d*)([-+]?\d*)",sys.argv[1])
print sum([random.randint(1,int(m.group(2))) for i in range(int(m.group(1)or"1"))]) + (int(m.group(3) or "0"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment