This article mainly introduces the PHP Grand turntable winning probability algorithm. The example describes the implementation process of the probability algorithm, which is of great practical value, for more information about how to implement the PHP Grand turntable winning probability algorithm, see the example in this article. 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:
The 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.