JSPM

@ricardomatias/roll

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q36371F
  • License MIT

Let's you pick an element randomly based on a chosen probability distribution

Package Exports

  • @ricardomatias/roll

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ricardomatias/roll) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

roll Build Status

Let's you pick an element randomly based on a chosen probability distribution

import { roll, distribute } from '@ricardomatias/roll';
import seedRandom from 'seed-random'; // works nicely together

const rng = seedRandom('roll');
const AM7 = [ 'A', 'C', 'E', 'G' ];

const equalOdds = distribute.equal(AM7.length);
const decreasingOdds = distribute.decreasing(AM7.length);
const increasingOdds = distribute.increasing(AM7);

roll(AM7, equalOdds, rng); // => G
roll(AM7, equalOdds, rng); // => C
roll(AM7, decreasingOdds, rng); // => A
roll(AM7, increasingOdds, rng); // => E

Install

Use npm to install.

npm install @ricardomatias/roll --save

Usage

roll

roll(elements, probabilities, rng) ⇒ Object | Null

Pick an element randomly based on a chosen probability distribution

Param Type Description
elements Array
probabilities Array.<String>
rng function Random Number Generator

distribute

decreasing(k, precision)Array.<String>

Creates a decreasing probability distribution

increasing(k, precision)Array.<String>

Creates an increasing probability distribution

equal(k, precision)Array.<String>

Creates an equal probability distribution

decreasing(k, precision) ⇒ Array.<String>

Creates a decreasing probability distribution

Param Type
k Number | Array.<Number>
[precision] Number

increasing(k, precision) ⇒ Array.<String>

Creates an increasing probability distribution

Param Type
k Number | Array.<Number>
[precision] Number

equal(k, precision) ⇒ Array.<String>

Creates an equal probability distribution

Param Type
k Number | Array.<Number>
[precision] Number

License

MIT, see LICENSE.md for details.