Skip to content

Instantly share code, notes, and snippets.

@maxjustus
Last active September 25, 2015 18:38
Show Gist options
  • Save maxjustus/b093358f21200bf2eb0b to your computer and use it in GitHub Desktop.
Save maxjustus/b093358f21200bf2eb0b to your computer and use it in GitHub Desktop.
Ranked array sample thingey
class Array
def ranked_sample(count)
slice_size = length / count
count.times.reduce([]) do |a, i|
i += 1
to_take = i == count ? length : slice_size * i
v = (take(to_take) - a).sample
a << v if v
a
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment