小范围均匀分布,产生精准大概率 [英] Uniform distribution in a small range to generate precise big probability

查看:54
本文介绍了小范围均匀分布,产生精准大概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用均匀分布来生成获胜概率.

Currently I'm using a uniform distribution to generate a winning probability.

假设概率为 1% 我定义一个中奖号码 47 然后我做一个 mt_rand(1,100) 并且如果号码是 47 用户获胜.哪个没问题.

For a probability of let's say 1% I define a winning number 47 then I do a mt_rand(1,100) and if the number is 47 the user win. Which is fine.

这对于像 1/100'000 这样的小概率来说效果很好,但是当我想要一个概率为 40%1/0.4 = 2.5

This work well for small probability like 1/100'000 but when I want a probability of let's say 40% which is 1/0.4 = 2.5

我不能做 mt_rand(1,2.5) 我必须做 mt_rand(1,2)mt_rand(1,3)分别表示 50%33%.

I cannot make mt_rand(1,2.5) I have to do mt_rand(1,2) or mt_rand(1,3) which mean respectively 50% and 33%.

我该怎么做才能获得 40% 的概率?

How should I do to get a 40% probability?

推荐答案

if (mt_rand(1, 100) / $probability <= 1) {
    // success
}

例如如果你现在有 $probability = 10;您有十个(共一百个)案例,其中 1 到 100 之间的数字小于或等于 1.

E.g. if you have now $probability = 10; you have ten (of hundred) cases where the number between 1 and 100 is smaller or equal to one.

这篇关于小范围均匀分布,产生精准大概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆