@jswork/next-weight-random

1.0.3 • Public • Published

next-weight-random

Random has weight.

version license size download

installation

npm install -S @jswork/next-weight-random

usage

import '@jswork/next-weight-random';

const results = {};

const params1 = [ 0.75, 0.15, 0.1 ];
const params2 = {
  0: 0.75,
  1: 0.15,
  2: 0.1
};

const rand = nx.weightRandom(params1);

for (let i = 0; i < 1000; i++) {
  const val = rand1();
  results[val] = results[val] || [];
  results[val].push(true);
}

const total = results[0].length + results[1].length + results[2].length;

console.log(
  results[0].length / total,
  results[1].length / total,
  results[2].length / total
);

// Run multple times:
// 0.765 0.129 0.106
// 0.751 0.152 0.097
// 0.778 0.135 0.087

resources

license

Code released under the MIT license.

/@jswork/next-weight-random/

    Package Sidebar

    Install

    npm i @jswork/next-weight-random

    Weekly Downloads

    2

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    5.97 kB

    Total Files

    5

    Last publish

    Collaborators

    • afeiship