PHP 随机生成0.1-0.9之内的数字
$string = "0.1-0.90";
$splitIndex = strpos($string, "-"); // 查找"-"的位置
$firstPart = substr($string, 0, $splitIndex); // 截取"0.1"部分
$secondPart = substr($string, $splitIndex + 1); // 截取"0.9"部分
echo "第一部分: " . $firstPart . "\n";
echo "第二部分: " . $secondPart . "\n";
// 生成随机数字
$randomNumber = $firstPart + mt_rand(0, (int)($secondPart * 100)) / 100;
echo "随机数字: " . $randomNumber . "\n";
随机数字生成
$randomNumber = random_int(1, 10);

本文详细解释了如何在PHP中通过字符串操作和mt_rand函数生成0.1到0.9之间的随机小数,包括分割字符串、获取部分值并进行随机数生成。
1727

被折叠的 条评论
为什么被折叠?



