PHPackages                             hi-folks/rando-php - 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. hi-folks/rando-php

ActiveLibrary

hi-folks/rando-php
==================

Random generator Library for PHP

v0.3.1(1y ago)12884.3k↑14.5%222MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4

Since Jul 19Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Hi-Folks/rando-php)[ Packagist](https://packagist.org/packages/hi-folks/rando-php)[ Docs](https://github.com/hi-folks/rando-php)[ RSS](/packages/hi-folks-rando-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (2)

Rando-PHP
=========

[](#rando-php)

[![Testing RandoPHP](https://camo.githubusercontent.com/7c0b95396e2cb03155c4cb57135da87a0f34fbae1afeaf6eb0df0881e9fecbb4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68692d666f6c6b732f72616e646f2d7068702f7068702e796d6c3f6272616e63683d6d6173746572266c6162656c3d5465737425323052414e444f2d504850267374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/rando-php/actions)[![GitHub last commit](https://camo.githubusercontent.com/b0a079da36639bb6cfe80022c19ec150c8d2af84222ec4d4edc96d947bb0bd03/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f68692d666f6c6b732f72616e646f2d7068703f7374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/rando-php/commits/master)[![GitHub Release Date](https://camo.githubusercontent.com/e25278edb2dff0dad3227b15103d1818a140224511fb022b0814f0ddfe3b905c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f68692d666f6c6b732f72616e646f2d7068703f7374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/rando-php/releases/)[![Packagist PHP Version Support](https://camo.githubusercontent.com/e0a566e72ccb23a18ee5ee9d7169f91a80c20c3d9a0def1da6885ac2ab1a2a0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f68692d666f6c6b732f72616e646f2d7068702f7068703f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/e0a566e72ccb23a18ee5ee9d7169f91a80c20c3d9a0def1da6885ac2ab1a2a0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f68692d666f6c6b732f72616e646f2d7068702f7068703f7374796c653d666f722d7468652d6261646765)

[![RandoPHP](rando-php.png)](rando-php.png)

RandoPHP is a PHP open-source package for random stuff. With this package you can:

- **Draw**: Extract random items (sample) from an array. This is useful when you want to "draw" some numbers or items;
- **Generate**: useful for create random items/sequences:
    - *item* like integer, byte, boolean, float, lat/long coordinates, char (numeric, alphabetic, alphanumeric);
    - *sequences* like an array of integers or chars;

With the fluent interface, you can control some things like:

- minimum and maximum value you want to create;
- how many items you want to create;
- for sequences if you want or not duplicates (\[1,5,3,1,1\], 1 is duplicate or \[1,6,5,3,8\], no duplicates);
- And other stuff, see the documentation for more options.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage, how to generate:](#usage)
    - [Random char](#generate-char)
    - [Random boolean](#generate-boolean)
    - [Random float](#generate-a-float)
    - [Random integer](#generate-an-integer)
    - [Random Bytes](#generate-bytes)
    - [Random Date](#generate-a-date)
    - [Random Sequences](#generate-sequences)
    - [Random Chars](#random-chars)
- [Usage, how to extract random values from array/list](#draw-random-stuff)

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

[](#installation)

You can install the package via composer:

```
composer require hi-folks/rando-php
```

Usage
-----

[](#usage)

To import the right class:

```
use HiFolks\RandoPhp\Randomize;
```

### Generate Char

[](#generate-char)

Sometimes you want to obtain a random char, for example, a numeric char:

```
Randomize::char()->numeric()->generate();
```

Or you might want an alphabetic char:

```
Randomize::char()->alpha()->generate();
```

You can even do both!

```
Randomize::char()->alphanumeric()->generate();
```

You can generate a lower case char:

```
Randomize::char()->alpha()->lower()->generate();
```

You can generate an upper case char:

```
Randomize::char()->alpha()->upper()->generate();
```

You can generate a special character. A special character is one of '!"#$%&amp;'()\*+,-./:;&lt;=&gt;?@\[\]^\_`{|}~':

```
Randomize::char()->specialCharacters()->generate();
```

### Generate Boolean

[](#generate-boolean)

Sometimes you want to obtain a random boolean `true` or `false` (flip a coin):

```
$randomBool = Randomize::boolean()->generate();
```

### Generate a Float

[](#generate-a-float)

Sometimes you want to obtain a random float (default min-max range of 0.0 - 1.0). For example, you want to generate a random temperature for a day:

```
$randomFloat = Randomize::float()->generate();
```

Or you can set the min-max range of 0 - 90, which is equivalent to -&gt;min(0)-&gt;max(90)

```
$randomFloat = Randomize::float()->min(0)->max(90)->generate();
```

### Generate an Integer

[](#generate-an-integer)

Sometimes you want to obtain a random integer (min-max range). For example, you want to roll the dice:

```
$randomNumber = Randomize::integer()->min(1)->max(6)->generate();
```

The same thing using `range()` method, instead of `min()` and `max()`:

```
$randomNumber = Randomize::integer()->range(1,6)->generate();
```

You can use a shortcut helper to generate an integer calling the constructor with min and max parameters:

```
$randomNumber = Randomize::integer(1,6)->generate();
```

### Generate bytes

[](#generate-bytes)

Sometimes you want to obtain some random bytes (hexadecimal). For example, you want to generate a random RGB color (a hex triplet in hexadecimal format):

```
$randomRGB = Randomize::byte()->length(3)->generate();
```

### Generate a Date

[](#generate-a-date)

Sometimes you want to obtain a random date. For example, you want to generate a random date:

```
$randomDate = Randomize::datetime()->generate();
```

By default, a date between the first day of the current year to the last day of the current year. If you want to define the range, for example, a range of 01 Jan 2020 to 10 Jan 2020, you can use `min()` and `max()` methods:

```
$randomDate = Randomize::datetime()->min('2020–01–01')->max('2020–01–10')->generate();
```

You can even specify your preferred format for the random date generated, by using the `format()` method:

```
$randomDate = Randomize::datetime()->format('d-M-Y')->generate();
```

You can use `min()` and `max()` with `format()` method:

```
$randomDate = Randomize::datetime()->min('2020–01–01')->max('2020–01–10')->format('d-M-Y')->generate();
```

With the latest example, you can obtain something like "05-Jan-2020".

### Generate sequences

[](#generate-sequences)

Sometimes, you want to obtain some random sequences. For example, you want to roll the dice 15 times:

```
$randomRolls = Randomize::sequence()->min(1)->max(6)->count(15)->generate();
```

Sometimes you want to obtain some random char sequences. For example, char sequences of length 10:

```
$randomChars = Randomize::sequence()->chars()->count(10)->generate();
```

Or you might want numeric char sequences.

```
$randomChars = Randomize::sequence()->chars()->numeric()->count(10)->generate();
```

Or you might want alphabetical char sequences.

```
$randomChars = Randomize::sequence()->chars()->alpha()->count(10)->generate();
```

Yes, even both.

```
$randomChars = Randomize::sequence()->chars()->alphanumeric()->count(10)->generate();
```

You want 20 lowercase chars:

```
Randomize::sequence()->chars()->alphaLowerCase()->count(20)->asString()->generate();
```

You want 20 upper case chars:

```
Randomize::sequence()->chars()->alphaUpperCase()->count(20)->asString()->generate();
```

Sometimes you want to obtain some random sequences with **no duplicates**. For example, you want to play "Tombola" (extracting numbers from 1 to 90 with NO duplicates):

```
$randomTombola = Randomize::sequence()->min(1)->max(90)->count(90)->noDuplicates()->generate();
```

Sometimes you want to obtain some random char sequences with **no duplicates**.

```
$randomChars = Randomize::sequence()->chars()->count(10)->noDuplicates()->generate();
```

Or you might want numeric char sequences with **no duplicates**. For example, char sequences of length 10:

```
$randomChars = Randomize::sequence()->chars()->numeric()->count(10)->noDuplicates()->generate();
```

Or you might want alphabetical char sequences with **no duplicates**.

```
$randomChars = Randomize::sequence()->chars()->alpha()->count(10)->noDuplicates()->generate();
```

Yes, even both and with **no duplicates**.

```
$randomChars = Randomize::sequence()->chars()->alphanumeric()->count(10)->noDuplicates()->generate();
```

### Random String

[](#random-string)

If you want to generate a random string (alphanumeric, only letters, only numbers, with no duplication, lower case, upper case etc) you can use random chars generation. To generate a string use `Randomize::chars()`:

```
$string = Randomize::chars()->generate();
```

The default behavior is:

- 10 chars;
- only letters (a-z);
- lowercase;
- duplication is allowed (the string 'aba' has a duplication for 'a' char).

You can change the default values with some methods and parameters. Method to set the type of chars (numeric, alpha, alphanumeric...):

- *alpha()* : 'a-z', 'A-Z';
- *alphanumeric()* : 'a-z', 'A-Z', '0-9';
- *numeric()* : '0-9';
- *alphaLowerCase()* : 'a-z';
- *alphaUpperCase()* : 'A-Z';
- *specialCharacters()* : !"#$%&amp;'()\*+,-./:;&lt;=&gt;?@\[\]^\_`{|}~

You have also some methods to "control" the output, for example, avoid duplications:

- `unique()`: it generates a string with at most one occurrence per character.

#### String with numeric chars ('0'-'9')

[](#string-with-numeric-chars-0-9)

If you want to generate a string with 16 chars, made with numeric chars ('0'-'9'):

```
$string = Randomize::chars(16)->numeric()->generate();
```

You could obtain something like this '3963233500573002'.

#### String with 20 chars, lower case, just letters, no dups

[](#string-with-20-chars-lower-case-just-letters-no-dups)

If you want to obtain a string with 20 chars, lower case and just letters ('a'-'z'), and you want to avoid character duplications ( `alphaLowerCase()` and `unique()` ):

```
$string = Randomize::chars(20)->alphaLowerCase()->unique()->generate();
```

You could obtain something like this: 'nmbsjhrgdyfxwoltqkzp'.

#### String with 20 chars, letters and special characters

[](#string-with-20-chars-letters-and-special-characters)

If you want to obtain a string with 20 chars, with letters and special characters:

```
$string = Randomize::chars(20)->specialCharacters()->alpha()->generate();
```

You could obtain something like this: 'IOgPckeGGifrD%DRy\[\*!'.

### Draw random stuff

[](#draw-random-stuff)

If you have a list of values and you want to extract/select/draw one or more elements, you could use the `Draw` class instead of `Randomize`. For using the `Draw` class you need to import it:

```
use HiFolks\RandoPhp\Draw;
```

#### Suggest which programming language you could use in your next project (random)

[](#suggest-which-programming-language-you-could-use-in-your-next-project-random)

```
use HiFolks\RandoPhp\Draw;

$randomLanguage = Draw::sample(["PHP", "Python", "Golang", "Javascript"])->snap();
var_dump($randomLanguage);
```

#### Suggest which JS framework you could use in your next project (random)

[](#suggest-which-js-framework-you-could-use-in-your-next-project-random)

```
$array=["React.js", "Vue.js", "Svelte.js", "Angular.js" , "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->extract();
```

#### Extract 3 JS frameworks you could use in your next project

[](#extract-3-js-frameworks-you-could-use-in-your-next-project)

```
$array=["React.js", "Vue.js", "Svelte.js", "Angular.js" , "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->count(3)->extract();
```

#### Extract 3 JS frameworks (duplicates allowed)

[](#extract-3-js-frameworks-duplicates-allowed)

```
$array = ["React.js", "Vue.js", "Svelte.js", "Angular.js", "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->count(3)->allowDuplicates()->extract();
```

### Testing

[](#testing)

```
composer test
```

If you want to see some coverage reports you can execute `phpunit` command with `coverage-text` option:

```
vendor/bin/phpunit --coverage-text
```

### Warning ⚠️

[](#warning-warning)

Under the hood, RandoPHP uses some native PHP functions like:

- array\_rand(): [PHP Doc for array\_rand](https://www.php.net/manual/en/function.array-rand.php);
- random\_int(): [PHP Doc for random\_int](https://www.php.net/manual/en/function.random-int.php);
- shuffle(): [PHP Doc for shuffle](https://www.php.net/manual/en/function.shuffle);
- random\_bytes(): [PHP Doc for random\_bytes](https://www.php.net/manual/en/function.random-bytes).

These PHP functions use a pseudo-random number generator that is not suitable for cryptographic purposes.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Submit ideas or feature requests or issues

[](#submit-ideas-or-feature-requests-or-issues)

Take a look if your request is already created If it is not present, you can create a new one

Credits
-------

[](#credits)

- [Roberto Butti](https://github.com/roberto-butti)
- [All Contributors](../../contributors)
- [PHP Package Boilerplate](https://laravelpackageboilerplate.com)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 82% 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 ~132 days

Recently: every ~334 days

Total

13

Last Release

543d ago

PHP version history (4 changes)v0.1.0PHP ^7.1

v0.1.6PHP ^7.1|^8.0

v0.3.0PHP ^8.0|^8.1|^8.2|^8.3

v0.3.1PHP ^8.0|^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe3f0e9f35a03ea055996e023bc25cfe408742fe9433f66858b714133da55313?d=identicon)[roberto](/maintainers/roberto)

---

Top Contributors

[![roberto-butti](https://avatars.githubusercontent.com/u/678434?v=4)](https://github.com/roberto-butti "roberto-butti (155 commits)")[![eruhaji](https://avatars.githubusercontent.com/u/6085192?v=4)](https://github.com/eruhaji "eruhaji (5 commits)")[![rebelchris](https://avatars.githubusercontent.com/u/554874?v=4)](https://github.com/rebelchris "rebelchris (4 commits)")[![vrabe](https://avatars.githubusercontent.com/u/8216525?v=4)](https://github.com/vrabe "vrabe (3 commits)")[![pret3nti0u5](https://avatars.githubusercontent.com/u/57453561?v=4)](https://github.com/pret3nti0u5 "pret3nti0u5 (3 commits)")[![jirkavrba](https://avatars.githubusercontent.com/u/14146321?v=4)](https://github.com/jirkavrba "jirkavrba (3 commits)")[![Septikwar](https://avatars.githubusercontent.com/u/20446481?v=4)](https://github.com/Septikwar "Septikwar (3 commits)")[![Zuruckt](https://avatars.githubusercontent.com/u/11967494?v=4)](https://github.com/Zuruckt "Zuruckt (2 commits)")[![armsasmart](https://avatars.githubusercontent.com/u/46369858?v=4)](https://github.com/armsasmart "armsasmart (2 commits)")[![quanlh-smartosc](https://avatars.githubusercontent.com/u/108383313?v=4)](https://github.com/quanlh-smartosc "quanlh-smartosc (1 commits)")[![paresh27](https://avatars.githubusercontent.com/u/25386515?v=4)](https://github.com/paresh27 "paresh27 (1 commits)")[![Rocksheep](https://avatars.githubusercontent.com/u/1311371?v=4)](https://github.com/Rocksheep "Rocksheep (1 commits)")[![sam0hack](https://avatars.githubusercontent.com/u/5379650?v=4)](https://github.com/sam0hack "sam0hack (1 commits)")[![marcio-adue](https://avatars.githubusercontent.com/u/66394749?v=4)](https://github.com/marcio-adue "marcio-adue (1 commits)")[![davidribeiro](https://avatars.githubusercontent.com/u/11426456?v=4)](https://github.com/davidribeiro "davidribeiro (1 commits)")[![webhaikal](https://avatars.githubusercontent.com/u/5836570?v=4)](https://github.com/webhaikal "webhaikal (1 commits)")[![wesolowski](https://avatars.githubusercontent.com/u/1388643?v=4)](https://github.com/wesolowski "wesolowski (1 commits)")[![Anita-ihuman](https://avatars.githubusercontent.com/u/62384659?v=4)](https://github.com/Anita-ihuman "Anita-ihuman (1 commits)")

---

Tags

generatorhacktoberfestlibrarypackagephprandomrandomlibrarygeneratorsequencehi-folksdrawrando-php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hi-folks-rando-php/health.svg)

```
[![Health](https://phpackages.com/badges/hi-folks-rando-php/health.svg)](https://phpackages.com/packages/hi-folks-rando-php)
```

###  Alternatives

[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[gladcodes/keygen

A fluent PHP random key generator.

119668.9k2](/packages/gladcodes-keygen)[standaniels/image-generator

A package to generate random images.

1696.6k1](/packages/standaniels-image-generator)

PHPackages © 2026

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