Home  >  Article  >  php教程  >  概率计算 PHP幸运星

概率计算 PHP幸运星

WBOY
WBOYOriginal
2016-06-13 10:33:27928browse

给定一个概率(这里是点数),确定某次事件是否发生.
可以用在根据用户获得的点数,随机产生网站幸运星等方面(注意:这里有个等字).
/**
@title:PHP幸运星(lucker)
@version:1.00
@license:BSD
@author:axgle
*/

$bl = lucker(50);//50%的可能性
var_dump($bl);

function lucker($dot) {
        $dot = intval($dot);
        $dot = max($dot,0);//min dot = 0
        $dot = min($dot,100);//max dot = 100

        $one = rand(1,100);
        $total = range(1,100);
        shuffle($total);

        $range = array();
        for($i=0; $i                 $range[] = $total[$i];
        }
        return in_array($one,$range);
}
?>

Statement:
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