From: Boris Schmid Date: 2008-05-26T19:32:18+09:00 Subject: Re: briefest method of generating a list of random numbers? > You could also do > > Array.new(100) { 97 + rand(26) }.pack("c*") > > Peter Pack seems to be faster than the combination of .chr and join, which is a nice side-effect, as I'm running simulations in ruby, and they takes aeons of time (well, nearly a week). Don't ask me why I'm using ruby, it just sort of happened ;), and the code is only 160 lines, which compares favorably to the C ancestor of this simulation (which did more or less the same in 4000 lines) irb(main):017:0> time = Time.new ; 1000.times {string = Array.new(1000) { rand(26) + 97 }.pack("c*")} ; puts Time.new - time 0.184389 => nil irb(main):018:0> time = Time.new ; 1000.times {string = Array.new(1000) { (rand(26) + 97).chr }.join} ; puts Time.new - time 0.330891 => nil -- Posted via http://www.ruby-forum.com/.