Module: Stringent
- Defined in:
- lib/stringent.rb
Constant Summary collapse
- TABLE =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.freeze
Class Method Summary collapse
Class Method Details
.generate(entropy: 256, table: TABLE) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/stringent.rb', line 6 def self.generate(entropy: 256, table: TABLE) number = SecureRandom.random_number(2 ** entropy) length = (entropy / Math.log2(table.size)).ceil Array.new(length) { number, modulo = number.divmod(table.size) table[modulo] }.join end |