Module: SecureRandom

Extended by:
Random::Formatter
Defined in:
opal/stdlib/securerandom.rb

Class Method Summary collapse

Class Method Details

.bytes(bytes = nil) ⇒ Object



51
52
53
# File 'opal/stdlib/securerandom.rb', line 51

def self.bytes(bytes = nil)
  gen_random(bytes)
end

.gen_random(count = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'opal/stdlib/securerandom.rb', line 55

def self.gen_random(count = nil)
  count = Random._verify_count(count)
  out = ''
  %x{
    var bytes = gen_random_bytes(#{count});
    for (var i = 0; i < #{count}; i++) {
      out += String.fromCharCode(bytes[i]);
    }
  }
  out.encode('ASCII-8BIT')
end