# weighted-random-object

> Get a weighted random object from an array of objects.

Latest version **1.0.8** (published 2019-06-04) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install weighted-random-object
pnpm add weighted-random-object
yarn add weighted-random-object
bun add weighted-random-object
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2019-06-04 |
| First published | 2015-11-11 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | separate (@types/weighted-random-object) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 36.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Just Thomas Hiorth Misund |
| Maintainers | misund |
| Keywords | simple, random, weighted, weights |

## Links

- npm: https://www.npmjs.com/package/weighted-random-object
- Repository: https://github.com/misund/weighted-random-object
- npm.io page: https://npm.io/package/weighted-random-object

## Recent versions

- 1.0.8 (latest) — 2019-06-04
- 1.0.7 — 2017-02-19
- 1.0.6 — 2015-11-11
- 1.0.5 — 2015-11-11
- 1.0.4 — 2015-11-11
- 1.0.3 — 2015-11-11
- 1.0.2 — 2015-11-11
- 1.0.1 — 2015-11-11
- 1.0.0 — 2015-11-11

## README

# weighted-random-object
Get a weighted random object from an array of objects with a weight property.

The objects should have a property with key 'weight' and a numerical value.

# Usage
```js
var weightedRandomObject = require("weighted-random-object");

var fruitBasket = [
    {
        "type": "apple",
        "weight": 33
    }, {
        "type": "pear",
        "weight": 66
    }
];

var fruit = weightedRandomObject(fruitBasket);

console.log(fruit.type); // sometimes 'apple', more often 'pear'
```

## Contributing
I appreciate your issues and PRs [on Github](https://github.com/misund/weighted-random-object)!

### Testing
```
yarn build && yarn test
```

### Releasing
This project uses [np](https://github.com/sindresorhus/np).
1. Make sure your changes are in master
2. Run `yarn release`
3. Follow the interactive release guide

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