Lars Christensen
5/26/2008 9:44:00 AM
On May 26, 11:16 am, Mikael Høilund <mik...@hoilund.org> wrote:
> On May 26, 2008, at 10:45, Boris Schmid wrote:
>
> > Hi all,
>
> > I wondered if there was a more compact method of generating things
> > like
> > a random string, or a random list of numbers than I'm using now (using
> > ruby 1.9.0-1)
>
> Array(100) { rand }
Don't you mean
Array.new(100) { rand }
Array(arg) creates an array equal to 'arg' (if it responds to .to_ary)
or an array containing precisly 'arg' otherwise. It never yields.
There is also
(1..100).map { rand }
And for strings
(1..100).map { (rand(26)+97).chr }.join
Lars