3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 Generate strong pseudo-random bytes.
11 This module is a simple wrapper around the Node.js core `crypto.randomBytes` API,
12 with the following additions:
14 * A `Promise` interface for environments with promises.
15 * For Node.js versions that do not wait for the PRNG to be seeded, this module
21 $ npm install random-bytes
27 var randomBytes = require('random-bytes')
30 ### randomBytes(size, callback)
32 Generates strong pseudo-random bytes. The `size` argument is a number indicating
33 the number of bytes to generate.
36 randomBytes(12, function (error, bytes) {
37 if (error) throw error
38 // do something with the bytes
44 Generates strong pseudo-random bytes and return a `Promise`. The `size` argument is
45 a number indicating the number of bytes to generate.
47 **Note**: To use promises in Node.js _prior to 0.12_, promises must be
48 "polyfilled" using `global.Promise = require('bluebird')`.
51 randomBytes(18).then(function (string) {
52 // do something with the string
56 ### randomBytes.sync(size)
58 A synchronous version of above.
61 var bytes = randomBytes.sync(18)
68 [npm-image]: https://img.shields.io/npm/v/random-bytes.svg
69 [npm-url]: https://npmjs.org/package/random-bytes
70 [node-version-image]: https://img.shields.io/node/v/random-bytes.svg
71 [node-version-url]: http://nodejs.org/download/
72 [travis-image]: https://img.shields.io/travis/crypto-utils/random-bytes/master.svg
73 [travis-url]: https://travis-ci.org/crypto-utils/random-bytes
74 [coveralls-image]: https://img.shields.io/coveralls/crypto-utils/random-bytes/master.svg
75 [coveralls-url]: https://coveralls.io/r/crypto-utils/random-bytes?branch=master
76 [downloads-image]: https://img.shields.io/npm/dm/random-bytes.svg
77 [downloads-url]: https://npmjs.org/package/random-bytes