$arr = array( 'a1' => 1, 'a2' => 2, 'a3' => 3, 'a4' => 4 ); $set = array(); for($i = 0 ;$i<=100000;$i++){ $set[] = getPrizeKey($arr); } var_dump(array_count_values($set)); function getPrizeKey($weightMap){ $sum = array_sum($weightMap); $low = 0; $rand = rand(1,$sum); foreach($weightMap as $key => $weight){ if($rand>$low && $rand<= $low+$weight){ return $key; } $low = $low+$weight; } }