Last active
February 17, 2016 18:23
-
-
Save zunda/c4bbf8d90bfd3c679e44 to your computer and use it in GitHub Desktop.
ふっかつのじゅもん生成器。最初のusableに使える文字を配列として与えるとパスフレーズ生成器にもなるよ
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
#/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
上位の桁が0の可能性を考えると「ぁ」の出現確率が低くなっちゃうな…というわけで修正しました