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

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

delight-im/random
=================

The most convenient way to securely generate anything random in PHP

v1.0.0(6y ago)2146.3k↑22.9%3[6 issues](https://github.com/delight-im/PHP-Random/issues)MITPHPPHP &gt;=7.0.0

Since Nov 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/delight-im/PHP-Random)[ Packagist](https://packagist.org/packages/delight-im/random)[ Docs](https://github.com/delight-im/PHP-Random)[ RSS](/packages/delight-im-random/feed)WikiDiscussions master Synced 2d ago

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

PHP-Random
==========

[](#php-random)

The most convenient way to securely generate anything random in PHP

Requirements
------------

[](#requirements)

- PHP 7.0.0+

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

[](#installation)

1. Include the library via Composer [\[?\]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md):

    ```
    $ composer require delight-im/random

    ```
2. Include the Composer autoloader:

    ```
    require __DIR__ . '/vendor/autoload.php';
    ```

Usage
-----

[](#usage)

### Generating integers and natural numbers

[](#generating-integers-and-natural-numbers)

```
Random::intBetween(300, 999);
// => e.g. int(510)

// or

Random::intBelow(5);
// => e.g. int(1)

// or

Random::intValue();
// => e.g. int(935477113)
```

### Generating floating-point numbers (floats, doubles or reals)

[](#generating-floating-point-numbers-floats-doubles-or-reals)

```
Random::floatBetween(1, 9);
// => e.g. float(7.6388446512546)

// or

Random::floatBelow(499);
// => e.g. float(281.51015805504)

// or

Random::floatValue();
// => e.g. float(0.05532844200834)
```

### Generating boolean values

[](#generating-boolean-values)

```
Random::boolValue();
// => e.g. bool(true)
```

### Generating raw bytes

[](#generating-raw-bytes)

```
Random::bytes(10);
// => e.g. "\x58\x3b\x15\x94\x0a\x78\x52\xd0\x53\xb0"
```

### Generating UUIDs (version 4)

[](#generating-uuids-version-4)

```
Random::uuid4();
// => e.g. string(36) "892a24f9-c188-4d06-9885-cf5d8de4592b"
```

### Generating hexadecimal strings

[](#generating-hexadecimal-strings)

```
Random::hexLowercaseString(2);
// => e.g. string(2) "5f"

// or

Random::hexUppercaseString(7);
// => e.g. string(7) "B0F4B0C"
```

### Generating strings consisting of letters

[](#generating-strings-consisting-of-letters)

```
Random::alphaString(32);
// => e.g. string(32) "GvogcpNdwaxsmOAzKGYwDwqfMOUkZvAn"

// or

Random::alphaHumanString(7);
// => e.g. string(7) "KykrbXb"

// or

Random::alphaLowercaseString(2);
// => e.g. string(2) "ce"

// or

Random::alphaLowercaseHumanString(32);
// => e.g. string(32) "kqbgcmkttvmxjthwpgbhkgdfqhxqmmxh"

// or

Random::alphaUppercaseString(2);
// => e.g. string(2) "IJ"

// or

Random::alphaUppercaseHumanString(7);
// => e.g. string(7) "LJWLLHJ"
```

### Generating strings consisting of letters and numbers

[](#generating-strings-consisting-of-letters-and-numbers)

```
Random::alphanumericString(2);
// => e.g. string(2) "h9"

// or

Random::alphanumericHumanString(7);
// => e.g. string(7) "NF34gd4"

// or

Random::alphanumericLowercaseString(2);
// => e.g. string(2) "4g"

// or

Random::alphanumericLowercaseHumanString(32);
// => e.g. string(32) "wbdt3fdtg9c33dnxxtphp3qd9tgdvhbn"

// or

Random::alphanumericUppercaseString(2);
// => e.g. string(2) "O7"

// or

Random::alphanumericUppercaseHumanString(32);
// => e.g. string(32) "TWFHNNWLNKMPJMYKXHX3TXRCRFTFMYYW"

// or

Random::base32String(7);
// => e.g. string(7) "AZUELC4"

// or

Random::base58String(32);
// => e.g. string(32) "jut9s2LdWHT1EGJeBug3F58oYsaoU85s"
```

### Generating strings consisting of letters, numbers and punctuation

[](#generating-strings-consisting-of-letters-numbers-and-punctuation)

```
Random::alphanumericAndPunctuationHumanString(32);
// => e.g. string(32) "x%jJ7pWTFwc94ctX3phyy^KT~??H4+JY"

// or

Random::asciiPrintableString(32);
// => e.g. string(32) "N~5_ kP5muxf,HeDY2(W_Bwy^qOkgOXa"

// or

Random::asciiPrintableHumanString(7);
// => e.g. string(7) "_r=kb?v"

// or

Random::base64String(19);
// => e.g. string(19) "I7A/H8D2R54uAo6jCQ3"

// or

Random::base64UrlString(4);
// => e.g. string(4) "_6GS"

// or

Random::base85String(7);
// => e.g. string(7) "j8o6sp:"
```

### Generating strings from arbitrary characters sets or alphabets

[](#generating-strings-from-arbitrary-characters-sets-or-alphabets)

```
Random::stringFromAlphabet('abcd+', 7);
// => e.g. string(7) "ad+cabb"
```

### Dividing output strings into segments

[](#dividing-output-strings-into-segments)

#### Using hyphens as dividers

[](#using-hyphens-as-dividers)

```
\Delight\Random\Util::hyphenate('aaaaaaaaaa');
// => string(12) "aaaa-aaaa-aa"

// or

\Delight\Random\Util::hyphenate('bbbbbbbbbb', 3);
// => string(13) "bbb-bbb-bbb-b"
```

#### Using spaces as dividers

[](#using-spaces-as-dividers)

```
\Delight\Random\Util::spaceOut('cccccccccc');
// => string(12) "cccc cccc cc"

// or

\Delight\Random\Util::spaceOut('dddddddddd', 3);
// => string(13) "ddd ddd ddd d"
```

#### Using arbitrary dividers

[](#using-arbitrary-dividers)

```
\Delight\Random\Util::segmentize('eeeeeeeeee', '/');
// => string(12) "eeee/eeee/ee"

// or

\Delight\Random\Util::segmentize('ffffffffff', '/', 3);
// => string(13) "fff/fff/fff/f"
```

Contributing
------------

[](#contributing)

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

License
-------

[](#license)

This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

2418d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6597567?v=4)[delight.im](/maintainers/delight-im)[@delight-im](https://github.com/delight-im)

---

Top Contributors

[![ocram](https://avatars.githubusercontent.com/u/1681478?v=4)](https://github.com/ocram "ocram (1 commits)")

---

Tags

randomcsprngpseudorandomcryptographygeneratorstringsrandom-numbersrandom-stringsPRNGnumberspseudo-randomintegers

### Embed Badge

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

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

###  Alternatives

[paragonie/random_compat

PHP 5.x polyfill for random\_bytes() and random\_int() from PHP 7

8.2k686.9M434](/packages/paragonie-random-compat)[ircmaxell/random-lib

A Library For Generating Secure Random Numbers

84032.1M132](/packages/ircmaxell-random-lib)[paragonie/random-lib

A Library For Generating Secure Random Numbers

743.6M27](/packages/paragonie-random-lib)[mistic100/randomcolor

Generate attractive random colors

2451.5M6](/packages/mistic100-randomcolor)[nubs/random-name-generator

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

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

A fluent PHP random key generator.

123804.0k2](/packages/gladcodes-keygen)

PHPackages © 2026

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