# random-choice

> Get a weighted random item from an array

Latest version **1.0.0** (published 2019-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-choice
pnpm add random-choice
yarn add random-choice
bun add random-choice
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-02-11 |
| First published | 2019-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | David Carew |
| Maintainers | carewdavid |
| Keywords | random, rand, array, item, pick, weighted |

## Links

- npm: https://www.npmjs.com/package/random-choice
- Repository: https://github.com/carewdavid/random-choice
- Homepage: https://github.com/carewdavid/random-choice#readme
- Issues: https://github.com/carewdavid/random-choice/issues
- npm.io page: https://npm.io/package/random-choice

## Recent versions

- 1.0.0 (latest) — 2019-02-11

## README

# random-choice

>Get a random item from an array with a weighted probablility

## Install
```
$ npm install random-choice
```

## Usage
```js
const randomChoice = require('random-choice');

//Give relative wqeights for the items in your array
randomChoice(['apple', 'orange', 'banana'], [.50, .25, .25]);
//=> 'apple'

//Integer ratios work too
randomChoice(['apple', 'orange', 'banana'], [2, 1, 1]);
//=> 'apple'
```

## License
MIT

---
_Source: https://npm.io/package/random-choice · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
