我想进行自定义彩票提取,以激励用户参与在线实验.规则是:
彩票是一个PHP函数,它被调用一次并返回奖品(0,10,50或500).我创建了下面的函数,经过70 000次试验后,统计数据是:
我应该担心这个算法吗?有没有比mt_rand更好的方法来创造良好的机会分配?
function lottery() {
// winnings before extraction
$win=0;
// choose a winning number between 1 and 10
$target=mt_rand(1,10);
// make three independent extractions, each with 1/10 probability
if (mt_rand(1,10) == $target) {
// if first extraction is the winning number -> prize=10
// probability: 1/10
$win=10;
if (mt_rand(1,10) == $target) {
// if second extraction is ALSO the winning number -> prize=50
// probability: 1/10 * 1/10
$win=50;
if (mt_rand(1,10) …
Run Code Online (Sandbox Code Playgroud)