Guest User

Untitled

a guest
Aug 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. <?php
  2. $targets = array(500,300,100,99,1); // 抽選対象
  3. $sum = array_sum($targets); // レート合計
  4. $total = 0; // レート累計
  5. $rand = rand(1, $sum); // 乱数
  6.  
  7. foreach($targets as $key => $value) {
  8. $total += $value;
  9. if ($rand <= $total) {
  10. $result = $key;
  11. break;
  12. }
  13. }
  14. echo $result; // 抽選結果($targetsの添字)
Add Comment
Please, Sign In to add comment