PHPackages                             shox/randomtoken - 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. shox/randomtoken

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

shox/randomtoken
================

Random token generator with custom length

120.8k↓92.1%[1 issues](https://github.com/calshox/RandomToken/issues)PHP

Since Dec 27Pushed 9y ago2 watchersCompare

[ Source](https://github.com/calshox/RandomToken)[ Packagist](https://packagist.org/packages/shox/randomtoken)[ RSS](/packages/shox-randomtoken/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RandomToken
===========

[](#randomtoken)

\##RandomToken function Random token generator with custom length

```
string RandomToken::generate(int $length [, int $mode = ALL [, string $alphabet = ""]])

```

`$length` Length of the resulting string

`$mode` \[CUSTOM, NUMERIC, LOWERCASE, UPPERCASE, NUMLOWER, NUMUPPER, ALL\] Alphabet mode

`$alphabet` Custom Alphabet if mode = CUSTOM

\##RandomToken function with prefix Random token generator with custom length and prefix

```
string RandomToken::generatePrefix(string $prefix, int $length [, int $mode = ALL [, string $alphabet = ""]])

```

`$prefix` Prefix

`$length` Length of the resulting string

`$mode` \[CUSTOM, NUMERIC, LOWERCASE, UPPERCASE, NUMLOWER, NUMUPPER, ALL\] Alphabet mode

`$alphabet` Custom Alphabet if mode = CUSTOM

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

Composer is required

### Installing

[](#installing)

```
composer require calshox/randomtoken

```

\##Examples

Generating a alphanumeric token \[a-zA-Z0-9\]

```
require_once __DIR__ . "/../vendor/autoload.php";

use Shox\RandomToken;

echo RandomToken::generate(8); //f.ex: Fe3fLv5A

```

Only uppercase \[A-Z\]

```
echo RandomToken::generate(8, RandomToken::UPPERCASE); //f.ex: HRWEQERB

```

Only numeric \[0-9\]

```
echo RandomToken::generate(8, RandomToken::NUMERIC); //f.ex: 72468234

```

Only lowercase \[a-z\]

```
echo RandomToken::generate(8, RandomToken::LOWERCASE); //f.ex: felgncoi

```

Numeric and lowercase \[a-z0-9\]

```
echo RandomToken::generate(8, RandomToken::NUMLOWER); //f.ex: 9kid6gfb

```

Numeric and uppercase \[a-z0-9\]

```
echo RandomToken::generate(8, RandomToken::NUMUPPER); //f.ex: DYN7DP0X

```

Custom Alphabet

```
echo RandomToken::generate(8, RandomToken::CUSTOM, "AEIOU0123456789"); //f.ex: E312AI7I

```

Only numeric with prefix \[0-9\]

```
echo RandomToken::generatePrefix("FX", 8, RandomToken::NUMERIC); //f.ex: FX72468234

```

Authors
-------

[](#authors)

- **Carlos Vázquez** - [Github](https://github.com/calshox/RandomToken)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/86bcd0863f81585a7602cbe1b2c38734dcf4ca47e82ed4afca6cffb5456cee91?d=identicon)[shox](/maintainers/shox)

---

Top Contributors

[![calshox](https://avatars.githubusercontent.com/u/11080359?v=4)](https://github.com/calshox "calshox (6 commits)")

### Embed Badge

![Health badge](/badges/shox-randomtoken/health.svg)

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

###  Alternatives

[dcblogdev/laravel-companies-house

A Laravel Companies House package

1115.4k](/packages/dcblogdev-laravel-companies-house)

PHPackages © 2026

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