Home >Backend Development >PHP Tutorial >Probability Calculation PHP Lucky Star_PHP Tutorial

Probability Calculation PHP Lucky Star_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:34:12775browse

Given a probability (here is a point), determine whether a certain event occurs.
It can be used to randomly generate website lucky stars based on the points obtained by the user (note: there is an equal word here).
/**
@title:PHP Lucky Star(lucker)
@version:1.00
@license:BSD
@author:axgle
*/

$bl = lucker(50);//50% possibility
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<$dot; $i++) {
                    $range[] = $total[$i];
}
          return in_array($one,$range);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508501.htmlTechArticleGiven a probability (here is the number of points), determine whether an event occurs. It can be used to determine whether a certain event occurs based on the user's information. Points, randomly generated website lucky stars and other aspects (note: there is an equal word here). ?php /*...
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