简体   繁体   English

数学和JavaScript | 随机机会

[英]Math & JavaScript | Random chances

I'm trying to figure the math behind a pretty known site called bustabit . 我试图弄清楚一个叫做bustabit的知名网站背后的数学原理

I can't seem to find the right math behind it since whenever I'm trying the things I come up with the odds seem to always be way different. 我似乎无法在其背后找到正确的数学方法,因为每当我尝试尝试要解决的问题时,似乎总是会有很大的不同。 According to the site you can find the odds here, calc . 根据站点,您可以在此处找到calc

Okay, so basically I'm trying to generate a random number that can go up to unlimited with chances attached to them, if we remove all edged the chance of the number being 200 should be about fifty percent, 300 thirtythree, and 500 about twenty percent. 好吧,所以基本上我正在尝试生成一个随机数,该随机数可以附加到它们的机会上达到无限,如果我们删除所有边缘,则该数字为200的机会应为百分之五十左右,300的百分之三十三,而500应该为二十左右百分。

What I figured out to replicate the system, which in my opinion doesn't really fit the odds. 我想出的办法可以复制该系统,我认为这确实不太适合。

var mainMultiplier = 99;

var numerator = 100;
var denominator = 101;      

var chance = 1;

for(;;){
    var randomInt = random.real(0, 1.0); 

  if(numerator/denominator > randomInt){
    numerator = numerator+1;
    denominator = denominator+1;
    mainMultiplier = mainMultiplier+1;
    chance = chance*(numerator/denominator);
  }else{
    break;
  }
}

Is there a way of doing this in a better way? 有没有更好的方法可以做到这一点?

You can figure out the odds in the calculator that I'm trying to replicate. 您可以在我要复制的计算器中找出几率。

It sounds like you just want: 听起来您只想要:

var number = 100.0 / (1 - Math.random());

Generating a million samples like this just now, the relative distribution went like this: 刚刚生成了百万个这样的样本,相对分布如下:

100 - 199 : 499817
200 - 299 : 166405
300 - 399 :  83643
400 - 499 :  50002
500 - 599 :  33155
600 - 699 :  23717
700 - 799 :  18030
800 - 899 :  13811
900 - 999 :  11140

generated thus: 因此产生:

// make array
var a = [];
for (i = 0; i < 1e6; ++i) {
    a.push(100.0 / (1 - Math.random()));
}

// count the distribution
var dist = a.reduce((p, n) => {
    n = 100 * Math.floor(n / 100);
    p[n] = ++p[n] || 1;
    return p;
}, {});

Note that numbers below 100 are not generated - deducting 100 from the value (and perhaps adjusting the 100 in the initial dividend) would resolve that. 请注意,不会生成低于100的数字-从值中减去100(并可能在初始股息中调整100)将解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM