cloned/luckybox
Composer 安装命令:
composer require cloned/luckybox
包简介
A library to pick up the one with a specified probability from some items.
README 文档
README
LuckyBox is a library for PHP to pick up the one with a specified probability from some items.
Requirements
- PHP 5.3.0 and up
Install
In your application or dependent library root directory, create a composer.json file. In the require or alternatively in the require-dev section, add the following dependency:
"cloned/luckybox": "$VERSION"
with $VERSION being one of the versions available at Packagist.
Usage
Example
Here is a simple example to pick up the item from 3 items which are Coin, Mushroom and Star. Probability of each item is below.
- Coin: 60%
- Mushroom: 35%
- Star: 5%
<?php use LuckyBox\LuckyBox; use LuckyBox\Card\IdCard; // Items $items = array( 1 => array('name' => 'Coin', 'rate' => 60), // 60% 2 => array('name' => 'Mushroom', 'rate' => 35), // 35% 3 => array('name' => 'Star', 'rate' => 5), // 5% ); // Setup $luckyBox = new LuckyBox(); foreach ($items as $id => $item) { $card = new IdCard(); $card->setId($id) ->setRate($item['rate']); $luckyBox->add($card); } // Draw $card = $luckyBox->draw(); $item = $items[$card->getId()]; echo "You got {$item['name']}" . PHP_EOL;
Consume cards
Cards in LuckyBox are not consumable by default. This means that the cards can be drawn endlessly. If you want to consume the cards in LuckyBox, set consumable to true.
$luckyBox = new LuckyBox(); // Add some cards. $luckyBox->setConsumable(true); while (!$luckyBox->isEmpty()) { $card = $luckyBox->draw(); // Do something. }
Increase the accuracy
You may want to higher accuracy than percent (0 to 100). You can set the rate more than 100.
$card1 = new IdCard(); $card2 = new IdCard(); $card1->setRate(1023); // 10.23% $card2->setRate(8977); // 89.77%
Remove a card
- Remove one card
$luckyBox->remove($card);
- Remove all of the cards
$luckyBox->clear();
License
LuckyBox is licensed under the MIT License - see the LICENSE file for details
cloned/luckybox 适用场景与选型建议
cloned/luckybox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.48k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2013 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「random」 「luckybox」 「lottery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cloned/luckybox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cloned/luckybox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cloned/luckybox 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Faker Japanese is a Faker provider that generates fake Japanese related data for you.
Gambling Algorithms for Certification.
Reusable utilities library for Lacus Solutions' packages (type description, HTML escaping, random sequences)
Random string generator
Laravel model support multi connection format master - slaves. Connect random a slave with weight
PHP class for randomly awarding a fixed amount of instant-win over a set period of time.
统计信息
- 总下载量: 7.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-20