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 );
?>
http://www.bkjia.com/PHPjc/327707.htmlwww.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...