定制 mrbrownnl/random-nickname-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrbrownnl/random-nickname-generator

最新稳定版本:4.0.0

Composer 安装命令:

composer require mrbrownnl/random-nickname-generator

包简介

Random nickname generator

README 文档

README

Latest Version on Packagist Total Downloads

Generates random nicknames based on an adjective (optional) + name + number (optional).

Installation

You can install the package via composer:

composer require mrbrownnl/random-nickname-generator

Basic usage

<?php

use MrBrownNL\RandomNicknameGenerator\RandomNicknameGenerator;

require 'vendor/autoload.php';

$nickNameGenerator = new RandomNicknameGenerator(['useAdjective' => false]);

echo $nickNameGenerator->generate();

// or generate a nickname that has been checked for uniqueness
echo $nickNameGenerator->generateUnique();

Using the Laravel facade

If you are using Laravel 5.5 and up, the service provider will automatically get registered.

For older versions of Laravel (<5.5), you have to add the service provider:

####config/app.php

'providers' => [
    ...
    MrBrownNL\RandomNicknameGenerator\RandomNicknameGeneratorServiceProvider::class,
]

To override the default config parameters in Laravel you can publish the config file to config/nickname-generator.php and specify your own parameters.

php artisan vendor:publish --provider="MrBrownNL\RandomNicknameGenerator\RandomNicknameGeneratorServiceProvider"

Using the facade:

use MrBrownNL\RandomNicknameGenerator\Facades\NicknameGenerator;

$nickname = NicknameGenerator::generate();

// or generate a nickname that has been checked for uniqueness
$nickname = NicknameGenerator::generateUnique();

or test it:

php artisan generate-nickname

Default config parameters

The default package dictionaries are used when no or empty dictionaries are specified on class instantiating.

[
    'useAdjective' => true,
    'separator' => '',
    'addNumericPostfix' => true,
    'postfix' => [
        'minimumValue' => 1,
        'maximumValue' => 999,
    ],
    'dictionaries' => [
        'adjectives' => [],
        'names' => [],
    ],
]

Function reference

Function Description
generate() Generates a random nickname which is not stored in the uniquely generated nickname list or checked for uniqueness.
generateUnique([]) Generates a unique random nickname which is not in the given array.
getNumberOfPossibleUniqueNicknames() Returns the total number of possible unique nicknames with the given configuration parameters.

Performance

The table below shows how much time it takes to generate a unique name.

While compiling custom adjective or name dictionaries, keep in mind that performance drops drastically if only 1% or less unique nicknames are left.

The table below shows the performance when 150.000 unique nicknames are possible.

Available nicknames Time
100 % 0.001 s
70 % 0.006 s
40 % 0.014 s
10 % 0.025 s
5 % 0.030 s
1 % 0.060 s

Changelog

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 28.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-04