PHP big wheel winning probability algorithm example, PHP big wheel winning probability_PHP tutorial

WBOY
Release: 2016-07-13 10:16:24
Original
1078 people have browsed it

PHP big wheel winning probability algorithm example, PHP big wheel winning probability

The example in this article describes the implementation method of the PHP Roulette winning probability algorithm and is shared with everyone for your reference. The details are as follows:

The Big Roulette is one of the more interesting things in many online activities recently. Let’s take a look at the algorithm and examples of the winning probability of this Big Roulette. I hope it will be helpful to you.

This is an APP client with a big carousel lottery algorithm. The specific method of lottery is of course implemented on our server. Let me briefly share with you the implementation code:

Copy code The code is as follows:
header("Content-type: text/html; charset=utf-8");
$prize_arr = array(
'0' => array('id'=>1,'prize'=>'tablet','v'=>1),
'1' => array('id'=>2,'prize'=>'Digital Camera','v'=>5),
'2' => array('id'=>3,'prize'=>'Speaker device','v'=>10),
'3' => array('id'=>4,'prize'=>'4G USB drive','v'=>12),
'4' => array('id'=>5,'prize'=>'10Q coins','v'=>22),
'5' => array('id'=>6,'prize'=>'You might win next time','v'=>50),
);

$actor = 100;

foreach ($prize_arr as $v) {
$arr[$v['id']] = $v['v'];
}
foreach ($arr as &$v) {
$v = $v*$actor;
}
asort($arr);
$sum = array_sum($arr); //Total probability

$rand = mt_rand(1,$sum);

$result = ''; //Winning product id

foreach ($arr as $k => $x)
{
if($rand <= $x)
{
$result = $k;
break;
}
else
{
$rand -= $x;
}
}
$res['yes'] = $prize_arr[$result-1]['prize']; //Win the prize
print_r($res);

I hope this article will be helpful to everyone’s PHP programming design.


Urgent, PHP is waiting to find an algorithm for the probability in the WeChat Lucky Wheel so that he can win the prize. If he wins the prize here, it still prompts that he has not won the prize

Come and take a look at the document

Problems with php algorithm

Your program can run and output the following content:
**********

**********

* *******

*******

******

*****

****

***

**

*


I don’t know what your problem is ? * is a symbol and cannot be summed.

Supplement:
I’m really sorry, I still don’t understand what “output 55 to lose” means?

Supplement:
The statement you added is the result of calculating 0+1+....+10. Do you have any questions?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897691.htmlTechArticleAn example of the PHP big wheel winning probability algorithm, the PHP big wheel winning probability algorithm. This example tells the PHP big wheel winning probability algorithm. The implementation method is shared with everyone for your reference. The details are as follows:...
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template