Skip to content
Permalink
Browse files
Array#sample checks all indexes when spinning. Fixes #3506.
  • Loading branch information
brixen committed Dec 28, 2015
1 parent f0b5ce6 commit deabe675c6872f7fbb331ad27bb955fb9ff6192d
Showing 1 changed file with 19 additions and 9 deletions.
@@ -1365,28 +1365,38 @@ def sample(count=undefined, options=undefined)
else
if size / count > 3
abandon = false
spin = 0

result = Array.new count
i = 1

result[0] = rng.rand(size)
while i < count
k = rng.rand(size)
j = 0

while j < i
while k == result[j]
spin += 1
if spin > 100
spin = false
spin_count = 0

while true
j = 0
while j < i
if k == result[j]
spin = true
break
end

j += 1
end

if spin
if (spin_count += 1) > 100
abandon = true
break
end

k = rng.rand(size)
else
break
end
break if abandon

j += 1
end

break if abandon

0 comments on commit deabe67

Please sign in to comment.