@inserciones = Adblock.where(code: @sponsorsection).inject({}) {|h, p| h[p.id] = p.ranking; h}
@ofertas_select2 = WeightedRandomizer.new(@inserciones)
@ofertas_select = @ofertas_select2.sample(3)
@coupons = []
@ofertas_select.each do |o|
@insert = Adblock.find(o)
@oferta = @insert.coupon
if @oferta.publicada == true
@coupons << @oferta
end
end
Is returning random results, and sometimes the same item is picked 3 times, there are 3 items to chose { one => 3, two => 2, three => 1}
Is there a way to avoid repeating ?
Is returning random results, and sometimes the same item is picked 3 times, there are 3 items to chose { one => 3, two => 2, three => 1}
Is there a way to avoid repeating ?