Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devision by 0 sometimes #5

Open
copyhold opened this issue Mar 16, 2015 · 3 comments
Open

devision by 0 sometimes #5

copyhold opened this issue Mar 16, 2015 · 3 comments

Comments

@copyhold
Copy link

Sometimes when weight includes 0 division by zero occures

Loading development environment (Rails 4.2.0)
[1] pry(main)> pond = {a: 1, b: 4, t:0}
=> {:a=>1, :b=>4, :t=>0}
[2] pry(main)> pu = Pickup.new(pond, uniq: true)
=> #<Pickup:0x00000005e6a6e0 @key_func=nil, @list={:a=>1, :b=>4, :t=>0}, @uniq=true, @weight_func=nil>
[3] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[4] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[5] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[6] pry(main)> pu.pick(3)
ZeroDivisionError: divided by 0
from /home/ilya/.rvm/gems/ruby-2.2.0@blc/gems/pickup-0.0.10/lib/pickup.rb:128:in `block in get_random_items'
@fl00r
Copy link
Owner

fl00r commented Mar 16, 2015

Hi! Thank you for your feedback.
Weight of zero is causing this edge case.
I will fix it soon

@fl00r
Copy link
Owner

fl00r commented Mar 16, 2015

Fixed

@fl00r fl00r closed this as completed Mar 16, 2015
@Youngv
Copy link

Youngv commented Mar 17, 2015

It seems still have this problem when I try the example above.

@fl00r fl00r reopened this Mar 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants