Skip to content

Instantly share code, notes, and snippets.

@fdcore
Created December 14, 2015 16:46
Show Gist options
  • Save fdcore/67148fb9deeec72635e9 to your computer and use it in GitHub Desktop.
Save fdcore/67148fb9deeec72635e9 to your computer and use it in GitHub Desktop.
<?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