pax_global_header00006660000000000000000000000064130534023700014507gustar00rootroot0000000000000052 comment=ddc4f9344287769d7e2c2ea987d26bbeec5456b4 brorand-1.1.0/000077500000000000000000000000001305340237000131355ustar00rootroot00000000000000brorand-1.1.0/.gitignore000066400000000000000000000000341305340237000151220ustar00rootroot00000000000000node_modules/ npm-debug.log brorand-1.1.0/README.md000066400000000000000000000021521305340237000144140ustar00rootroot00000000000000# Brorand #### LICENSE This software is licensed under the MIT License. Copyright Fedor Indutny, 2014. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. brorand-1.1.0/index.js000066400000000000000000000027461305340237000146130ustar00rootroot00000000000000var r; module.exports = function rand(len) { if (!r) r = new Rand(null); return r.generate(len); }; function Rand(rand) { this.rand = rand; } module.exports.Rand = Rand; Rand.prototype.generate = function generate(len) { return this._rand(len); }; // Emulate crypto API using randy Rand.prototype._rand = function _rand(n) { if (this.rand.getBytes) return this.rand.getBytes(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') { if (self.crypto && self.crypto.getRandomValues) { // Modern browsers Rand.prototype._rand = function _rand(n) { var arr = new Uint8Array(n); self.crypto.getRandomValues(arr); return arr; }; } else if (self.msCrypto && self.msCrypto.getRandomValues) { // IE Rand.prototype._rand = function _rand(n) { var arr = new Uint8Array(n); self.msCrypto.getRandomValues(arr); return arr; }; // Safari's WebWorkers do not have `crypto` } else if (typeof window === 'object') { // Old junk Rand.prototype._rand = function() { throw new Error('Not implemented yet'); }; } } 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'); Rand.prototype._rand = function _rand(n) { return crypto.randomBytes(n); }; } catch (e) { } } brorand-1.1.0/package.json000066400000000000000000000012161305340237000154230ustar00rootroot00000000000000{ "name": "brorand", "version": "1.1.0", "description": "Random number generator for browsers and node.js", "main": "index.js", "scripts": { "test": "mocha --reporter=spec test/**/*-test.js" }, "repository": { "type": "git", "url": "git@github.com:indutny/brorand" }, "keywords": [ "Random", "RNG", "browser", "crypto" ], "author": "Fedor Indutny ", "license": "MIT", "bugs": { "url": "https://github.com/indutny/brorand/issues" }, "homepage": "https://github.com/indutny/brorand", "devDependencies": { "mocha": "^2.0.1" }, "browser": { "crypto": false } } brorand-1.1.0/test/000077500000000000000000000000001305340237000141145ustar00rootroot00000000000000brorand-1.1.0/test/api-test.js000066400000000000000000000003121305340237000161740ustar00rootroot00000000000000var brorand = require('../'); var assert = require('assert'); describe('Brorand', function() { it('should generate random numbers', function() { assert.equal(brorand(100).length, 100); }); });