Sha256: c99a2a53ffe66e365fccf05797173ce030b92c7296d73650f2db0dc9d224a626

Contents?: true

Size: 916 Bytes

Versions: 8

Compression:

Stored size: 916 Bytes

Contents

// Original code adapted from Robert Kieffer.
// details at https://github.com/broofa/node-uuid
(function() {
  var _global = this;

  var mathRNG, whatwgRNG;

  // NOTE: Math.random() does not guarantee "cryptographic quality"
  mathRNG = function(size) {
    var bytes = new Array(size);
    var r;

    for (var i = 0, r; i < size; i++) {
      if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
      bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;
    }

    return bytes;
  }

  // currently only available in webkit-based browsers.
  if (_global.crypto && crypto.getRandomValues) {
    var _rnds = new Uint32Array(4);
    whatwgRNG = function(size) {
      var bytes = new Array(size);
      crypto.getRandomValues(_rnds);

      for (var c = 0 ; c < size; c++) {
        bytes[c] = _rnds[c >> 2] >>> ((c & 0x03) * 8) & 0xff;
      }
      return bytes;
    }
  }

  module.exports = whatwgRNG || mathRNG;

}())

Version data entries

8 entries across 6 versions & 3 rubygems

Version Path
snowball-0.1.22 node_modules/browserify/node_modules/crypto-browserify/rng.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/rng.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/rng.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/browser-resolve/node_modules/crypto-browserify/rng.js
sprockets-browserify-0.1.2 node_modules/browserify/node_modules/crypto-browserify/rng.js
sprockets-browserify-0.1.2 node_modules/module-deps/node_modules/browser-resolve/node_modules/crypto-browserify/rng.js
sprockets-browserify-0.1.0 node_modules/module-deps/node_modules/browser-resolve/node_modules/crypto-browserify/rng.js
sprockets-browserify-0.1.0 node_modules/browserify/node_modules/crypto-browserify/rng.js