- Roll a 6 sided die 4 times.
- Remove the lowest dice result.
- Add up the remaining numbers to get an ability score.
- Write down this ability score on note paper.
- Repeat these steps until you have 6 ability scores.
Created
May 31, 2022 23:46
-
-
Save mike-pete/e1ea73d69753c33d0f1b74c20f2b1ea9 to your computer and use it in GitHub Desktop.
D&D Stat Roller
This file contains hidden or 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
const rollD6 = () => Math.ceil(Math.random() * 6) | |
const getOneStat = () => { | |
let sumOfRolls = 0 | |
let smallestRoll = 6 | |
// roll 4 times and add the totals together | |
for (let i=0; i < 4; i++){ | |
const roll = rollD6() | |
sumOfRolls += roll | |
smallestRoll = roll < smallestRoll ? roll : smallestRoll | |
} | |
// drop the smallest roll | |
sumOfRolls -= smallestRoll | |
return sumOfRolls | |
} | |
const getAllStats = () => { | |
let allRolls = [] | |
// roll 6 stats | |
for (let i=0; i<6; i++){ | |
allRolls[i] = getOneStat() | |
} | |
// sort largest to smallest | |
return allRolls.sort((a,b)=>b-a) | |
} | |
console.log(getAllStats()) |
This file contains hidden or 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
import random | |
def oneStat(): | |
sumOfRolls = 0 | |
smallestRoll = 6 | |
# roll 4 times and add the totals together | |
for i in range(4): | |
d6Roll = random.randint(1,6) | |
sumOfRolls += d6Roll | |
if d6Roll < smallestRoll: | |
smallestRoll = d6Roll | |
# drop smallest roll | |
sumOfRolls -= smallestRoll | |
return sumOfRolls | |
def allStats(): | |
allRolls = [] | |
# roll 6 stats | |
for i in range(6): | |
allRolls.append(oneStat()) | |
# sort largest to smallest | |
allRolls.sort(reverse=True) | |
return allRolls | |
print(allStats()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment