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" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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) -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Fri, 14 Mar 2008, Aaron Brown wrote:> > 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 > bunuritoYou''d better trademark that last one before Taco Bell gets hold of it :-) David -- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS, April 14-17 2008, New York City CORE RAILS, June 24-27 2008, London (Skills Matter) See http://www.rubypal.com for details. Berlin dates coming soon! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 14, 2008, at 8:24 PM, 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"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 -- PA. http://alt.textdrive.com/nanoki/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 14, 2008, at 8:24 PM, 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"Also, if you like overkill, ''yould'' is kind of fun: http://ygingras.net/yould -- http://alt.textdrive.com/nanoki/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 14, 7:24 pm, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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"In addition to the other suggestions, apg (http://www.adel.nursat.kz/ apg/) is worth a look. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---