Last active
June 14, 2016 06:13
-
-
Save momota/4780232 to your computer and use it in GitHub Desktop.
ランダムな文字列生成用。一時的なパスワードなど。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# conding: utf-8 | |
def random_string( length ) | |
str = ('a'..'z').to_a + ('A'..'Z').to_a + | |
('0'..'9').to_a + ['-', '+', '_', '@', '=', '&', '$', '#', '?'] | |
Array.new( length ){ str[rand( str.size )] }.join | |
end | |
# ------------------------------------------------------------------- | |
# main | |
if __FILE__ == $0 | |
length = 15 # default length | |
length = ARGV[0].to_i if ARGV[0].to_i != 0 | |
puts random_string( length ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment