Class: PublicUid::Generators::HexStringSecureRandom
- Inherits:
-
Object
- Object
- PublicUid::Generators::HexStringSecureRandom
- Defined in:
- lib/public_uid/generators/hex_string_secure_random.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(length = 8) ⇒ HexStringSecureRandom
constructor
A new instance of HexStringSecureRandom.
Constructor Details
#initialize(length = 8) ⇒ HexStringSecureRandom
Returns a new instance of HexStringSecureRandom.
6 7 8 |
# File 'lib/public_uid/generators/hex_string_secure_random.rb', line 6 def initialize(length=8) @length = length end |
Instance Method Details
#generate ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/public_uid/generators/hex_string_secure_random.rb', line 10 def generate if @length.odd? result = SecureRandom.hex( (@length+1)/2 ) #because in "SecureRandom.hex(@length)" @length means length in bytes = 2 hexadecimal characters return result[0...-1] else SecureRandom.hex(@length/2) end end |