Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/suretnohq/chance
Give you a result from random calculation by decimal scoring
https://github.com/suretnohq/chance
chance javascript-probability js-chance probability
Last synced: about 1 month ago
JSON representation
Give you a result from random calculation by decimal scoring
- Host: GitHub
- URL: https://github.com/suretnohq/chance
- Owner: SuretnoHQ
- License: mit
- Created: 2019-08-12T05:26:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-27T22:59:34.000Z (4 months ago)
- Last Synced: 2024-10-27T07:51:18.898Z (about 2 months ago)
- Topics: chance, javascript-probability, js-chance, probability
- Language: JavaScript
- Homepage:
- Size: 72.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chance
Give you a result from random calculation by decimal scoring
## Usage
Use NPM to install **zero-chance**
```bash
$ npm install zero-chance
```Import and create config on your project :
```js
import Chance from 'zero-chance'const weights = [
{
weight: 0.001,
title: 'Some title',
description: 'Some description'
},
{
weight: 20.40,
title: 'Some title',
description: 'Some description'
},
... so on
]const simple = Chance(weights)
console.log(simple) // 1 <-- result of random, given number by highest probability
/**
* Or, you can show any detail on result with option
*/const result = Chance(weights, {
detail: true
})console.log(result)
// Given result by highest probability
// {
// index: 1,
// weight: 0.001,
// title: 'Some title',
// description: 'Some description'
// }
```## License
This project under MIT License