a = [1,2,3,4,5]
a.sort_by {rand}
=> 3,1,5,2,4
On 12/23/06, Justin
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> (sorry if I posted this twice, google groups is not working well, I
> think)
>
> I''m trying to randomize an array, and this is what I have:
>
> arr_set_unordered = randomizer(arr_set)
>
> def randomizer(arr)
> result = arr.collect { arr.slice!(rand arr.length) }
> end
>
> It does randomize it, but it only returns 3 values instead of the 5
> values that I''m expecting. Any ideas why?
>
> Thank you!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---