brorand
Advanced tools
Comparing version 1.0.8 to 1.0.9
21
index.js
@@ -19,2 +19,10 @@ var r; | ||
// Emulate crypto API using randy | ||
Rand.prototype._rand = function _rand(n) { | ||
var res = new Uint8Array(n); | ||
for (var i = 0; i < res.length; i++) | ||
res[i] = this.rand.getByte(); | ||
return res; | ||
}; | ||
if (typeof self === 'object') { | ||
@@ -43,8 +51,8 @@ if (self.crypto && self.crypto.getRandomValues) { | ||
} | ||
} | ||
if (Rand.prototype._rand === undefined) { | ||
} else { | ||
// Node.js or Web worker with no crypto support | ||
try { | ||
var crypto = require('crypto'); | ||
if (typeof crypto.randomBytes !== 'function') | ||
throw new Error('Not supported'); | ||
@@ -55,10 +63,3 @@ Rand.prototype._rand = function _rand(n) { | ||
} catch (e) { | ||
// Emulate crypto API using randy | ||
Rand.prototype._rand = function _rand(n) { | ||
var res = new Uint8Array(n); | ||
for (var i = 0; i < res.length; i++) | ||
res[i] = this.rand.getByte(); | ||
return res; | ||
}; | ||
} | ||
} |
{ | ||
"name": "brorand", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Random number generator for browsers and node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3463
61