From: Adam Prescott Date: 2011-05-11T10:41:22+09:00 Subject: Re: Generate random string matching specific pattern and length --20cf304271c8fcf4b404a2f628f5 Content-Type: text/plain; charset=UTF-8 On Tue, May 10, 2011 at 10:12 PM, Adam Prescott wrote: > characters = ("A".."Z").to_a + ("a".."z").to_a # there is a shortcut to > this in 1.9, but it escapes me. > characters << "-" > > 10.times.map { a << b.sample } > To rectify this abomination, it comes from two ways: a = [] # this was the b: characters = ("A".."Z").to_a + ("a".."z").to_a characters << "-" 10.times { a << characters.sample } a.join("") or characters = ("A".."Z").to_a + ("a".."z").to_a characters << "-" 10.times.map { characters.sample }.join("") --20cf304271c8fcf4b404a2f628f5--