public static function getRandomWeightedElement(array $weightedValues, $default = 1)
    {
        $sum = (int) array_sum($weightedValues);
        $min = 1;

        $rand = mt_rand(min($min, $sum), max($min, $sum));

        $ret = $default;

        foreach ($weightedValues as $key => $value) {
            $rand -= (int) $value;

            if ($rand <= 0) {
                $ret = $key;
                break;
            }
        }

        return $ret;
    }