From: 7stud -- Date: 2011-05-11T06:20:00+09:00 Subject: Re: Generate random string matching specific pattern and length Adam Prescott wrote in post #997841: > 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-]/. Of course with all your misnamed/non-existent variables, that code won't run. Atrocious. -- Posted via http://www.ruby-forum.com/.