public
Last active

Average value and success chance for d4 + wild in Savage worlds

  • Download Gist
savage-d4.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import random
 
# Roll an n-sided die
def d(n):
return random.randint(1, n)
# Roll an n-sided die, exploding on maximum value
def e(n):
total = 0
while True:
roll = d(n)
total += roll
if roll != n:
break
return total
# Roll an exploding n-sided die and an exploding d6, take the better
def w(n):
return max(e(n), e(6))
# Roll 1 million times exploding d4+wild
print 'd4 + wild:'
dice = ([w(4) for i in xrange(1000000)])
print '\tavg:', 1.0 * sum(dice) / len(dice)
print '\tsuc:', 1.0 * len(filter(lambda n : n >= 4, dice)) / len(dice)
 
# Roll 1 million times just exploding d4
print 'd4:'
dice = ([e(4) for i in xrange(1000000)])
print '\tavg:', 1.0 * sum(dice) / len(dice)
print '\tsuc:', 1.0 * len(filter(lambda n : n >= 4, dice)) / len(dice)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.