Example of the PHP grand turntable winning probability algorithm and the php grand turntable winning probability

Source: Internet
Author: User

Example of the PHP grand turntable winning probability algorithm and the php grand turntable winning probability

This article describes how to implement the PHP grand turntable winning probability algorithm and share it with you for your reference. The details are as follows:

The big turntable is one of the most interesting items in many online activities recently. Let's take a look at the algorithm and example of the winning probability of the big turntable. I hope it will help you.

This is an APP client with a big turntable lottery algorithm. Of course, we have implemented the lottery on our server. The implementation code is as follows:

Copy codeThe Code is as follows: header ("Content-type: text/html; charset = UTF-8 ");
$ Prize_arr = array (
'0' => array ('id' => 1, 'prize' => 'tablet pc', '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 disks', 'V' => 12 ),
'4' => array ('id' => 5, 'prize' => '10q coin ', 'V' => 22 ),
'5' => array ('id' => 6, 'prize' => 'Next time you may be able to get in, ', '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); // The total probability.
 
$ Rand = mt_rand (1, $ sum );
 
$ Result = ''; // The winning product id
 
Foreach ($ arr as $ k => $ x)
{
If ($ rand <= $ x)
{
$ Result = $ k;
Break;
}
Else
{
$ Rand-= $ x;
}
}
$ Res ['yes'] = $ prize_arr [$ result-1] ['prize']; // medium Award
Print_r ($ res );

I hope this article will help you with PHP programming.


In a hurry, php will wait for you to find the probability algorithm in the lucky big turntable so that he can win the prize. If he wins the prize, he will still be prompted not to win the prize.

Here is a document.

Php algorithm problems

Your program can run and output the following content:
* ********* <Br>
* ******** <Br>
* ******* <Br>
* ****** <Br>
* ***** <Br>
***** <Br>
* *** <Br>
* ** <Br>
** <Br>
* <Br>

I don't know what's wrong with you? * It is a symbol and cannot sum.

Supplement:
Sorry, I still don't know what it means to output 55?

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

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.