From: Adam Prescott Date: 2011-05-11T06:12:31+09:00 Subject: Re: Generate random string matching specific pattern and length --90e6ba613ac0e7557404a2f26968 Content-Type: text/plain; charset=UTF-8 On Tue, May 10, 2011 at 9:56 PM, Kevin wrote: > I'm trying to generate a random set of strings to fill a database with that > match the following pattern: /^([A-Z]|[a-z]|-)+$/ > > The array I'm trying to create must contain strings that look like > "A12-34-4567" and be exactly ten characters long How's this? 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 } Sure there's a quicker way. By the way, /[A-Z|[a-z]|-/ is equivalent to /[A-Za-z-]/. --90e6ba613ac0e7557404a2f26968--