LoginSignup
5
4

More than 5 years have passed since last update.

Rubyでランダムなパスワードを生成する(サンプル)

Last updated at Posted at 2017-03-14

Rubyでランダムなパスワードを生成する

ランダムなパスワードを生成するサンプル。

randompwd.rb
#!/usr/bin/env ruby

#パスワードに利用する文字の一覧
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/!$%&'()=~|@`[]{}*+<>?_;:,.\\\""
len = chars.length
#とりあえず10文字
10.times do
  pos = rand(0..len-1)
  print chars[pos]
end

Python3版のサンプルはこちら

5
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4