'use strict';
(function() {
  var g = ('undefined' === typeof window ? global : window) || {}
  var _crypto = (
    g.crypto || g.msCrypto || require('crypto')
  )
  module.exports = function(size) {
    // Modern Browsers
    if(_crypto.getRandomValues) {
      var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array
      /* This will not work in older browsers.
       * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
       */

      _crypto.getRandomValues(bytes);
      return bytes;
    }
    else if (_crypto.pseudoRandomBytes) {
      return _crypto.pseudoRandomBytes(size)
    }
    else
      throw new Error(
        'pseudo random number generation not yet implemented for this browser\n'+
        'use chrome, FireFox or Internet Explorer 11'
      )
  }
}())
