Skip to content

Instantly share code, notes, and snippets.

@pmaojo
Last active January 31, 2018 00:09
Show Gist options
  • Save pmaojo/f98eb7a18a6e2ed200d8ca286b615a95 to your computer and use it in GitHub Desktop.
Save pmaojo/f98eb7a18a6e2ed200d8ca286b615a95 to your computer and use it in GitHub Desktop.
Intento de selección aleatoria con peso
@inserciones = Adblock.where(code: @sponsorsection).inject({}) {|h, p| h[p.id] = p.ranking; h}
@ofertas_select2 = WeightedRandomizer.new(@inserciones)
@ofertas_select = @ofertas_select2.sample(10)
@ofertas = []
@ofertas_select.each do |o|
@insert = Adblock.find(o)
@oferta = @insert.coupon
if @oferta.publicada == true
@ofertas << @oferta
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment