I have an array full of items and I have to draw from all of them only one. It's simple, but here there are complications. Each of them has a variable chance of being drawn. The default chance is 1. 0 means that the element will never be selected and 2 means that the element has double chance to be selected.
$elements = array(
"A" => "1", // normal chance to be selected (= 25%)
"B" => "1", // normal chance to be selected (= 25%)
"C" => "2", // double chance to be selected (= 50%)
"D" => "0" // no chance to be selected (= 0%)
)
This is only simple example, but my appropriate array has 2000+ elements and chance from 0 to 20.
What is the best way to do that?