Skip to content

Instantly share code, notes, and snippets.

@gdemir
Created March 22, 2012 09:06
Show Gist options
  • Select an option

  • Save gdemir/2157255 to your computer and use it in GitHub Desktop.

Select an option

Save gdemir/2157255 to your computer and use it in GitHub Desktop.
random element select
array = [3, 2, 4, 6, 8, 9]
n = 3
# 1.9.2 öncesi
array = array.sort {|a, b| rand <=> rand }.slice(0..n - 1)
p array
# 1.9.2
array = array.shuffle.slice(0..n - 1)
p array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment