I have a collection of elements that I want to shuffle randomly, but every element has a different priority or weight. So the element with bigger weight has to have more pro
elements.flat_map { |h| [h[:id]] * h[:weight] }.shuffle.uniq