随机生成一个固定位数的字符串:

def newpass( len )
chars = ("a".."z").to_a + ("A".."Z").to_a + ("".."").to_a
newpass = ""
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
puts newpass(15)
05-11 20:42