district5/random
Composer 安装命令:
composer require district5/random
包简介
District5 Randomness Library
关键字:
README 文档
README
Generate... well... random stuff.
Composer:
{
"repositories":[
{
"type": "vcs",
"url": "git@github.com:district5/php-random.git"
}
],
"require": {
"district5/random": ">=2.0.0"
}
}
- Installing for development environments:
$ composer install
- Installing for production environments. Ignoring the dev dependencies and optimise the autoloader:
$ composer install --no-dev -o
Unit testing:
- Install with composer, ensuring you include the dev details:
$ composer install
- Run the phpunit binary:
$ ./vendor/bin/phpunit
Common uses:
UUID / GUID Pseudo Random
$includeHyphens = true; // fast UUID generator $uuid = \District5\Random\Uuid::simple($includeHyphens); // slower but higher entropy UUID generator $cost = 64; $uuid = \District5\Random\Uuid::highEntropy($cost, $includeHyphens);
String Pseudo Random
$length = 16; // generate an alphanumeric string $str = \District5\Random\Strings::alphanumeric($length); // generates an alphabetical lowercase string $str = \District5\Random\Strings::alphabeticLowercase($length); // generates a hex string $str = \District5\Random\Strings::hex($length); // generates a string using a set of allowable characters $str = \District5\Random\Strings::fromStringOfAllowableCharacters('abcd1234', $length); // generates a string with full custom control $allowAlphabetical = true; $allowNumeric = true; $allowSpecial = true; $excludeAmbiguous = false; $toIgnore = ['1', 'i', 'I', '0', 'O', 'o']; $forceEachType = true; $str = \District5\Random\Strings::custom( $length, $allowAlphabetical, $allowNumeric, $allowSpecial, $excludeAmbiguous, $ignoreCharacters, $forceEachType );
Password Pseudo Random
// generate an 8 character single password with allowed characters including alphabetical, numerical and special $password = \District5\Random\Password::single(8); // generate a list of 5 x 8 character passwords $passwords = \District5\Random\Password::multiple(5, 8);
Integer Pseudo Random
// Between 0 and 10 $int = \District5\Random\Integer::inRange(0, 10); // generate an integer between 1 and mt_getrandmax() $int = \District5\Random\Integer::positive(); // generate an integer between 1 and 55 $int = \District5\Random\Integer::positive(55); // generate an integer between -1 and negative mt_getrandmax() $int = \District5\Random\Integer::negative(); // generate an integer between -1 and -55 $int = \District5\Random\Integer::negative(-55);
Array Pseudo Random
These functions work for both default keyed arrays and associative style keyed arrays, or a combination of both.
$data = ['foo', 'bar', 'dog', 'cat']; $key = \District5\Random\Arrays::randomKey($data); // $key would be in the range of 0-3 inclusive $data = ['a' => 'foo', 'b' => 'bar', 'c' => 'dog', 'd' => 'cat']; $value = \District5\Random\Arrays::randomItem($data); // $value would be one of foo|bar|dog|cat
Dates(string) and DateTime Pseudo Random
// generates a pseudo random DateTime between the epoch and now $randomDateTime = \District5\Random\Dates::dateTime(); // generates a pseudo random DateTime between DateTime 1 and DateTime 2. $randomDateTime = \District5\Random\Dates::dateTimeBetweenDateTimes($dt1, $dt2); // generate a pseudo random date string between the epoch and now with default formatting of Y-m-d (optional argument defaulted to Y-m-d) $randomDateStr = \District5\Random\Dates::date('Y-m-d'); // generates a pseudo random date string between DateTime 1 and DateTime 2. $randomDateStr = \District5\Random\Dates::dateBetweenDateTimes($dt1, $dt2, 'Y-m-d');
district5/random 适用场景与选型建议
district5/random 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 101 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「random」 「district5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 district5/random 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 district5/random 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 district5/random 相关的其它包
同方向 / 同关键字的高下载量 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
District5 Validator Library
Laravel model support multi connection format master - slaves. Connect random a slave with weight
统计信息
- 总下载量: 101
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2024-05-07