PHPackages                             ngiusti/random-string-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ngiusti/random-string-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ngiusti/random-string-generator
===============================

Generates a random string based on a given pattern

v1.0.0(8y ago)01691MITPHPPHP ^7.0

Since Oct 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/nathaliagiusti/random-string-generator)[ Packagist](https://packagist.org/packages/ngiusti/random-string-generator)[ Docs](https://github.com/nathaliagiusti/random-string-generator)[ RSS](/packages/ngiusti-random-string-generator/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

RandomStringGenerator
=====================

[](#randomstringgenerator)

**Generates a random string based on a given string pattern**

Installation
------------

[](#installation)

The package can be used by adding `random-string-generator` to your list of dependencies in `composer.json` as following:

```
composer require ngiusti/random-string-generator

```

Usage
-----

[](#usage)

#### Accepted string patterns:

[](#accepted-string-patterns)

Use `l` for lower case letter from a to z

Use `L` for upper case letter from A to Z

Use `d` for digit from 0 to 9

Use `p` for punctuation

#### Punctuation is any character on the following group:

[](#punctuation-is-any-character-on-the-following-group)

`!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `-`, `.`, `/`, `:`, `;`, ``, `?`, `@`, `[`, `\`, `]`, `^`, `_`, `{`, `|`,`}`, `~` and ```

##### Generate a string containing 2 lower case letters followed by 2 digits.

[](#generate-a-string-containing-2-lower-case-letters-followed-by-2-digits)

```
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('lldd'); // "ol68"
```

##### Generate a string containing 2 upper case letters.

[](#generate-a-string-containing-2-upper-case-letters)

```
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('LL'); // "VR"
```

##### Generate a string containing 2 punctuations.

[](#generate-a-string-containing-2-punctuations)

```
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('pp'); // "?!"
```

**Delimiters**

Apart from `l`,`L`,`d` and `p`, any other character is considered a delimiter. Therefore, the pattern `-dl?` is interpreted as : a hyphen followed by a random digit, followed by a random lower case letter, followed by a question mark.

##### Generate a string containing 2 letters followed by a hyphen.

[](#generate-a-string-containing-2-letters-followed-by-a-hyphen)

```
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('ll-'); // "yz-"
```

**Scape**

In order to generate a string containing the characters `l`,`L`,`d` and `p`as a delimiter you need to use the backslash twice in order to scape it.

##### Generate a string containing 2 digits followed by the letters `lLdp`.

[](#generate-a-string-containing-2-digits-followed-by-the-letters-lldp)

```
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('dd\\l\\L\\d\\p'); // "39lLdp"
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3166d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4750684?v=4)[ngiusti](/maintainers/ngiusti)[@ngiusti](https://github.com/ngiusti)

---

Top Contributors

[![nathaliagiusti](https://avatars.githubusercontent.com/u/20708798?v=4)](https://github.com/nathaliagiusti "nathaliagiusti (11 commits)")

---

Tags

randomstringgeneratorpattern

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ngiusti-random-string-generator/health.svg)

```
[![Health](https://phpackages.com/badges/ngiusti-random-string-generator/health.svg)](https://phpackages.com/packages/ngiusti-random-string-generator)
```

###  Alternatives

[mistic100/randomcolor

Generate attractive random colors

2411.5M6](/packages/mistic100-randomcolor)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

375369.1k](/packages/ihor-nspl)[nubs/random-name-generator

A library to create interesting, sometimes entertaining, random names.

132705.1k3](/packages/nubs-random-name-generator)[gladcodes/keygen

A fluent PHP random key generator.

119759.9k2](/packages/gladcodes-keygen)[genphrase/genphrase

Secure passphrase generator for PHP applications

117312.1k4](/packages/genphrase-genphrase)[hi-folks/rando-php

Random generator Library for PHP

12889.8k2](/packages/hi-folks-rando-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
