fork download
  1. <?php
  2. $times=500; //허바 100개 뽑기
  3. $sum = 0; //허바 뽑는데 쓴 지푸라기 총 개수
  4. $i=0;
  5. $list_item = array("머리","오른손","왼손","몸통","다리"); //허수아비 부위
  6. $list_item_count = array(0,0,0,0,0); //허수아비 부위 개수
  7. $list_percent = array(0.1,33,17,44.6,5.3); //허수아비 부위 확률
  8. do{
  9. $i=$i+1;
  10. $Straw = 0; //새로 허바 뽑을때 마다 지푸라기 개수 초기화 해줘야 겠죠
  11. $list_item_count = array(0,0,0,0,0); //새로 허바 뽑을때 마다 부위 개수 초기화 해줘야 겠죠
  12. $Straw_exc = 0; //지푸라기 45개 될때마다 교환권 있죠
  13. do{ //허바 뽑기 시작
  14. $draw = Percent_draw($list_item,$list_percent);
  15. $Straw = $Straw+3;
  16. $Straw_exc = $Straw_exc+3;
  17. if($draw=="머리") $list_item_count[0]=$list_item_count[0]+1;
  18. if($draw=="오른손") $list_item_count[1]=$list_item_count[1]+1;
  19. if($draw=="왼손") $list_item_count[2]=$list_item_count[2]+1;
  20. if($draw=="몸통") $list_item_count[3]=$list_item_count[3]+1;
  21. if($draw=="다리") $list_item_count[4]=$list_item_count[4]+1;
  22. if($Straw_exc >= 45){ //지푸라기 45개 넘으면 교환해서도 받아갈수 있으니깐.....
  23. if($list_item_count[0] >1 && $list_item_count[1] >1 && $list_item_count[2] >1 && $list_item_count[3] >1) {
  24. $Straw_exc = $Straw_exc-45; //교환하면 지푸라기 45개 빼줍니다.
  25. $list_item_count[4] = $list_item_count[4]+1;
  26. }
  27. if($list_item_count[0] >1 && $list_item_count[1] >1 && $list_item_count[2] >1 && $list_item_count[4] >1) {
  28. $Straw_exc = $Straw_exc-45;
  29. $list_item_count[3] = $list_item_count[3]+1;
  30. }
  31. if($list_item_count[0] >1 && $list_item_count[1] >1 && $list_item_count[3] >1 && $list_item_count[4] >1) {
  32. $Straw_exc = $Straw_exc-45;
  33. $list_item_count[2] = $list_item_count[2]+1;
  34. }
  35. if($list_item_count[0] >1 && $list_item_count[2] >1 && $list_item_count[3] >1 && $list_item_count[4] >1) {
  36. $Straw_exc = $Straw_exc-45;
  37. $list_item_count[1] = $list_item_count[1]+1;
  38. }
  39. if($list_item_count[1] >1 && $list_item_count[2] >1 && $list_item_count[3] >1 && $list_item_count[4] >1) {
  40. $Straw_exc = $Straw_exc-45;
  41. $list_item_count[0] = $list_item_count[0]+1;
  42. }
  43. }
  44. if($list_item_count[0] >0 && $list_item_count[1] >0 && $list_item_count[2] >0 && $list_item_count[3] >0 && $list_item_count[4] >0) {
  45. break; //허수아비 헬멧 뽑았으면 반복문 탈출
  46. }
  47. }while(true); //허바뽑기 끝
  48. $sum = $Straw+$sum; //허바 뽑는데 사용한 지푸라기 개수 누적처리
  49. }while($i<$times);
  50. echo "허수아비 헬멧 ".$i."회 뽑기 평균값 : ".$sum/$i;
  51.  
  52. function Percent_draw($items_list,$percent_list) {
  53. $range_now = 0;
  54. $range_last = 0;
  55. $decimal = 4;
  56. if(count($percent_list) != count($items_list)) return false;
  57. $draw = mt_rand(1,pow(10,$decimal)*array_sum($percent_list));
  58. for($sequence=0; $sequence<count($percent_list); $sequence++) {
  59. $range_now += pow(10,$decimal)*$percent_list[$sequence];
  60. if($range_now >= $draw && $range_last < $draw) {
  61. return $items_list[$sequence];
  62. }else{
  63. $range_last = $range_now;
  64. }
  65. }
  66. }
  67. ?>
Success #stdin #stdout 0.02s 24488KB
stdin
Standard input is empty
stdout
허수아비 헬멧 500회 뽑기 평균값 : 112.776