Created
June 23, 2015 01:20
-
-
Save ereidland/0ce749d9015f0d7cabe8 to your computer and use it in GitHub Desktop.
Rough testing of average stat roll for DnD
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
function Roll(sides) | |
{ | |
return 1 + Math.round(Math.random()*(sides - 1)); | |
} | |
function RollForStat() | |
{ | |
var totals = [Roll(6), Roll(6), Roll(6), Roll(6)]; | |
var lowestIndex = 0; | |
var lowestNumber = totals[0]; | |
for (var i = 1; i < totals.length; i++) | |
{ | |
var currentNumber = totals[i]; | |
if (currentNumber < lowestNumber) | |
lowestIndex = i; | |
} | |
var numberCount = totals.length - 1; | |
var totalNumber = 0; | |
for (var i = 0; i < totals.length; i++) | |
{ | |
if (lowestIndex == i) | |
continue; | |
totalNumber += totals[i]; | |
} | |
return totalNumber; | |
} | |
function TestAverageStat(howManyTimes) | |
{ | |
var totalNumber = 0; | |
for (var i = 0; i < howManyTimes; i++) | |
{ | |
var stat = RollForStat(); | |
totalNumber += stat; | |
} | |
return totalNumber / howManyTimes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment