r = Hash.new(0)
1000.times do
ran = rand(10)+1
r[ran] = r[ran]+1
end
new = r.values.sort
loop do
new.size.times do |i|
if new[i+1].present? && new[i] >= new[i+1]
new[i] = new[i]-1
new[i+1] = new[i+1]+1
end
end
break if new.size == new.uniq.size
end
r.size.times { |i| r[i+1] =new.reverse[i]}
Hash[r.sort]