map ++$array[rand $elements], 1..$sum; #### $array[$_] ||= 0 for 0..$elements-1;