Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

random-bool

mock-end1.1kMIT1.0.2

Return a random boolean value (true or false).

bool, boolean, generator, generate, random, randomly, randomize, chance, test, dice, mock

readme

random-bool

Return a random boolean value (true or false).

MIT License

build:? coverage:?

Install

$ npm install --save random-bool 

Usage

For more use-cases see the tests.

var randomBool = require('random-bool');

// API
// - randomBool([options])

// options
// - likelihood

The default likelihood of success (returning true) is 50%:

randomBool(); 
// => true

Can optionally specify the likelihood in percent:

randomBool({ likelihood: 30 });
// => false

In this case only a 30% likelihood of true, and a 70% likelihood of false.

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.