Home > Backend Development > PHP Tutorial > Implement a simple random lottery applet based on PHP, php lottery applet_PHP tutorial

Implement a simple random lottery applet based on PHP, php lottery applet_PHP tutorial

WBOY
Release: 2016-07-12 09:01:38
Original
1378 people have browsed it

Implement a simple random lottery applet based on PHP, PHP lottery applet

A lottery applet with a controllable overview, and a certain prize can also be displayed on the front end, and in the program It’s simply impossible to get! After adding up all the probabilities x10, the value of each item in the new array is equal to the sum of its previous ones plus itself.

Then immediately generate a number between 0 and the maximum number, check which interval it belongs to through a loop, and return the key of that interval.

The code is as follows

$prize = array(
1 => 3.5, //3.5%机率
2 => 2.5, 
3 => 6, 
4 => 2, 
5 => 42, //42%机率
6 => 36, 
7 => 2, 
8 => 4, 
9 => 2
);
//最后确认相加等于100
$prizeList = array(
1 => array('小仙子'), 
2 => array('5Q币'), 
3 => array('38888游戏币'), 
4 => array('88888游戏币'), 
5 => array('谢谢参与!'), 
6 => array('欢迎下次再来!'), 
7 => array('10Q币'), 
8 => array('888银元宝(绑定)'), 
9 => array('随机高级坐骑(绑定)')
);
//unset($prize[7]); 直接把10Q这个奖品去掉
$times = 10;
$max = 0;
foreach ($prize as $k => $v)
{
$max = $v * $times + $max;
$row['v'] = $max;
$row['k'] = $k;
$prizeZone[] = $row;
}
$max--; //临界值
$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]);
Copy after login

That’s all I have written for you to implement a simple lottery applet based on PHP, but they are all core codes. I hope it will be helpful to everyone’s study and work.

Articles you may be interested in:

  • PHP lottery applet implementation code
  • php code sharing for lottery program that can set the probability of winning
  • Applicable Examples of PHP probability algorithm for lottery programs and random advertisements
  • php solves the problem of negative inventory caused by high-traffic concurrent warehousing such as flash sale lottery etc.
  • PHP carousel lottery interface example
  • Lottery program winning probability algorithm written in php

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1088781.htmlTechArticleImplementing a simple random lottery applet based on PHP, a php lottery applet and a lottery applet, the overview is controllable, and But a certain prize is displayed on the front end, but it is impossible to get it in the program! Check everything...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template