Skip to content

Repository files navigation

random-bytes

NPM VersionNPM DownloadsNode.js VersionBuild StatusTest Coverage

Generate strong pseudo-random bytes.

This module is a simple wrapper around the Node.js core crypto.randomBytes API, with the following additions:

  • A Promise interface for environments with promises.
  • For Node.js versions that do not wait for the PRNG to be seeded, this module will wait a bit.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install random-bytes

API

varrandomBytes=require('random-bytes')

randomBytes(size, callback)

Generates strong pseudo-random bytes. The size argument is a number indicating the number of bytes to generate.

randomBytes(12,function(error,bytes){if(error)throwerror// do something with the bytes})

randomBytes(size)

Generates strong pseudo-random bytes and return a Promise. The size argument is a number indicating the number of bytes to generate.

Note: To use promises in Node.js prior to 0.12, promises must be "polyfilled" using global.Promise = require('bluebird').

randomBytes(18).then(function(string){// do something with the string})

randomBytes.sync(size)

A synchronous version of above.

varbytes=randomBytes.sync(18)

License

MIT

About

Generate strong pseudo-random bytes

Topics

Resources

Stars

29 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages