mrbrownnl/random-nickname-generator

Random nickname generator

4.0.0 2025-01-03 18:18 UTC

This package is auto-updated.

Last update: 2025-02-03 18:30:50 UTC


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

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.

Changelog

Please see CHANGELOG for more information what has changed recently.

License

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