Created
September 12, 2014 05:00
-
-
Save nawada/82d04b5e9d0fec0c8fb9 to your computer and use it in GitHub Desktop.
ASCIIコード範囲内でのランダム文字列出力
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
# encoding: utf-8 | |
totalLength = 10 # 出力桁数 | |
symbolLen = 0 # 記号の出力桁数 | |
numericLen = 3 # 数字の出力桁数 | |
symbols = (("!".."/").to_a + (":".."@").to_a + ("[".."`").to_a + ("{".."~").to_a) | |
numerics = (0..9).to_a | |
upperAlpha = ("A".."Z").to_a | |
lowerAlpha = ("a".."z").to_a | |
# アルファベットで使える文字数 | |
alphaLen = totalLength - (symbolLen + numericLen) | |
symbols = symbols.sample(symbolLen) | |
numerics = numerics.sample(numericLen) | |
alpha = (upperAlpha + lowerAlpha).sample(alphaLen) | |
puts (symbols + numerics + alpha).shuffle.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment