@js-random/boolean
v0.3.5
Published
A simple and lightweight boolean randomizer for JavaScript (TypeScript friendly)
Downloads
8
Maintainers
Readme
@js-random/boolean
A simple and lightweight boolean randomizer for JavaScript (TypeScript friendly)
Installation
npm i -S @js-random/boolean
Usage
commonjs:
var randomBoolean = require('@js-random/boolean').default;
TS/ES6+:
import randomBoolean from '@js-random/boolean';
<script> tag
:
<script src="https://unpkg.com/@js-random/boolean"></script>
var boolean = randomBoolean(); // from 0 to 100 (inclusive)
var fromTwoToTen = randomBoolean(2, 10); // random boolean from `2` to `10` (inclusive)
Global version
This package also has a global version, which introduces side-effects by exposing the api as Boolean.random()
function.
Import
commonjs:
require('@js-random/boolean/lib/global');
ES6+:
import '@js-random/boolean/module/global';
TS:
import '@js-random/boolean/module/global';
<script> tag
<script src="https://unpkg.com/@js-random/boolean/unpkg/global"></script>
Usage
var boolean = Boolean.random(); // `true` or `false`
var probablyTrue = Boolean.random(0.99); // 99% chance of getting `true`
Other packages
Please, have a look at other packages from @js-random
series:
@js-random/all
- all the randomizers in one package - GitHub repo, NPM@js-random/number
GitHub repo, NPM@js-random/string
GitHub repo, NPM@js-random/date
GitHub repo, NPM