class DaFunk::SecureRandom

Constants

CHARS

Public Class Methods

random_bytes(n = nil) click to toggle source
# File lib/da_funk/secure_random.rb, line 5
def self.random_bytes(n = nil)
  n = n ? n.to_int : 16
  (0...n).map { CHARS[rand(CHARS.length)] }.join
end
uuid() click to toggle source
# File lib/da_funk/secure_random.rb, line 10
def self.uuid
  bytes = random_bytes.unpack('NnnnnN')
  bytes[2] = (bytes[2] & 0x0fff) | 0x4000
  bytes[3] = (bytes[3] & 0x3fff) | 0x8000
  "%08x-%04x-%04x-%04x-%04x%08x" % bytes
end