Last active
August 30, 2024 10:10
-
-
Save hotyes/de65844a4816994983e7fa08961809a6 to your computer and use it in GitHub Desktop.
dice
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 random(min, max) { // min and max included | |
return Math.random() * (max - min + 1) + min; | |
} | |
const bet = 1 | |
const rtp = 0.99 | |
const max = 100 | |
function roll(threshold, under) { | |
const dice = random(0, max) | |
const win = under ? dice < threshold : dice >= threshold | |
const chance = under ? threshold / max : 1 - (threshold / max) | |
const mul = rtp / chance | |
const winAmount = win ? mul * bet : 0 | |
return { | |
threshold, | |
dice, | |
win, | |
chance, | |
mul, | |
winAmount | |
} | |
} | |
console.log(roll(2, false)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment