jeudi 5 mai 2016

Generating random URL with real words

I've written a little script that will generate a random URL, it works, however I would like the generated URL to be somewhat believable, meaning I want it to generate real words. As of now it generates 7 random characters and digits.

def generate_url(length=7)
  protocall = %w(https:// http://)
  body = rand(36**length).to_s(36)
  num = rand(1..999).to_s
  url = "#{protocall.sample.to_s}#{body}.com/php?id=#{num}"
  puts url
end

#<= http://ift.tt/1SOT9G5
#<= http://ift.tt/1T0qvAp
#<= http://ift.tt/1SOTc4z

So what I'm looking for is an easier way to do this with real words in place of the random 7 character string (please keep it between 7 and 10 characters) without using an external gem

My OS is Windows 7




Aucun commentaire:

Enregistrer un commentaire