Skip to content

Instantly share code, notes, and snippets.

@hotyes
Last active August 30, 2024 10:10
Show Gist options
  • Save hotyes/de65844a4816994983e7fa08961809a6 to your computer and use it in GitHub Desktop.
Save hotyes/de65844a4816994983e7fa08961809a6 to your computer and use it in GitHub Desktop.
dice
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