Skip to content

@jpverkamp /savage-d4.py
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Average value and success chance for d4 + wild in Savage worlds
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.