Skip to content

Instantly share code, notes, and snippets.

@pachun
Created September 7, 2017 21:04
Show Gist options
  • Select an option

  • Save pachun/8ee48cdb72c62ea6f708e6f76f7d5cd9 to your computer and use it in GitHub Desktop.

Select an option

Save pachun/8ee48cdb72c62ea6f708e6f76f7d5cd9 to your computer and use it in GitHub Desktop.
Generate a random string of a given length (editable character set)
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