Re: Php亂數問題 急急急!

作者: jhunkyoiori (瓦爾加布)   2015-11-09 12:03:51
※ 引述《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*/

Links booklink

Contact Us: admin [ a t ] ucptt.com