20, 'white' => 10, 'red' => 40, 'green' => 5, 'blue' => 25, ); // Initialize the scores array with all 0's // The "outs" will be used when the probability does not // occur in any of the rules $scores = array('outs' => 0); foreach($rules as $k => $v) { $scores[$k] = 0; } $count = count($rules); for($x = 0; $x < $i; $x++) { $rules = shuffle_assoc($rules); $accumulated_probability = 0; $rand = mt_rand(1,100); foreach($rules as $k => $probability) { $actual_probability = $probability + $accumulated_probability; $accumulated_probability = $probability + $accumulated_probability; if($rand > $actual_probability) { continue; } else { $scores[$k]++; continue 2; } } $scores['outs']++; } foreach($scores as $k => $v) { echo "$k: " . (($v/$i)*100) . "% ($v/$i)\n"; } ?>