Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/choose-randomly-by-ratio
Choose randomly a value by ratio
https://github.com/kjirou/choose-randomly-by-ratio
Last synced: 12 days ago
JSON representation
Choose randomly a value by ratio
- Host: GitHub
- URL: https://github.com/kjirou/choose-randomly-by-ratio
- Owner: kjirou
- License: mit
- Created: 2015-03-10T05:59:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:49:06.000Z (about 3 years ago)
- Last Synced: 2024-10-01T12:47:08.862Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# choose-randomly-by-ratio
[![npm version](https://badge.fury.io/js/choose-randomly-by-ratio.svg)](http://badge.fury.io/js/choose-randomly-by-ratio)
[![Build Status](https://travis-ci.org/kjirou/choose-randomly-by-ratio.svg?branch=master)](https://travis-ci.org/kjirou/choose-randomly-by-ratio)Choose randomly a value by ratio from collection
## Usage
```
var chooseRandomlyByRatio = require('choose-randomly-by-ratio');// This value will be 'x'(1.0/4.5) or 'y'(1.5/4.5) or 'z'(2.0/4.5)
var value = chooseRandomlyByRatio([['x', 1], ['y', 1.5], ['z', 2]]);// It's possible to write like this
var value = chooseRandomlyByRatio({ x: 1, y: 1.5, z: 2 });
```## Installation
```
npm install choose-randomly-by-ratio
```Or, you can use in browser through the [browserify](https://github.com/substack/node-browserify).