PHP big turntable Winning probability algorithm example, PHP big turntable winning probability _php tutorial

Source: Internet
Author: User
Tags php programming

PHP big turntable Winning probability algorithm example, PHP big turntable winning probability


This paper introduces the method of realizing the probability algorithm of the big Carousel of PHP, and shares it for everyone's reference. Specific as follows:

Big turntable is a lot of recent online moving in a more interesting thing, let's take a look at this big turntable winning probability algorithm and examples, I hope you have some help.

This is an app client that has the big Carousel Lottery algorithm, specifically how the lottery is certainly implemented on our service side. Here's a simple way to share the implementation code with you:

The

copy Code 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 ', ' V ' =>12,
' 4 ' = = Array (' ID ' =>5, ' prize ' = ' 10Q ', ' V ' =>22),
' 5 ' = > Array (' ID ' =>6, ' prize ' = ' = ' next time it will be able to be in oh ', ' V ' =>50),
);

$actor =;

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 ');//Medium award
Print_r ($res);

I hope this article is helpful to everyone's PHP programming.


Urgency, PHP waiting to find the lucky big wheel in the probability of the algorithm, so that he can win, here or not to win the lottery tips

Come on, look at the papers.

Problems with the PHP algorithm

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

*********

********

*******

******

*****

****

***

**

*


I don't know what's wrong with you? * is the symbol, cannot sum.

Add:
I am really sorry, I still do not understand "output 55 this loses" what meaning?

Add:
The statement you added is the result of calculating 0+1+....+10, do you have any questions?

http://www.bkjia.com/PHPjc/897691.html www.bkjia.com true http://www.bkjia.com/PHPjc/897691.html techarticle PHP big turntable Winning probability algorithm example, PHP big turntable winning probability This article describes the PHP big turntable winning probability algorithm implementation method, share to everyone for your reference. Specific as follows: ...

  • Related Article

    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.