PHPackages                             district5/random - 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. district5/random

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

district5/random
================

District5 Randomness Library

2.0.0(2y ago)0101mitPHPPHP &gt;=7.1

Since Nov 20Pushed 2y agoCompare

[ Source](https://github.com/district-5/php-random)[ Packagist](https://packagist.org/packages/district5/random)[ Docs](https://github.com/district-5/random)[ RSS](/packages/district5-random/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

District5 - Random
==================

[](#district5---random)

Generate... well... random stuff.

Composer:
---------

[](#composer)

```
{
    "repositories":[
        {
            "type": "vcs",
            "url": "git@github.com:district5/php-random.git"
        }
    ],
    "require": {
        "district5/random": ">=2.0.0"
    }
}

```

- Installing for development environments:
    - `$ composer install`
- Installing for production environments. Ignoring the dev dependencies and optimise the autoloader:
    - `$ composer install --no-dev -o`

Unit testing:
-------------

[](#unit-testing)

- Install with composer, ensuring you include the dev details:
    - `$ composer install`
- Run the phpunit binary:
    - `$ ./vendor/bin/phpunit`

Common uses:
------------

[](#common-uses)

#### UUID / GUID Pseudo Random

[](#uuid--guid-pseudo-random)

```
$includeHyphens = true;

// fast UUID generator
$uuid = \District5\Random\Uuid::simple($includeHyphens);

// slower but higher entropy UUID generator
$cost = 64;
$uuid = \District5\Random\Uuid::highEntropy($cost, $includeHyphens);
```

#### String Pseudo Random

[](#string-pseudo-random)

```
$length = 16;

// generate an alphanumeric string
$str = \District5\Random\Strings::alphanumeric($length);

// generates an alphabetical lowercase string
$str = \District5\Random\Strings::alphabeticLowercase($length);

// generates a hex string
$str = \District5\Random\Strings::hex($length);

// generates a string using a set of allowable characters
$str = \District5\Random\Strings::fromStringOfAllowableCharacters('abcd1234', $length);

// generates a string with full custom control
$allowAlphabetical = true;
$allowNumeric = true;
$allowSpecial = true;
$excludeAmbiguous = false;
$toIgnore = ['1', 'i', 'I', '0', 'O', 'o'];
$forceEachType = true;
$str = \District5\Random\Strings::custom(
    $length,
    $allowAlphabetical,
    $allowNumeric,
    $allowSpecial,
    $excludeAmbiguous,
    $ignoreCharacters,
    $forceEachType
);
```

#### Password Pseudo Random

[](#password-pseudo-random)

```
// generate an 8 character single password with allowed characters including alphabetical, numerical and special
$password = \District5\Random\Password::single(8);

// generate a list of 5 x 8 character passwords
$passwords = \District5\Random\Password::multiple(5, 8);
```

#### Integer Pseudo Random

[](#integer-pseudo-random)

```
// Between 0 and 10
$int = \District5\Random\Integer::inRange(0, 10);

// generate an integer between 1 and mt_getrandmax()
$int = \District5\Random\Integer::positive();

// generate an integer between 1 and 55
$int = \District5\Random\Integer::positive(55);

// generate an integer between -1 and negative mt_getrandmax()
$int = \District5\Random\Integer::negative();

// generate an integer between -1 and -55
$int = \District5\Random\Integer::negative(-55);
```

#### Array Pseudo Random

[](#array-pseudo-random)

These functions work for both default keyed arrays and associative style keyed arrays, or a combination of both.

```
$data = ['foo', 'bar', 'dog', 'cat'];
$key = \District5\Random\Arrays::randomKey($data);
// $key would be in the range of 0-3 inclusive

$data = ['a' => 'foo', 'b' => 'bar', 'c' => 'dog', 'd' => 'cat'];
$value = \District5\Random\Arrays::randomItem($data);
// $value would be one of foo|bar|dog|cat
```

#### Dates(string) and DateTime Pseudo Random

[](#datesstring-and-datetime-pseudo-random)

```
// generates a pseudo random DateTime between the epoch and now
$randomDateTime = \District5\Random\Dates::dateTime();

// generates a pseudo random DateTime between DateTime 1 and DateTime 2.
$randomDateTime = \District5\Random\Dates::dateTimeBetweenDateTimes($dt1, $dt2);

// generate a pseudo random date string between the epoch and now with default formatting of Y-m-d (optional argument defaulted to Y-m-d)
$randomDateStr = \District5\Random\Dates::date('Y-m-d');

// generates a pseudo random date string between DateTime 1 and DateTime 2.
$randomDateStr = \District5\Random\Dates::dateBetweenDateTimes($dt1, $dt2, 'Y-m-d');
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.2% 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 ~314 days

Total

5

Last Release

748d ago

Major Versions

1.0.3 → 2.0.02024-04-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/5de4b9a90eadf6b595e1b5efc802683f2358da5661c616820b90c922f8aa8e05?d=identicon)[rogerthomas84](/maintainers/rogerthomas84)

![](https://www.gravatar.com/avatar/c566343bfe6b0a3602622dd1def882992f10ff114b6a95ffb000da2ba9e22578?d=identicon)[mark-morgan](/maintainers/mark-morgan)

---

Top Contributors

[![mark-morgan](https://avatars.githubusercontent.com/u/1934581?v=4)](https://github.com/mark-morgan "mark-morgan (30 commits)")[![rogerthomas84](https://avatars.githubusercontent.com/u/350232?v=4)](https://github.com/rogerthomas84 "rogerthomas84 (19 commits)")

---

Tags

randomphpdistrict5

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/district5-random/health.svg)

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

###  Alternatives

[gladcodes/keygen

A fluent PHP random key generator.

119668.9k2](/packages/gladcodes-keygen)[savvot/random

Deterministic pseudo-random generators library with dozens of useful functions and several sources of randomness

21243.7k5](/packages/savvot-random)[sinergi/token

PHP library to generate random strings

188.7k9](/packages/sinergi-token)

PHPackages © 2026

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