#conding:utf-8

#生成只有数字的随机码可控制长度
def random_int(len)
  newpass = ""
  1.upto(len){ |i| newpass << rand(10).to_s}
  return newpass
end
#生成有数字和字母组成的随机数 长度可控
def random_int_str(len)
  chars = ("a".."z").to_a+ ("A".."Z").to_a + ("0".."9").to_a
  newpass = ""
  len.times{
    newpass << chars[rand(chars.size-1)]
  }
  return newpass
end
data = random_int_str(8)
data_int = random_int(8)
p data
p data_int

05-11 15:08