{"_id":"secure-random","_rev":"4579414","name":"secure-random","description":"Normalize the creation of cryptographically strong random values.","dist-tags":{"latest":"1.1.2"},"maintainers":[{"name":"jprichardson","email":""}],"time":{"modified":"2026-04-10T15:54:50.000Z","created":"2013-11-07T15:13:28.359Z","1.1.2":"2019-05-22T22:29:13.674Z","1.1.1":"2014-06-30T21:13:39.304Z","1.1.0":"2014-06-30T21:10:41.732Z","1.0.0":"2014-06-03T18:15:54.073Z","0.2.1":"2014-03-20T22:34:03.455Z","0.2.0":"2013-12-17T06:43:27.047Z","0.1.0":"2013-12-08T20:27:52.984Z","0.0.1":"2013-11-07T15:13:28.359Z"},"users":{},"author":{"name":"JP Richardson"},"repository":{"type":"git","url":"git+https://github.com/jprichardson/secure-random.git"},"versions":{"1.1.2":{"name":"secure-random","version":"1.1.2","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","repository":{"type":"git","url":"git+https://github.com/jprichardson/secure-random.git"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"^1.20.0","terst":"^0.1.0","mochify":"^0.9.3"},"dependencies":{},"browser":{"crypto":false},"scripts":{"test":"mocha --ui bdd","unit":"mocha"},"testling":{"files":"test/*.js","browsers":["firefox/latest","chrome/latest","safari/6..latest","ie/9..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"gitHead":"7cc33e3da62afc900d31d79261bd0334b84dd595","bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"homepage":"https://github.com/jprichardson/secure-random#readme","_id":"secure-random@1.1.2","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"jprichardson","email":"jprichardson@gmail.com"},"dist":{"shasum":"ed103b460a851632d420d46448b2a900a41e7f7c","size":2725,"noattachment":false,"key":"/secure-random/-/secure-random-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-1.1.2.tgz"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/secure-random_1.1.2_1558564153568_0.9469194558256413"},"_hasShrinkwrap":false,"publish_time":1558564153674,"_cnpm_publish_time":1558564153674,"_cnpmcore_publish_time":"2021-12-16T10:18:18.784Z"},"1.1.1":{"name":"secure-random","version":"1.1.1","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"^1.20.0","terst":"^0.1.0","mochify":"^0.9.3"},"dependencies":{},"browser":{"crypto":false},"scripts":{"test":"mocha --ui bdd","unit":"mocha"},"testling":{"files":"test/*.js","browsers":["firefox/latest","chrome/latest","safari/6..latest","ie/9..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"homepage":"https://github.com/jprichardson/secure-random","_id":"secure-random@1.1.1","dist":{"shasum":"0880f2d8c5185f4bcb4684058c836b4ddb07145a","size":2718,"noattachment":false,"key":"/secure-random/-/secure-random-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-1.1.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1404162819304,"_hasShrinkwrap":false,"_cnpm_publish_time":1404162819304,"_cnpmcore_publish_time":"2021-12-16T10:18:19.031Z"},"1.1.0":{"name":"secure-random","version":"1.1.0","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"^1.20.0","terst":"^0.1.0","mochify":"^0.9.3"},"dependencies":{},"browser":{"crypto":false},"scripts":{"test":"mocha --ui bdd","unit":"mocha"},"testling":{"files":"test/*.js","browsers":["firefox/latest","chrome/latest","safari/6..latest","ie/9..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"homepage":"https://github.com/jprichardson/secure-random","_id":"secure-random@1.1.0","dist":{"shasum":"9d262431a9fca3d4aacb8ecc16084af879ce6558","size":2660,"noattachment":false,"key":"/secure-random/-/secure-random-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-1.1.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1404162641732,"_hasShrinkwrap":false,"_cnpm_publish_time":1404162641732,"_cnpmcore_publish_time":"2021-12-16T10:18:19.616Z"},"1.0.0":{"name":"secure-random","version":"1.0.0","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"^1.20.0","terst":"^0.1.0","mochify":"^0.9.3"},"dependencies":{},"browser":{"crypto":false},"scripts":{"test":"mocha --ui bdd","unit":"mocha"},"testling":{"files":"test/*.js","browsers":["firefox/latest","chrome/latest","safari/6..latest","ie/9..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"homepage":"https://github.com/jprichardson/secure-random","_id":"secure-random@1.0.0","dist":{"shasum":"9ad47d0e8189cd43f711645fa0338367c571a972","size":2616,"noattachment":false,"key":"/secure-random/-/secure-random-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-1.0.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1401819354073,"_hasShrinkwrap":false,"_cnpm_publish_time":1401819354073,"_cnpmcore_publish_time":"2021-12-16T10:18:19.825Z"},"0.2.1":{"name":"secure-random","version":"0.2.1","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"*","terst":"0.0.1"},"dependencies":{},"browser":{"crypto":false},"bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"homepage":"https://github.com/jprichardson/secure-random","_id":"secure-random@0.2.1","dist":{"shasum":"1c2f08cb94d8c06deff52721a6045bba96f85a9a","size":2005,"noattachment":false,"key":"/secure-random/-/secure-random-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-0.2.1.tgz"},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1395354843455,"_hasShrinkwrap":false,"_cnpm_publish_time":1395354843455,"_cnpmcore_publish_time":"2021-12-16T10:18:20.025Z"},"0.2.0":{"name":"secure-random","version":"0.2.0","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"*","terst":"0.0.1"},"dependencies":{},"readmeFilename":"README.md","bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"_id":"secure-random@0.2.0","dist":{"shasum":"7963a0a1969a3a03087ddbd7ce705c0e7daf3a3a","size":1994,"noattachment":false,"key":"/secure-random/-/secure-random-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-0.2.0.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1387262607047,"_hasShrinkwrap":false,"_cnpm_publish_time":1387262607047,"_cnpmcore_publish_time":"2021-12-16T10:18:20.394Z"},"0.1.0":{"name":"secure-random","version":"0.1.0","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"*","terst":"0.0.1"},"dependencies":{},"readmeFilename":"README.md","bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"_id":"secure-random@0.1.0","dist":{"shasum":"43a29ed076802ee9439c8ff8d1b8f108a69f7495","size":1977,"noattachment":false,"key":"/secure-random/-/secure-random-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-0.1.0.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1386534472984,"_hasShrinkwrap":false,"_cnpm_publish_time":1386534472984,"_cnpmcore_publish_time":"2021-12-16T10:18:20.587Z"},"0.0.1":{"name":"secure-random","version":"0.0.1","description":"Normalize the creation of cryptographically strong random values.","main":"./lib/secure-random.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"https://github.com/jprichardson/secure-random"},"keywords":["crypto","cryptography","secure","random","rand","generator","number"],"author":{"name":"JP Richardson"},"license":"MIT","devDependencies":{"mocha":"*","terst":"0.0.1"},"dependencies":{},"readmeFilename":"README.md","_id":"secure-random@0.0.1","dist":{"shasum":"622266f48b2d8f658d335d3ea8c708de675fc17b","size":1741,"noattachment":false,"key":"/secure-random/-/secure-random-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/secure-random/download/secure-random-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.17","_npmUser":{"name":"jp","email":"jprichardson@gmail.com"},"maintainers":[{"name":"jprichardson","email":""}],"directories":{},"publish_time":1383837208359,"_hasShrinkwrap":false,"_cnpm_publish_time":1383837208359,"_cnpmcore_publish_time":"2021-12-16T10:18:20.981Z"}},"readme":"secure-random\n==============\n\n[![build status](https://secure.travis-ci.org/jprichardson/secure-random.png)](http://travis-ci.org/jprichardson/secure-random)\n\n[![browser support](https://ci.testling.com/jprichardson/secure-random.png)](https://ci.testling.com/jprichardson/secure-random)\n\nA simple JavaScript component to normalize the creation of cryptographically strong random values.\n\n\nWhy?\n----\n\nContext switching between the browser and Node.js and creating cryptographically secure random numbers is annoying. This normalizes the behavior. Used by [CryptoCoinJS](http://cryptocoinjs.com) and [BitcoinJS](https://github.com/bitcoinjs/bitcoinjs-lib).\n\n\n\nInstall\n-------\n\n### Node.js/Browserify\n\n    npm install --save secure-random\n\n\n### Component\n\n    component install jprichardson/secure-random\n\n\n### Bower\n\n    bower install secure-random\n\n\n### Script\n\n```html\n<script src=\"/path/to/secure-random.js\"></script>\n```\n\n\nUsage\n-----\n\n### secureRandom(byteCount, options)\n\n- **byteCount**: is the number of bytes to return. \n- **options**: options to pass. Only valid value at this time `type`. `type` can be\neither `Array`, `Uint8Array`, or `Buffer`. `Buffer` is only valid in Node.js or \n[Browserify](https://github.com/substack/node-browserify) environments - it will throw an error otherwise.\n\n\nreturn an `Array`:\n\n```js\nvar bytes = secureRandom(10) //return an Array of 10 bytes\nconsole.log(bytes.length) //10\n```\n\nor:\n\n```js\nvar bytes = secureRandom(10, {type: 'Array'}) //return an Array of 10 bytes\nconsole.log(bytes.length) //10\n```\n\nreturn a `Buffer`:\n\n```js\nvar bytes = secureRandom(10, {type: 'Buffer'}) //return a Buffer of 10 bytes\nconsole.log(bytes.length) //10\n```\n\nreturn a `Uint8Array`:\n\n```js\nvar bytes = secureRandom(10, {type: 'Uint8Array'}) //return a Uint8Array of 10 bytes\nconsole.log(bytes.length) //10\n```\n\n### randomArray(byteCount)\n\nSugar for `secureRandom(byteCount, {type: 'Array'})`.\n\n```js\nvar secureRandom = require('secure-random')\nvar data = secureRandom.randomArray(10)\n```\n\n### randomUint8Array(byteCount)\n\nSugar for `secureRandom(byteCount, {type: 'Uint8Array'})`.\n\n```js\nvar secureRandom = require('secure-random')\nvar data = secureRandom.randomUint8Array(10)\n```\n\n### randomBuffer(byteCount)\n\nSugar for `secureRandom(byteCount, {type: 'Buffer'})`.\n\n```js\nvar secureRandom = require('secure-random')\nvar data = secureRandom.randomBuffer(10)\n```\n\nHandling Errors\n-----\n\nAn error will be thrown if a secure random number generator is not available.\n\n```javascript\nthrow new Error(\"Your browser does not support window.crypto.\")\n```\n\nReferences\n----------\n* [Node.js crypto.randomBytes()](http://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback)\n* [Node.js Buffer](http://nodejs.org/api/buffer.html)\n* [window.crypto.getRandomValues()](https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues)\n* [JavaScript typed arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)\n\n\nLicense\n-------\n\n(MIT License)\n\nCopyright 2013-2014, JP Richardson\n\n\n","_attachments":{},"homepage":"https://github.com/jprichardson/secure-random#readme","bugs":{"url":"https://github.com/jprichardson/secure-random/issues"},"license":"MIT"}