简单版本:
base_char = (32..126).map{|i|i.chr} - ["'",'"'," ", "`","\\"]
puts (1..16).map{base_char[rand(base_char.length)]}.join
复杂版本:
#工具脚本,快速生成随机密码 base_char=[]
#定义密码基础字符集
base_char += (''..'').to_a
base_char += ('a'..'z').to_a
base_char += ('A'..'Z').to_a
base_char += ('!'..'/').to_a
base_char.delete("'")
# puts base_char #密码长度
size = 16 #生成密码
password = (1..size).map{base_char[rand(base_char.length)]}.join puts password