smoren/probability-selector
最新稳定版本:v2.1.0
Composer 安装命令:
composer require smoren/probability-selector
包简介
Probability selector
README 文档
README
Selection manager for choosing next elements to use from data source based on uniform distribution of selections.
Infinite iteration
use Smoren\ProbabilitySelector\ProbabilitySelector; $ps = new ProbabilitySelector([ // data // weight // initial usage counter ['first', 1, 0], ['second', 2, 0], ['third', 3, 4], ]); foreach ($ps as $datum) { echo "{$datum}, "; } // second, second, first, second, third, third, second, first, third, second, third, third, second, first, third, ...
Iteration limit and export
use Smoren\ProbabilitySelector\ProbabilitySelector; $ps = new ProbabilitySelector([ // data // weight ['first', 1], ['second', 2], ]); foreach ($ps->getIterator(6) as $datum) { echo "{$datum}, "; } // second, second, first, second, second, first print_r($ps->export()); /* [ ['first', 1, 2], ['second', 2, 4], ] */
Single decision
use Smoren\ProbabilitySelector\ProbabilitySelector; $ps = new ProbabilitySelector([ // data // weight ['first', 1], ['second', 2], ]); $ps->decide(); // second $ps->decide(); // second $ps->decide(); // first
Unit testing
composer install
composer test-init
composer test
Standards
PHP Probability Selector conforms to the following standards:
- PSR-1 — Basic coding standard
- PSR-4 — Autoloader
- PSR-12 — Extended coding style guide
License
PHP Probability Selector is licensed under the MIT License.
统计信息
- 总下载量: 771
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-26