Skip to content

Instantly share code, notes, and snippets.

@zunda
Last active February 17, 2016 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zunda/c4bbf8d90bfd3c679e44 to your computer and use it in GitHub Desktop.
Save zunda/c4bbf8d90bfd3c679e44 to your computer and use it in GitHub Desktop.
ふっかつのじゅもん生成器。最初の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
Copy link
Author

zunda commented Feb 16, 2016

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

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