Here is a simple PHP function that generates a random number within a specified range and returns a string separated by English commas:
function generateRandomNumbers($min, $max, $count) {
$numbers = array();
for ($i = 0; $i < $count; $i++) {
$numbers[] = mt_rand($min, $max);
}
return implode(',', $numbers);
}This function is being used. mt_rand() The function generates random numbers within a specified range and adds each random number to an array. Finally, use it. implode() The function concatenates the array elements into a single string using English commas and returns this string.
You can call this function to generate a random number as follows:
$min = 1; // 最小值
$max = 100; // 最大值
$count = 10; // 生成数量
$randomNumbers = generateRandomNumbers($min, $max, $count);
echo $randomNumbers;The above code generates 10 random numbers between 1 and 100 and outputs a string separated by English commas. You can modify this code as needed. $min、$max 和 $count Value.