https://github.com/cellular/variation
Utility functions to pick random values 🎲
https://github.com/cellular/variation
Last synced: about 1 year ago
JSON representation
Utility functions to pick random values 🎲
- Host: GitHub
- URL: https://github.com/cellular/variation
- Owner: cellular
- Created: 2018-06-04T13:09:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-04T13:14:21.000Z (about 8 years ago)
- Last Synced: 2025-02-15T11:19:46.924Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Variation 🎲
[](https://travis-ci.org/cellular/variation)
Utility functions to add variations to any kind of output.
## Usage Example
```js
const { random, chance, randomItem } = require('variation');
console.log(
random('hello', 'ciao', 'hola', 'salut'),
chance(0.5, 'beautiful'),
randomItem(['world', 'people'])
);
```
## API
#### Table of Contents
- [random](#random)
- [randomItem](#randomitem)
- [chance](#chance)
### random
Returns a random argument.
**Parameters**
- `args` **...any**
### randomItem
Returns a random item from the given array.
**Parameters**
- `array` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<any>**
### chance
Returns `value` with the given probability, `false` otherwise.
**Parameters**
- `probability` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** (optional, default `0.5`)
- `value` **any** (optional, default `true`)
# License
MIT