Home > Backend Development > PHP Tutorial > PHP抽奖算法有关问题

PHP抽奖算法有关问题

WBOY
Release: 2016-06-13 13:33:46
Original
925 people have browsed it

PHP抽奖算法问题
现在要做一个抽奖的活动
 中奖概率具体如下:
一等奖 5%
二等奖 10%
三等奖 60%
参与奖 25%

我的思路很笨 :
我是随机一个0-100的数,然后按照中奖概率 来划分区间 
一等奖 96-100
二等奖 86-95
三等奖 26-85
参与奖 1-25

没接触过算法 请大神们帮忙

------解决方案--------------------
楼主这个想法可以的

PHP code
<?php $arr=array(5=>'一等奖',10=>'二等奖',60=>'三等奖',25=>'参与奖');
$pool=array();
foreach($arr as $k=>$v)//构造奖池
    $pool+=array_fill(count($pool),$k,$v);
echo $pool[rand(0,99)];//开始抽奖 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template