So I have an array of possible combinations:
$faces = array ('Bar', 'Cherry', 'Lemon', 'Seven', 'DoubleBar', 'TripleBar');
And an array of payouts
$payouts = array (
'Bar|Bar|Bar' => '5',
'Double Bar|Double Bar|Double Bar' => '10',
'Triple Bar|Triple Bar|Triple Bar' => '15',
'Cherry|Cherry|Cherry' => '20',
'Seven|Seven|Seven' => '70',
'Seven|Any|Any' => '70',
'Diamond|Diamond|Diamond' => '100',
);
And an array for every wheel (3 in total), how can I make weighted random combinations with Seven|Any|Any working properly?
I know I can just create two arrays 6^3 in size one representing the weights and the other array representing every possible combination and using something like this script, but isn't there a shorter, more efficient way?
function weighted_random_simple($values, $weights){
$count = count($values);
$i = 0;
$n = 0;
$num = mt_rand(0, array_sum($weights));
while($i < $count){
$n += $weights[$i];
if($n >= $num){
break;
}
$i++;
}
return $values[$i];
}