Home >Backend Development >PHP Tutorial >Probability Calculation PHP Lucky Star_PHP Tutorial
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);
}
?>