Last active
October 20, 2021 18:36
-
-
Save jantoniomartin/392790af14144a5341570720cbe95e83 to your computer and use it in GitHub Desktop.
A simple simulation of TOR council math
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import random | |
def roll(dice, tn): | |
successes = 0 | |
result = feat = random.randint(0, 11) | |
for i in range(0, dice): | |
r = random.randint(1, 6) | |
result += r | |
if r == 6: | |
successes += 1 | |
if feat == 11 or result >= tn: | |
successes += 1 | |
else: | |
successes = 0 | |
return successes | |
def council(dice, tn, res, rolls): | |
successes = 0 | |
for i in range(0, rolls): | |
successes += roll(dice, tn) | |
return successes >= res | |
def simulation(iterations, dice, tn, res, rolls): | |
""" | |
Parameters: | |
iterations for the simulation. | |
dice: number of d6 in the skill | |
tn: target number of the rolls | |
res: resistance of the council | |
rolls: number of rolls (usually the same as res or a 1-3 more) | |
""" | |
ok = 0 | |
for i in range(0, iterations): | |
if council(dice, tn, res, rolls): | |
ok += 1 | |
r = ok * 100. / iterations | |
print(f"Success rate is {r}%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment