This article describes the PHP large turntable winning probability algorithm to achieve the method of sharing for everyone to reference. Specifically as follows:
Large turntable is a lot of recent online movement of a more interesting things, let's take a look at this large turntable winning probability algorithm and examples, I hope to help you.
This is an app client with a large turntable lottery algorithm, specifically how the lottery is certainly implemented in our service side. Here's a simple share of the implementation code:
Copy Code code as follows:
Header ("content-type:text/html; Charset=utf-8 ");
$prize _arr = Array (
' 0 ' => array (' ID ' =>1, ' prize ' => ' tablet computer ', ' 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 flash drive ', ' V ' =>12),
' 4 ' => array (' ID ' =>5, ' Prize ' => ' 10Q ', ' V ' =>22),
' 5 ' => array (' ID ' =>6, ' prize ' => ' will be able to be in the next time Oh ', ' 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 ']; Award in
Print_r ($res);
I hope this article will help you with your PHP program design.