Module: SecureRandom

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

Class Method Summary collapse

Class Method Details

.bytes(bytes = nil) ⇒ Object



53
54
55
# File 'opal/stdlib/securerandom.rb', line 53

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

.gen_random(count = nil) ⇒ Object



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

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