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

概率计算 PHP幸运星

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:33:27
Original
1011 people have browsed it

给定一个概率(这里是点数),确定某次事件是否发生.
可以用在根据用户获得的点数,随机产生网站幸运星等方面(注意:这里有个等字).
/**
@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);
}
?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template