Home > Backend Development > PHP Tutorial > Implementation code of PHP lottery applet_PHP tutorial

Implementation code of PHP lottery applet_PHP tutorial

WBOY
Release: 2016-07-21 15:05:11
Original
977 people have browsed it

This lottery applet can also be used in actual testing environments. For example, when querying test data under the in condition, you need to query 5 random IDs, and then use ab to perform stress testing

Copy code The code is as follows:

/**
* "Lottery" function
*
* @param integer $first Starting number
* @param integer $last Ending number
* @param integer $total Number of winners
*
* @return string
*
*/
function isWinner($first , $last, $total)
{
$winner = array();
for ($i=0;;$i++)
{
$number = mt_rand($first, $last);
if (!in_array($number, $winner))
$winner[] = $number; // If the number does not exist in the array, add it to the array
if (count ($winner) == $total) break;
}
return implode(' ', $winner);
}
// for test
echo isWinner(1, 100, 5 );
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327707.htmlTechArticleThis lottery applet can also be used in the actual test environment. For example, the test data query is in Under the conditions, you need to query 5 random IDs, and then use ab to stress test the copied code code...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template