Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

randomize array content


Hello,

After 2 months working with ruby i still bump to some of those:

what would be the simplest way (couldn't find a rand method) to
achieve a subject's task?

thanks!
t

traktor@gmail.com wrote:
> Hello,

> After 2 months working with ruby i still bump to some of those:

> what would be the simplest way (couldn't find a rand method) to
> achieve a subject's task?

If you mean that you want to shuffle the array, then:

array.sort_by{rand}

This comes up often enough that it'd almost be worth adding an
Array#shuffle (and/or #shuffle!) method to core...

--
Alex

traktor@gmail.com wrote:
> Hello,

> After 2 months working with ruby i still bump to some of those:

> what would be the simplest way (couldn't find a rand method) to
> achieve a subject's task?

> thanks!
> t

ary.sort_by { rand }

Regards
Stefan

--
Posted via http://www.ruby-forum.com/.

On May 28, 2:07 pm, Alex Young <a@blackkettle.org> wrote:

Thanks Alex, that would be it!

best
t

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc