Created
September 7, 2017 21:04
-
-
Save pachun/8ee48cdb72c62ea6f708e6f76f7d5cd9 to your computer and use it in GitHub Desktop.
Generate a random string of a given length (editable character set)
This file contains hidden or 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
| if ARGV[0].to_i == 0 || ARGV[0].to_i == nil | |
| puts "usage: ruby random.rb [random string length (integer)]" | |
| return -1 | |
| end | |
| o = [('a'..'z'), ('A'..'Z'), (1...9), ('!'..'/')].map(&:to_a).flatten | |
| string = (0...ARGV[0].to_i).map { o[rand(o.length)] }.join | |
| puts "random: #{string}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment