Last active
September 21, 2022 16:49
-
-
Save StephanWagner/0e5f1173749365df9cf996d3ab82a99e to your computer and use it in GitHub Desktop.
Probability functions for dropchance calculations
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 parseProbability(probability) { | |
return Math.min(100, Math.max(0, parseFloat(probability) || 0)); | |
} | |
function probabilityToPercent(nr) { | |
return toFixed(nr * 100) + "%"; | |
} | |
function probabilityByRuns(probability, runs) { | |
return 1 - Math.pow(1 - probability, runs); | |
} | |
function dropchanceByRuns(probability, runs) { | |
probability = parseProbability(probability); | |
runs = Math.max(0, parseInt(runs) || 0); | |
return probabilityToPercent(probabilityByRuns(probability / 100, runs)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment