3v4l.org

run code in 300+ PHP versions simultaneously
<?php $priorities = array( 6=> 10, 5=> 40, 4=> 35, 3=> 5, 2=> 5 ); # you put each of the values N times, based on N being the probability # each occurrence of the number in the array is a change it will get picked up # same is with lotteries $numbers = array(); foreach($priorities as $k=>$v){ for($i=0; $i<$v; $i++) $numbers[] = $k; } # then you just pick a random value from the array # the more occurrences, the more chances, and the occurrences are based on "priority" $entry = $numbers[array_rand($numbers)]; echo "x: ".$entry;

preferences:
28.55 ms | 402 KiB | 5 Q