A simple PHP lottery small program

Source: Internet
Author: User


It then generates a number from 0 to the maximum number, loops through it to see which interval it belongs to, and returns the key for that interval.

The code is as follows Copy Code

$prize = Array (
1 => 3.5,//3.5% probability
2 => 2.5,
3 => 6,
4 => 2,
5 => 42,//42% probability
6 => 36,
7 => 2,
8 => 4,
9 => 2
);
Finally confirm that the addition equals 100
$prizeList = Array (
1 => Array (' Little fairy '),
2 => Array (' 5Q currency '),
3 => Array (' 38888 game currency '),
4 => Array (' 88888 game currency '),
5 => Array (' Thank you for participating! '),
6 => Array (' Welcome to come back next time! '),
7 => Array (' 10Q currency '),
8 => Array (' 888 Silver dollar Treasure (binding) '),
9 => Array (' Random advanced Mount (binding) ')
);
Unset ($prize [7]); Get rid of the 10Q prize directly.

$times = 10;
$max = 0;
foreach ($prize as $k => $v)
{
$max = $v * $times + $max;
$row [' V '] = $max;
$row [' k '] = $k;
$prizeZone [] = $row;
}

$max--; Critical value
$rand = Mt_rand (0, $max);
$zone = 1;
foreach ($prizeZone as $k => $v)
{
if ($rand >= $v [' V '])
{
if ($rand >= $prizeZone [$k + 1][' V '])
{
Continue
}
Else
{
$zone = $prizeZone [$k + 1][' K '];
Break
}
}
$zone = $v [' K '];
Break
}
Print_r ($prizeList [$zone][0]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.