Skip to content

Instantly share code, notes, and snippets.

@andytwoods
Last active November 17, 2022 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andytwoods/81be395fd4a44366e7fc6d9d9c77f675 to your computer and use it in GitHub Desktop.
Save andytwoods/81be395fd4a44366e7fc6d9d9c77f675 to your computer and use it in GitHub Desktop.
dnd advantage vs regular vs disadvantage
import random
from collections import Counter
simulations = 1000000
def dice_roll():
return random.randint(1, 20)
def show_outcome(nam, counter):
total = 0
for key, val in counter.items():
total += key * val
print(nam, round(total / simulations, 2))
def do_run():
adv_counter = Counter()
reg_counter = Counter()
dis_counter = Counter()
for sim in range(simulations):
outcome = dice_roll()
outcome2 = dice_roll()
adv_counter.update([max(outcome, outcome2), ])
reg_counter.update([outcome])
dis_counter.update([min(outcome, outcome2), ])
show_outcome('advantage ', adv_counter)
show_outcome('regular ', reg_counter)
show_outcome('disadvantage', dis_counter)
do_run()
# advantage 13.82
# regular 10.51
# disadvantage 7.18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment