weighted-random-object
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/weighted-random-object package

1.0.8 • Public • Published

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

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!

Testing

yarn build && yarn test

Releasing

This project uses np.

  1. Make sure your changes are in master
  2. Run yarn release
  3. Follow the interactive release guide

Package Sidebar

Install

npm i weighted-random-object

Weekly Downloads

342

Version

1.0.8

License

GPL-3.0

Unpacked Size

37.3 kB

Total Files

7

Last publish

Collaborators

  • misund