Skip to content

Instantly share code, notes, and snippets.

@eloj
Created July 20, 2021 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eloj/9b8145ad05b5441301b9daa6be7f4f76 to your computer and use it in GitHub Desktop.
Save eloj/9b8145ad05b5441301b9daa6be7f4f76 to your computer and use it in GitHub Desktop.
Roll for D20/D&D 5ed ability scores (python)
#!/usr/bin/env python3
#
# Roll for D20/D&D 5ed ability scores.
# Using procedure in Player's Handbook for D&D 5ed, p13.
# "Roll four 6-sided dice and record the total of the highest three"
#
import random
total = 0
for i in range(6):
rolls = [random.randint(1,6) for _ in range(4)]
score = sum(sorted(rolls)[1:])
total += score
print(f"{i+1}: Rolled {rolls}, ability score is {score}")
print(f"total {total}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment