Seems to be some unreasonable, trouble everybody help to correct me! Thank you ~
<?PHPHeader("Content-type:text/html;charset=utf-8"); functionGetv ($k,$arr){ for($j=$k;$j>=0;$j--){ if($j==0){ $tmp[' B ']=intval(0); $tmp[' E ']=intval($arr[$j[' V ']); return $tmp; }Else{ $tmp[' B ']=intval($arr[$j-1][' E ']); $tmp[' E ']=intval($arr[$j-1][' E ']+$arr[$j[' V ']); return $tmp; } } } functionDorand () {//Prizes $prize _arr=Array( ' 0 ' + =Array(' id ' =>1, ' prize ' = ' tablet ', ' V ' =>3), ' 1 ' + =Array(' id ' =>2, ' prize ' = ' digital camera ', ' V ' =>5), ' 2 ' =Array(' id ' =>3, ' prize ' = ' speaker device ', ' V ' =>10), ' 3 ' + =Array(' id ' =>4, ' prize ' = ' 4G usb ', ' V ' =>12), ' 4 ' =Array(' id ' =>5, ' prize ' = ' Q $10 ', ' V ' =>20), ' 5 ' =Array(' id ' =>6, ' prize ' = ' = ' will be able to be in oh ', ' V ' =>50), ); //Calculate probability range for($i= 0;$i<Count($prize _arr);$i++){ $tmp= Getv ($i,$prize _arr); $prize _arr[$i[' B '] =$tmp[' B ']; $prize _arr[$i[' e '] =$tmp[' E ']; } //Get probability foreach($prize _arr as $key=$val) { $arr[$val[' ID ']] [' V '] =$val[' V ']; $arr[$val[' ID ']] [' B '] =$val[' B ']; $arr[$val[' ID ']] [' e '] =$val[' E ']; $arr[$val[' ID ']] [' prize '] =$val[' Prize ']; //get the sum of probabilities $sum+=$arr[$val[' ID ']] [' V ']; } ///Generate random number $r=Mt_rand(1,$sum); //Var_dump ($arr); Traversing Data foreach($arr as $k=$v){ //exit; Judging the probability interval if(($v[' B ']<=$r&&$v[' E ']>=$r)){ Echo"Random number:".$r. "\ T". "Probability".$v[' B ']. " --".$v[' E ']. "\ T". " Total probability: ".$sum. "\ n"; //return the winning ID $id=$k; return $prize=$arr[$k[' Prize ']; Break; } } } for($z= 1;$z<=3;$z++){ Echo"\ r \ n".$z." "The Winning prizes are:". Dorand (). " <p> "; } ?>