Module: Core::Random

Defined in:
lib/svcbase/random.rb

Overview

random id helpers

Class Method Summary collapse

Class Method Details

.base64_id(bytes) ⇒ Object



18
19
20
# File 'lib/svcbase/random.rb', line 18

def self.base64_id(bytes)
  Base64.strict_encode64(SecureRandom.random_bytes(bytes))
end

.number(max_plus_one) ⇒ Object

generate an integer i such that 0 <= i < max_plus_one



27
28
29
# File 'lib/svcbase/random.rb', line 27

def self.number(max_plus_one)
  SecureRandom.random_number(max_plus_one)
end

.short_idObject



10
11
12
# File 'lib/svcbase/random.rb', line 10

def self.short_id
  ShortUUID.shorten(SecureRandom.uuid)
end

.urlsafe_base64_id(bytes) ⇒ Object



22
23
24
# File 'lib/svcbase/random.rb', line 22

def self.urlsafe_base64_id(bytes)
  Base64.urlsafe_encode64(SecureRandom.random_bytes(bytes), padding: false)
end

.uuidObject



14
15
16
# File 'lib/svcbase/random.rb', line 14

def self.uuid
  SecureRandom.uuid
end