Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $targets = array(500,300,100,99,1); // 抽選対象
- $sum = array_sum($targets); // レート合計
- $total = 0; // レート累計
- $rand = rand(1, $sum); // 乱数
- foreach($targets as $key => $value) {
- $total += $value;
- if ($rand <= $total) {
- $result = $key;
- break;
- }
- }
- echo $result; // 抽選結果($targetsの添字)
Add Comment
Please, Sign In to add comment