Random strings

Posted by root Tue, 19 Aug 2008 13:06:00 GMT

module Kernel
  def random_uc(size=16)
    Array.new(size){ rand(26)+65 }.pack('C*')
  end
  def random_lc(size=16)
    Array.new(size){ rand(26)+97 }.pack('C*')
  end
  def random_num(size=16)
    Array.new(size){ rand(10) }.join
  end
end

random_uc => "HRTWYJBJEZDKYPTJ"
random_lc => "onxkvkezqukspmcx"
random_num => "5862195932579950"

Posted in  | Tags  | no comments | no trackbacks

Comments

Trackbacks

Use the following link to trackback from your own site:
http://www.vidul.com/articles/trackback/79

Comments are disabled