choose-by-probability
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Choose by probability 根据概率进行选择

说明

Given an array (assuming a length of N), the array contains probabilities. Based on these probabilities, make a selection. The result is one of N numbers from 1 to N (given array length).
给定一个数组(假定长度为N),数组内包含的是概率。根据这些概率,进行选择。结果为1到N(给定的数组长度)这N个数之一。

Example 例子

We called choose used the array [0.1, 0.2, 0.3, 0.4, 0.5] 150000 times and obtained the result:
我们使用数组[0.1, 0.2, 0.3, 0.4, 0.5]调用150000次,得到结果:

1 => 9960
2 => 20068
3 => 29982
4 => 40124
5 => 49866

This result matches the probability array.
这个结果跟概率数组是匹配的。

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i choose-by-probability

    Weekly Downloads

    2

    Version

    1.0.3

    License

    ISC

    Unpacked Size

    3.03 kB

    Total Files

    6

    Last publish

    Collaborators

    • zyballbj