An open API service indexing awesome lists of open source software.

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 🎲

Awesome Lists containing this project

README

          

# Variation 🎲

[![Build Status](https://travis-ci.org/cellular/variation.svg?branch=master)](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