1

what is your version to this problem ? i'm doing so:

array = [1,2,3,4,5,6,7,8,9] 
puts array.sort_by { array }.first    
puts array[rand(array.size)]
puts array.shuffle.first
puts array.sample
Said Kaldybaev
  • 9,380
  • 8
  • 36
  • 53
  • 3
    may be the answer of this question valuable for your: http://stackoverflow.com/questions/3482149/how-do-i-pick-randomly-from-an-array – Siwei Mar 23 '12 at 11:31

1 Answers1

5

I use array.sample. It is MUCH easier to read than the first 2 and slightly easier to read than the third.

Josh
  • 5,631
  • 1
  • 28
  • 54