javascript - Math behind generating random number (Crash game BTC Casino) - Stack Overflow

I'm working on a web based game where we have multiple minigames.We're insisting on also add

I'm working on a web based game where we have multiple minigames. We're insisting on also adding a Crash game, which is pretty popular in the gambling world. However we have been struggling to understand the concept of generating a random (almost unpredictable) number. Most gambling sites provide hashes etc to prove that the numbers are untampered with. We don't really need this because there's no real money involved in our game. So we're only looking for a way to generate a (almost unpredictable) random number (which starts from 1 and goes to infinity) but which gives us a bit of house edge (1/2%).

I'm working on a web based game where we have multiple minigames. We're insisting on also adding a Crash game, which is pretty popular in the gambling world. However we have been struggling to understand the concept of generating a random (almost unpredictable) number. Most gambling sites provide hashes etc to prove that the numbers are untampered with. We don't really need this because there's no real money involved in our game. So we're only looking for a way to generate a (almost unpredictable) random number (which starts from 1 and goes to infinity) but which gives us a bit of house edge (1/2%).

Share Improve this question edited May 25, 2021 at 14:11 sneaker asked May 25, 2021 at 13:51 sneakersneaker 491 gold badge3 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

For a (almost unpredictable) random number, you can use Crypto.getRandomValues() which is safer to use and more random than the default Math.random() method.

For a crash game, if you want that the probability of the crash point to be higher than X should be 1/X, you can use this method:

function getCrashPoint() {
    e = 2**32
    h = crypto.getRandomValues(new Uint32Array(1))[0]
    return Math.floor((100*e-h) / (e-h)) / 100
}

If you want to add 2% for the house edge, just add an if statement:

function getCrashPoint() {
    e = 2**32
    h = crypto.getRandomValues(new Uint32Array(1))[0]
    // if h % (100 / desired_precentage) is 0 then the game will crash immediately 
    if (h % 50 == 0) return 1
    return Math.floor((100*e-h) / (e-h)) / 100
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745142916a4613511.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信