PHPackages                             nickjbedford/randomstringgenerator - 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. nickjbedford/randomstringgenerator

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

nickjbedford/randomstringgenerator
==================================

Provides methods to generate cryptographically strong random strings based on an input alphabet.

0.5.0(3mo ago)01.7k↓33.3%1MITPHPPHP &gt;=8.4CI passing

Since Jan 31Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/nickjbedford/randomstringgenerator)[ Packagist](https://packagist.org/packages/nickjbedford/randomstringgenerator)[ Docs](https://github.com/nickjbedford/randomstringgenerator)[ RSS](/packages/nickjbedford-randomstringgenerator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (16)Used By (0)

Random String Generator
=======================

[](#random-string-generator)

`Generator\RandomStringGenerator` generates cryptographically strong random strings based on a supplied alphabet of characters (such as alphanumeric characters). This is perfect for generating API keys within a set of allowed characters. It can also be used to generate strong passwords.

The class relies on the `random_bytes()` function to generate the cryptographically strong random numbers for use in building the random strings.

Usage
-----

[](#usage)

To generate a 16-character string using the default 62-character alphanumeric alphabet, the usage is as simple as the following:

```
	$generator = new Generators\RandomStringGenerator();
	$key = $generator->generate();
	// string(16) "7m98Jvc0ArBDS4jK"
```

To use a different alphabet, such as uppercase hexadecimal characters, and to generate a random string of a different length, these parameters can be passed to the class as follows:

```
$generator = new RandomStringGenerator(RandomStringGenerator::ALPHABET_HEX_UPPER);
$key = $generator->generate(8);
// string(8) "CF70D24E"

```

A custom alphabet can be provided in the form of an input string of characters, such as:

```
$generator = new RandomStringGenerator('abc123');
$key = $generator->generate();
// string(16) "cb2c2a33c2c3a23b"

```

This is then converted to an array of characters internally. This array can be retrieved using the `$generator->alphabet()` function with no argument.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance79

Regular maintenance activity

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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

Every ~140 days

Recently: every ~173 days

Total

14

Last Release

111d ago

PHP version history (4 changes)0.1PHP 7.4.\*

0.3.1PHP &gt;=7.3

0.4.0PHP &gt;=8.3

0.5.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bce7dd852d725a53d2d7a81183acc952c7902242b8fcfa4b45564fe1702d8f3?d=identicon)[nickjbedford](/maintainers/nickjbedford)

---

Top Contributors

[![nickjbedford](https://avatars.githubusercontent.com/u/10795658?v=4)](https://github.com/nickjbedford "nickjbedford (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

randomcryptographygenerator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nickjbedford-randomstringgenerator/health.svg)

```
[![Health](https://phpackages.com/badges/nickjbedford-randomstringgenerator/health.svg)](https://phpackages.com/packages/nickjbedford-randomstringgenerator)
```

###  Alternatives

[ircmaxell/random-lib

A Library For Generating Secure Random Numbers

84130.2M119](/packages/ircmaxell-random-lib)[mistic100/randomcolor

Generate attractive random colors

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

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

381368.5k](/packages/ihor-nspl)[paragonie/random-lib

A Library For Generating Secure Random Numbers

703.3M26](/packages/paragonie-random-lib)[nubs/random-name-generator

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

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

A fluent PHP random key generator.

119668.9k2](/packages/gladcodes-keygen)

PHPackages © 2026

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