Home > Backend Development > PHP Tutorial > PHP implementation of lottery program code sharing that can set the probability of winning_PHP tutorial

PHP implementation of lottery program code sharing that can set the probability of winning_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:40:44
Original
738 people have browsed it

Copy code The code is as follows:

/**
* Lottery
* @param int $total
*/
function getReward($total=1000)
{
$win1 = floor((0.12*$total)/100);
$win2 = floor((3*$total)/100);
$win3 = floor((12*$total)/100);
$other = $total-$win1-$win2-$win3;
$return = array();
for ($ i=0;$i<$win1;$i++)
{
$return[] = 1;
}
for ($j=0;$j<$win2;$j++)
{
$return[] = 2;
}
for ($m=0;$m<$win3;$m++)
{
$return[] = 3 ;
}
for ($n=0;$n<$other;$n++)
{
$return[] = 'Thank you for your patronage';
}
shuffle( $return);
return $return[array_rand($return)];
}

$data = getReward();
echo $data;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/714948.htmlTechArticleCopy the code as follows: ?php /*** Lottery * @param int $total*/ function getReward($total=1000) { $win1 = floor((0.12*$total)/100); $win2 = floor((3*$total)/100); $win3 = floor...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template