Skip to content

Instantly share code, notes, and snippets.

@kirel
Created September 10, 2009 14:03
Show Gist options
  • Select an option

  • Save kirel/184569 to your computer and use it in GitHub Desktop.

Select an option

Save kirel/184569 to your computer and use it in GitHub Desktop.
class Array
def random_slice length
values_at(*(1..length).inject([]){|a,_|a.include?(r=rand(size))?redo:a<<r})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment