random-binary

1.0.3 • Public • Published

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.

Package Sidebar

Install

npm i random-binary

Weekly Downloads

6

Version

1.0.3

License

MIT

Last publish

Collaborators

  • bubkoo