Create a gist now

Instantly share code, notes, and snippets.

ふっかつのじゅもん生成器。最初のusableに使える文字を配列として与えるとパスフレーズ生成器にもなるよ
#/usr/bin/ruby
usable = (''..'').to_a + ['', '']
class Integer
def stringify(chars, min_digits = nil)
i = 0
d = chars.size
x = self.abs
r = ''
begin
x, c = x.divmod(d)
r << chars[c]
i += 1
end while x > 0 or (min_digits and i < min_digits)
return (self < 0 ? '-' : '') + r.reverse
end
end
n = Integer(ARGV.shift || 16)
puts rand(usable.size**n).stringify(usable, n)
@zunda
Owner
zunda commented Feb 16, 2016

上位の桁が0の可能性を考えると「ぁ」の出現確率が低くなっちゃうな…というわけで修正しました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment