作者jhunkyoiori (瓦尔加布)
看板PHP
标题Re: Php乱数问题 急急急!
时间Mon Nov 9 12:03:51 2015
※ 引述《HarryWen (Harry)》之铭言:
: http://i.imgur.com/t1fyTrC.jpg
: http://i.imgur.com/NdFwdI6.jpg
: http://i.imgur.com/P77pKq2.jpg
: 请各位帮帮忙
/*练习6*/
$array = array();
$max = 0;
for($i=0;$i<10;$i++){ //(1)
$rand = rand(1,50);
if($max < $rand) $max = $rand;
array_push($array,$rand); //(2)
echo $rand;//(2)
}
print_r($array);//(3)
echo $max;//(4)
/*练习6 end*/
/*练习7*/
$array = array_fill(1,6,0);
for($i=0;$i<100;$i++){ //(1)
$rand = rand(1,6);
$array[$rand]++;//(2)
}
foreach($array as $key => $value){//(3)
echo "出现 {$key}点 的机率为 {probability($value)}".PHP_EOL;
}
function probability($count){//(3)
return $count/100;
}
/*练习7 end*/
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.161.65.185
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1447041834.A.41F.html
※ 编辑: jhunkyoiori (218.161.65.185), 11/09/2015 12:08:01
※ 编辑: jhunkyoiori (218.161.65.185), 11/09/2015 12:12:19
※ 编辑: jhunkyoiori (218.161.65.185), 11/09/2015 12:44:20