From: Brian Candler Date: 2010-10-22T00:27:05+09:00 Subject: Re: generating random argument lists Robert Klemme wrote in post #956028: >> arrays = (1..rand(10)).map { (1..rand(5).map { rand(4)) } } > > It seems there is a bracket misalignment. :-) Sorry, I corrected it in irb but forgot to paste it back into the message I was composing. arrays = (1..rand(10)).map { (1..rand(5)).map { rand(4) } } >> That also gives between 0 and 9 arrays, each with between 0 and 4 >> elements, each element being between 0 and 3. > > Note that rand(x) can return 0 so it would be more natural to start > ranges at 0 IMHO. I did that originally, but (0..0).map { ... } gives a one-element array, and I wanted to have empty arrays too. You can omit the far end with (0...0), but then (0...rand(5)) gives between 0 and 3, which is even more confusing IMO. > Another version with less brackets especially around ranges where I > find them ugly: > > arrays = rand(10).times.map { rand(5).times.map { rand 4 } } I'm an old fogey and avoid avoid 1.8.7-isms :-) -- Posted via http://www.ruby-forum.com/.