Skip to content

Instantly share code, notes, and snippets.

@jsrn
Last active December 15, 2015 17:59
Show Gist options
  • Save jsrn/5300045 to your computer and use it in GitHub Desktop.
Save jsrn/5300045 to your computer and use it in GitHub Desktop.
A random number generator to be used as a substitute for dice in a tabletop RPG. Given properly formatted input, outputs a series of random numbers, e.g. 4d12 rolls four 12-sided dice.
import random;
print "Usage:";
print "[N]d[M]";
print "where N is the number of dice and M is the size of the die.";
while 1:
try:
a = raw_input("Roll: ");
inp = a.split('d');
if(a == ""):
break;
for i in range(int(inp[0])):
print random.randint(1,int(inp[1]));
except ValueError:
print "Example: 2d10";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment