Created
December 14, 2015 16:46
-
-
Save fdcore/67148fb9deeec72635e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_win($arr){ | |
$chance = rand(0, 100); | |
$keys = array_keys($arr); | |
$total = count($keys); | |
if($total == 0) return false; | |
$inter_stopper = 100;// DDOS FIX? | |
$i = 0;// DDOS FIX? | |
while (true) { | |
$i++; // DDOS FIX? | |
if($i == $inter_stopper) return $keys[0]; // DDOS FIX? LOGIC STOPPER | |
$rand = rand(0, $total-1); | |
if($arr[$keys[$rand]]['percent'] >= $chance) | |
return $keys[$rand]; | |
} | |
} | |
function assign_chance(&$array){ | |
$max_sum = get_max_sum($array); | |
foreach($array as $key => $value){ | |
$array[$key]['percent'] = 100 / $max_sum * $array[$key]['min_sum']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment