1.0.0 • Published 4 years ago

@feizheng/next-weight-random v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

next-weight-random

Random has weight.

version license size download

installation

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

usage

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

const results = {};
const rand = nx.weightRandom({
  0: 0.75,
  1: 0.15,
  2: 0.1
});

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

license

Code released under the MIT license.

1.0.0

4 years ago