random-binary
v1.0.3
Published
Return a random binary number.
Downloads
21
Maintainers
Readme
random-binary
Return a random binary number.
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
- random-integral - Return a random integer.
- random-natural - Return a random natural number.
- random-decimal - Return a random decimal.
- random-floating - Return a random floating point number.
- random-index - Return a random array-like index.
- random-octal - Return a random octal number.
- random-hexadecimal - Return a random hexadecimal number.
- random-unicode - Return a random unicode.
- random-bool - Return a random boolean (true/false).
- random-char - Return a random char.
Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.