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

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

emonkak/random
==============

A random number generator library

v3.0.0(5y ago)927.2k↓32.1%1[1 issues](https://github.com/emonkak/php-random/issues)MITPHPPHP &gt;=7.1CI failing

Since Mar 24Pushed 5y ago3 watchersCompare

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

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

Emonkak\\Random
===============

[](#emonkakrandom)

[![Build Status](https://camo.githubusercontent.com/281df2bd6db03ef396245563354f86600cb53ef0aa99db8c56c8b21366d21389/68747470733a2f2f7472617669732d63692e6f72672f656d6f6e6b616b2f7068702d72616e646f6d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/emonkak/php-random)[![Coverage Status](https://camo.githubusercontent.com/d58b8d1e08480929d6e1e745c9debbc04246d159626b052cdd301a726b15a5ed/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f656d6f6e6b616b2f7068702d72616e646f6d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/emonkak/php-random?branch=master)

This library provides pseudo-random number generators and probability distributions.

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

[](#requirements)

- PHP 7.1 or higher

Licence
-------

[](#licence)

MIT Licence

Example
-------

[](#example)

```
use Emonkak\Random\Engine\MT19937Engine;
use Emonkak\Random\Distribution\NormalDistribution;

$seed = 100;  // Initial seed
$engine = new MT19937Engine($seed);  // 32bit Mersenne Twister engine
$distribution = new NormalDistribution(0, 1);  // Standard normal distribution

// Generate a random number with the normal distribution.
$distribution->generate($engine);
```

Engine
------

[](#engine)

- `KnuthBEngine`
- `LinearCongruentialEngine`
- `MinstdRand0Engine`
- `MinstdRandEngine`
- `MT19937Engine`

    The random generator engine according to [Mersenne Twister](http://en.wikipedia.org/wiki/Mersenne_twister). It is full-compatible to the built-in `mt_rand()`.

    ```
     // Also, the initial seed algorithm is full-compatible to the built-in `mt_srand()`
     $engine = new MT19937Engine(/* $seed */);

     // Get a next random number from the current generator state.
     $number = $engine->next();  // as int
     $number = $engine->nextDouble();  // as float

     // Get the minimum and maximum number which generate a value by the engine.
     $minimum = $engine->min();
     $maximum = $engine->max();

     // Iterate the generator engine.
     foreach (new LimitIterator($engine, 0, 100) as $n) {
     }
    ```
- `MTRandWrapper`

    The wrapper for the built-in `mt_rand()`.
- `ShuffleOrderEngine`
- `XorShift128Engine`

    The random generator engine according to [Xorshift](http://en.wikipedia.org/wiki/XorShift) 128 bit algorithm.

Distribution
------------

[](#distribution)

- `BernoulliDistribution`
- `BinomialDistribution`
- `DiscreteDistribution`
- `DistributionIterator`
- `ExponentialDistribution`
- `GammaDistribution`
- `GeometricDistribution`
- `LogNormalDistribution`
- `NormalDistribution`
- `PiecewiseConstantDistribution`
- `PiecewiseLinerDistribution`
- `UniformIntDistribution`
- `UniformRealDistribution`

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 99% 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 ~383 days

Total

5

Last Release

2175d ago

Major Versions

v1.0.0 → v2.0.02016-04-11

v2.0.2 → v3.0.02020-06-04

PHP version history (2 changes)v1.0.0PHP &gt;=5.3.0

v3.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/482d690ac653e05c9f5625e0f5f6e71b55e77646ab722bbcfdfbd26bf3c8d86b?d=identicon)[emonkak](/maintainers/emonkak)

---

Top Contributors

[![emonkak](https://avatars.githubusercontent.com/u/188621?v=4)](https://github.com/emonkak "emonkak (103 commits)")[![AlexeyKupershtokh](https://avatars.githubusercontent.com/u/499778?v=4)](https://github.com/AlexeyKupershtokh "AlexeyKupershtokh (1 commits)")

---

Tags

random

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[paragonie/random_compat

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

8.2k655.0M405](/packages/paragonie-random-compat)[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)[pragmarx/random

Create random chars, numbers, strings

714.2M5](/packages/pragmarx-random)[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)

PHPackages © 2026

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