Skip to content

Instantly share code, notes, and snippets.

@StephanWagner
Last active September 21, 2022 16:49
Show Gist options
  • Save StephanWagner/0e5f1173749365df9cf996d3ab82a99e to your computer and use it in GitHub Desktop.
Save StephanWagner/0e5f1173749365df9cf996d3ab82a99e to your computer and use it in GitHub Desktop.
Probability functions for dropchance calculations
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