Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4223
| From | Adam Prescott <adam@aprescott.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Generate random string matching specific pattern and length |
| Date | 2011-05-10 20:41 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <BANLkTimFnGhsk1-L=_Wz-R6vQBMd3qJGHA@mail.gmail.com> (permalink) |
| References | <BANLkTimBHzkQmhhBAb7EEX7WjXc+xzfURQ@mail.gmail.com> <BANLkTinoFJhRF8zq_AAaPkUx5OHKyakcGA@mail.gmail.com> |
[Note: parts of this message were removed to make it a legal post.]
On Tue, May 10, 2011 at 10:12 PM, Adam Prescott <adam@aprescott.com> 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("")
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generate random string matching specific pattern and length Kevin <darkintent@gmail.com> - 2011-05-10 15:56 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 16:12 -0500
Re: Generate random string matching specific pattern and length 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-10 16:20 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 16:24 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 20:41 -0500
Re: Generate random string matching specific pattern and length Robert Klemme <shortcutter@googlemail.com> - 2011-05-11 02:11 -0500
Re: Generate random string matching specific pattern and length Chris Hulan <chris.hulan@gmail.com> - 2011-05-11 07:50 -0700
Re: Generate random string matching specific pattern and length Kevin <darkintent@gmail.com> - 2011-05-16 21:47 -0500
csiph-web