PHP winning probability algorithm, can be used for scraping cards, large turntable, such as lottery algorithm. The usage is very simple, the code has the detailed annotation explanation, at a glance can understand
--> $proCur) {$randNum = Mt_rand (1, $proSum);
if ($randNum
Then we in the program will inevitably design to the algorithm, that is, according to a certain probability to allow users to receive prizes. Let's look at two probability algorithm functions first.
Algorithm One
Copy Code code as follows:
/**
* Full probability calculation
*
* @param array $p Array (' A ' =>0.5, ' B ' =>0.2, ' C ' =>0.4)
Early on these requirements, and then according to the information on the Internet, using a stage-based extraction method, we look at the overall program: The program is completed under the thinkphp framework, using some of the framework of the class library and functions, the following I will explain each, the controller part
The lottery algorithm needs to meet the following requirements:
1. Can control
A php probability algorithm instance applicable to lottery programs and random advertisements. Then we will inevitably design algorithms in the program, that is, to give the user a prize based on a certain probability. Let's look at two probability algorithm functions. Algorithm 1: Copy the code as follows: *** the
This example for you to share the Java Lottery snapping algorithm for everyone to refer to, the specific contents are as follows
Application Scenarios
Single-piece trophy snapping (limited)Multiple prizes are awarded according to Probability (limited, limited)
Code implementation
Table structure:
--Lottery Set
CREATE TABLE Award_info
(ID number (one)
Probabilistic algorithm for winning lottery programs written by PHP
This article to share is the PHP winning probability algorithm, can be used for scraping cards, large turntable and other lottery algorithm. The usage is very simple, the code has the detailed comment expla
The php winning probability algorithm can be used for scratch cards, big turntable, and other lottery algorithm. The php winning probability algorithm can be used for scratch cards, big turntable, and other lottery algorithms. The usage is very simple. the code has a detaile
The requirements for the lottery algorithm are as follows: 1. Can control the probability of winning the lottery 2. With Randomness 3. It is best to control the number of prizes 4. According to the user ID or IP, mobile number, QQ number and other conditions to limit the number of lottery Early on these require
I set the probability of the award for 0, what does that mean? This means that no matter how much the lottery draws, no one will ever get the premium sedan. When the organizer flips the remaining blocks each time, the participant will find that the first prize may be just under a number in the box next to the draw, blaming their bad luck. Is it really bad luck? In fact, when the participant flipped that block, the program has decided on the award, w
second is not, and the third is not. The last one must be. This algorithm is simple and highly efficient. The key is that it has been used in our previous projects, especially in projects with large data volumes.
Next we will use the PHP configuration award.
The Code is as follows:
$ 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
A lottery algorithm is implemented by the interval distribution of random numbers. Accept a list that contains the odds of winning a prize and return the prize.
Define an abstract award category first.
Public abstract class Abstractprize {
/**
* Prize probability * *
private double probability;
Public double getprobability () {return
probability;
}
public void s
sedan, but I set the prize probability of 0, which means what? This means that no matter how much the lottery draws, no one will ever get the premium sedan. When the organizer flips the remaining blocks each time, the participant will find that the first prize may be just under a number in the box next to the draw, blaming their bad luck. Is it really bad luck? In fact, when the participants flipped that block, the program has decided on the award, w
The PHP lottery algorithm is now available for a lottery activity nbsp; the probability of winning the prize is as follows: First Prize 5% second prize 10% third prize 60% participation prize 25% my thoughts are very stupid: I have a random number ranging from 0 to, and then divide the interval according to the winning probability nbsp; first prize 96-100 secon
PHP winning probability algorithm, can be used for scraping cards, large turntable and other lottery algorithm. The usage is very simple, the code has the detailed comment explanation, can understand at a glancePHP/** Classical probability algorithm, * $PROARR is a pre-set array, * Assuming array is: Array (100,200,300
Do site class sometimes get an activity or something, to let users participate, both to attract users to register, but also improve the user activity of the site. At the same time to participate in the user will receive a certain prize, there are 100% of winning, there is a certain probability of winning, big such as the ipad, iphone5, small in a Q currency or something. Then we will certainly design the algorithm in the program, that is, in accordanc
Original: http://blog.csdn.net/dongsg11200/article/details/24607877PHP winning probability algorithm, can be used for scraping cards, large turntable and other lottery algorithm
/*
* Classical probability algorithm,
* $PROARR is a pre-set array,
* Suppose array is: Array (100,200,300,400),
* Start is
This article to share is the PHP winning probability algorithm, can be used for scraping cards, large turntable, such as lottery algorithm. The usage is very simple, the code has the detailed annotation explanation, a look is understood, has the need the small partner reference under.
We finish the process of PHP backstage, PHP's main work is responsible for the
: This article mainly introduces the php lottery algorithm weight. if you are interested in the PHP Tutorial, refer to it.
Function getReward ($ total = 1000) {$ win1 = floor (0.12 * $ total)/100); $ win2 = floor (3 * $ total)/100 ); $ win3 = floor (12 * $ total)/100); $ other = $ total-$ win1-$ win2-$ win3; $ return = array (); for ($ I = 0; $ I
Php lottery
Php lottery probability algorithm
/** The lottery drawing principle with different probabilities is to divide the 0 to * (total proportion) intervals based on the proportion of the entire item, then, the random number seed is used to generate a number in 0-* to determine the range in which the number falls, and the interval corresponds to the item drawn. * The r
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.