Random strings

I would like to know how to obtain random string of 8 characters, and if
it possible, obtaining readable strings. For example, I would like to
obtain strings like "chocoles" and not string like "akgudyfn"

John Smith wrote:

I would like to know how to obtain random string of 8 characters, and if
it possible, obtaining readable strings. For example, I would like to
obtain strings like "chocoles" and not string like "akgudyfn"
  

As for a purely random string, I've got this in my lib directory...

class String
  class << self
    def random(opts = {})
      if opts[:character_set]
        chars = opts[:character_set]
      else
        chars = ("a".."z").to_a unless opts[:lowercase] == false
        chars += ("A".."Z").to_a if opts[:uppercase]
        chars += ("0".."9").to_a if opts[:alphanumeric]
        chars += opts[:additional_character_set] if opts[:additional_character_set]
      end
      newstr = ""
      1.upto(opts[:length] || 42) { |i| newstr << chars[rand(chars.size-1)] }
      return newstr
    end
  end
end

which lets me call

x = String.random(:length => 42)

John Smith wrote:

I would like to know how to obtain random string of 8 characters, and if
it possible, obtaining readable strings. For example, I would like to
obtain strings like "chocoles" and not string like "akgudyfn"

As soon as you try to accomplish readability you sacrifice a lot of randomness. If you're willing to make that compromise, would this work?

Define two arrays, one of vowels and one of consonants. Then generate 8-letter words by choosing a random consonant, then a vowel, then... [do 4.times]. That would give you words like:

jerotowe
bunurito

...and so on.

You could try to add double-consonant sounds like ch, th, sh, but that would make your letter count more tricky.

  - Aaron

Hi --

Take a look at Bubble Babble or RFC 1751:

http://en.wikipedia.org/wiki/Bubble_Babble
http://www.faqs.org/rfcs/rfc1751.html

Watch out for, errr, unexpected results though:

http://blog.extracheese.org/2007/12/human-readable-encryption-keys.html

Also, if you like overkill, 'yould' is kind of fun:

http://ygingras.net/yould

In addition to the other suggestions, apg (http://www.adel.nursat.kz/
apg/) is worth a look.

Fred