循环10次,每次得到一个随机数,相加要等于100,随机数不能为0,且随机数需有大有小
function randStr($num,$max){
$sum = 0;
$count = 0;
while($sum<$max){
$surNum = $num-$count;
$rand = mt_rand(1,($max-$sum-$surNum)+1);
$sum += $rand;
$count++;
echo $rand."<br/>";
}
echo $sum;
}
randStr(10,100);
我写的这个,一开始值会特别大,后面就全是2,1,1这种数,我希望得到的结果是7,9,15,3,5这种有大有小的,要怎么做呢?望各位大佬指教