From: Robert Klemme Date: 2008-05-26T18:45:17+09:00 Subject: Re: briefest method of generating a list of random numbers? 2008/5/26 Boris Schmid : > >> But what's wrong with the first - it looks fairly compact to me: >> >> string = "" ; 100.times { string << (rand(26) + 97).chr} >> > > For strings I'll have to use the one above, Note that String#<< understands ints as being character codes - so you do not need the .chr: irb(main):005:0> str = 100.to_enum(:times).inject("") {|s,| s << (?a + rand(26))} => "uepizlkepyoxxfkefosxxptvcpdiuwyexecngmftnidlyfnhqgmtndbzthhykdjjiyayzwvhatovzbxzqkhclnxwbqbsoxpszwkn" irb(main):006:0> I believe in 1.9 you can as well do str = 100.times.inject("") {|s,| s << (?a + rand(26))} Kind regards robert -- use.inject do |as, often| as.you_can - without end