- 我在尝试打造一个raffle系统**
- 可能的总数为60,000
- 我卖了一万张票
- 我必须使用50,000张未使用的彩票......因此每张彩票都有额外的"机会"赢取。50,000张未售出彩票除以10,000张售出彩票
- 每张门票可获得5次额外机会。
知道了这一点,我需要的是这样的东西:
- 票证:机会1、机会2、机会3、机会4、机会5**
00001: ["20000","20001","40000","40001","60000"]
00002: ["19999","20002","39999","40002","59999"]
00003: ["19998","20003","39998","40003","59998"]
00004: ["19997","20004","39997","40004","59997"]
00005: ["19996","20005","39996","40005","59996"]
.
.
.
09995: ["10006","29995","30006","49995","50006"]
09996: ["10005","29996","30005","49996","50005"]
09997: ["10004","29997","30004","49997","50004"]
09998: ["10003","29998","30003","49998","50003"]
09999: ["10002","29999","30002","49999","50002"]
10000: ["10001","30000","30001","50000","50001"]
因为我不能用已经卖出的一万张票。
第一列从20,000开始,下降到10,001;第二列从20,001开始,结束于30,000,依此类推。
我已经有了这个代码,它是这样工作的。
function randomGen($min, $max, $quantity) {
$numbers = range($min, $max);
$find = array("[","]");
$replace = array("","");
$cadena = str_replace($find, $replace, json_encode(array_slice($numbers, 0, $quantity)));
return $cadena;
}
$minCol1 = 20000;
$maxCol1 = 10001;
$minCol2 = 20001;
$maxCol2 = 30000;
$minCol3 = 40000;
$maxCol3 = 30001;
$minCol4 = 40001;
$maxCol4 = 50000;
$minCol5 = 60000;
$maxCol5 = 50001;
for($i = 1; $i<=10000; $i++){
$oportunidades = randomGen($minCol1,$maxCol1,1).",".randomGen($minCol2,$maxCol2,1).",".randomGen($minCol3,$maxCol3,1).",".randomGen($minCol4,$maxCol4,1).",".randomGen($minCol5,$maxCol5,1);
$str_arr = explode (",", $oportunidades);
?>
<li>
<span data-oportunidades='<? echo(json_encode($str_arr));?>'>
<?=str_pad($i, 5, "0", STR_PAD_LEFT);?>
</span>
</li>
<?
$minCol1 = $minCol1 -1;
$maxCol1 = $minCol1 -1;
$minCol2 = $minCol2 +1;
$maxCol2 = $minCol2 +1;
$minCol3 = $minCol3 -1;
$maxCol3 = $minCol3 -1;
$minCol4 = $minCol4 +1;
$maxCol4 = $minCol4 +1;
$minCol5 = $minCol5 -1;
$maxCol5 = $minCol5 -1;
}
但我很肯定这不是解决这个问题的正确方法。
有人知道怎么做吗?
太感谢你了!
1条答案
按热度按时间0pizxfdo1#
也许你想要这样的东西:
或者以不那么自然而然的方式: