eonx-com/easy-random

提供生成随机值(字符串、整数、UUID等)的简单方法

6.0.0 2024-08-15 12:18 UTC

This package is auto-updated.

Last update: 2024-09-19 04:47:53 UTC


README

---eonx_docs--- 标题:介绍 重量:0 ---eonx_docs---

需要生成随机且唯一的值吗?此包适用于您!

  • 字符串
  • 数字
  • UUIDs

所需的所有随机性!


需要包(Composer)

安装此包的推荐方式是使用Composer

$ composer require eonx-com/easy-random

用法

整数

// Will generate a random integer between 0 and 20 (both included)
$myNumber = (new \EonX\EasyRandom\Generator\RandomGenerator(...))->integer(0, 20);

字符串

随机生成器允许您通过优雅的流畅接口控制生成的随机字符串的长度和组成

$myString = (new \EonX\EasyRandom\Generator\RandomGenerator(...))
    ->string(16)
    ->excludeSimilar() // Will exclude similar characters
    ->excludeVowel() // Will exclude vowels, nice trick to avoid "bad words" in generated random strings
    ->includeNumeric(); // Include 0-9 numbers

您需要为最终用户生成随机字符串吗?

// Will generate "user friendly" random string:
// - exclude ambiguous characters
// - exclude symbols
// - exclude vowels
// - include numeric
// - include uppercase

$reference = (new \EonX\EasyRandom\Generator\RandomGenerator(...))
    ->string(16)
    ->userFriendly();

UUID

随机生成器允许您生成UUID。此包内置了对以下内容的实现: symfony/uid。如果您想使用自己的实现,则需要确保它实现了 EonX\EasyRandom\Generator\UuidGeneratorInterface

$uuid = (new \EonX\EasyRandom\Generator\RandomGenerator(...))->uuid();