昨日のやつを Ruby でもやってみた。
# coding: utf-8
def randstr(length)
pool = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
r = Random.new
l = pool.size
rand_str = ''
length.times do |i|
rand_str += pool[r.rand(l)]
end
rand_str
end
length = ARGV.shift.to_i
print randstr(length)
実行結果:
^o^ > random_string.rb 20 y397x9Bx1z7fAvJTr9RK
Random クラスの使い方はここ: