Skip to content

Instantly share code, notes, and snippets.

@april
Created April 7, 2017 20:08
Show Gist options
  • Save april/be09a9c1d27e50972034d8121bab176c to your computer and use it in GitHub Desktop.
Save april/be09a9c1d27e50972034d8121bab176c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from random import randint
dice = 2 # two dice
die = 20 # d20
rolls = 10000000 # roll this many times
f = min # low roll == min, high roll == max
rolled = sum = 0
while rolled < rolls:
rolled += 1
sum += f((randint(1, die) for _ in range(dice)))
print("Average roll: ", sum / rolled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment