A PHP version of bryanmylee's zoo-ids, originally written in JavaScript, which was in turn inspired by the URL ID's of gfycat.com. For a frontend or backend that uses JavaScript, I highly recommend you use their package!
Generate predictable and unique identifiers composed of adjectives and animal names, with the ability to seed the random identifiers.
Currently, there are 1347 adjectives and 221 animals. The more adjectives used, the more possible combinations of IDs available.
For a quick reference, with 2 adjectives used, there are 400,984,389 possible unique IDs.
With 3 adjectives, there are 540,125,971,983 possible unique IDs.
$ composer require iliain/php-zoo-ids
use Iliain\ZooIDs\UsernameRandomizer;
$randomizer = new UsernameRandomizer();
$randomizer->generateID('short seed'); // KnobbyNauticalKingfisher
// Defaults to the current time if seed is null.
$randomizer->generateID(null, 2, '🍓', 'lowercase'); // enchanted🍓narrow🍓wallaby
If you want to control the list of Nouns and Adjectives, you can provide your own:
$randomizer = new UsernameRandomizer(['Jumping','Flying','Running','Waving'], ['Rock', 'Paper', 'Scissors']);
$randomizer->generateID(); // JumpingRunningScissors
$randomizer->setAdjectives(['Diving','Walking','Spinning']);
$randomizer->generateID(); // WalkingDivingScissors
$randomizer->setNouns(['Koala', 'Dog']);
$randomizer->generateID(); // WalkingDivingKoala
An array of adjectives to use in generation. Defaults to preprovided list if none are specified.
An array of nouns to use in generation. Defaults to preprovided list if none are specified.
The seed used to generate the id. This allows us to generate predictable, but random and unique identifiers.
Defaults to the current time.
The number of adjectives to use in the identifier.
Defaults to 2
.
The delimiter used between words. The delimiter will also be used between multi-word adjectives.
Defaults to ''
.
The case style for the words. Possible options are 'titlecase'
, 'camelcase'
, 'uppercase'
, 'lowercase'
, and 'togglecase'
.
generateID($seed, $numAdjectives, $delimiter, 'titlecase'); // FineAntiqueElk
generateID($seed, $numAdjectives, $delimiter, 'camelcase'); // pertinentPoshGoldfinch
generateID($seed, $numAdjectives, $delimiter, 'uppercase'); // PIERCINGRESPONSIBLECAMEL
generateID($seed, $numAdjectives, $delimiter, 'lowercase'); // imaginarywingedsalamander
generateID($seed, $numAdjectives, $delimiter, 'togglecase'); // sTuNnInGdEsCrIpTiVepEaFoWl
Defaults to 'titlecase'
.
All credit goes to Bryan Lee and his zoo-ids package. I wanted a version of this to use in PHP (username generation was handled by a PHP CMS), and converted the majority of his existing code to that format. Currently lacking some of his original features, such as the ability to use objects as seeds.