php年会抽奖

年会抽奖,要求一等奖的中奖概率是0.12%,二等奖中奖概率是3%,三等奖中奖概率是12%,其他中奖概率是都是谢谢惠顾。

<?php
/**
 * 抽奖
 * @param int $total
 */
function getReward($total=1000)
{
	$win1 = floor((0.12*$total)/100);
	$win2 = floor((3*$total)/100);
	$win3 = floor((12*$total)/100);
	$other = $total-$win1-$win2-$win3;
	$return = array();
	for ($i=0;$i<$win1;$i++)
	{
		$return[] = 1;
	}
	for ($j=0;$j<$win2;$j++)
	{
		$return[] = 2;
	}
	for ($m=0;$m<$win3;$m++)
	{
		$return[] = 3;
	}
	for ($n=0;$n<$other;$n++)
	{
		$return[] = '谢谢惠顾';
	}
	shuffle($return);
	return $return[array_rand($return)];
}

$data = getReward();
echo $data;
?> 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值