1.0.3 • Published 8 years ago

random-binary v1.0.3

Weekly downloads
289
License
MIT
Repository
github
Last release
8 years ago

random-binary

Return a random binary number.

MIT License

build:? coverage:?

Install

$ npm install --save random-binary 

Usage

For more use-cases see the tests

var randomBinary = require('random-binary');

// API
// - randomBinary([bit]);
// - randomBinary([options]);

By default, the bit length is randomly between 0 and 256:

randomBinary();     
// => 11010000101111010101011010101100

Can optionally specify a bit length and the result will be exactly that length:

randomBinary(4); // or
randomBinary({ bit: 4 });
// => 0111

randomBinary(8); // or
randomBinary({ bit: 8 });
// => 11011111

randomBinary(16); // or
randomBinary({ bit: 16 });
// => 0101100001110000

Note: the bit should between 0 and 256.

Related

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.