What is a good algorithm that shuffles an array or arrays using weights from the nested arrays?
Example:
$array = array(
array("name"=>"John", "rank"=>3),
array("name"=>"Bob", "rank"=>1),
array("name"=>"Todd", "rank"=>8),
array("name"=>"Todd", "rank"=>14),
array("name"=>"Todd", "rank"=>4)
);
I want the array randomly shuffled but I want the rank
value to be a weight. So those with a low number rank are more likely to be at the top of the list.
I've experimented with a few things, like iterating through the array and pulling out arrays chosen using mt_rand(mt_rand(0,$value),$value)
but I don't think I'm on the right track...
I was able to solve this problem like so:
You can try something like this: