ruby脚本,随机生成复杂密码

作者: baibaluo
发布时间:2015-08-10 15:42:37

简单版本:

base_char = (32..126).map{|i|i.chr} - ["'",'"'," ", "`","\\"]
puts (1..16).map{base_char[rand(base_char.length)]}.join

复杂版本:

#工具脚本,快速生成随机密码

base_char=[]
#定义密码基础字符集
base_char += ('0'..'9').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

 

标签: Ruby
来源:http://www.cnblogs.com/baibaluo/p/4589554.html

推荐: